跳转到主要内容

概述

在 KasFun 上创建代币需要平台签名——没有签名无法直接调用 createToken()。这是设计使然:所有代币应通过 kas.fun 网站创建。
代币创建需通过 KasFun 网站 kas.fun/create-token 完成。平台签名确保元数据完整性并防止垃圾代币。

工作流程

1

准备(通过 KasFun)

用户在 kas.fun 上填写代币信息(名称、符号、图标、描述)。平台生成授权创建的签名。
2

链上交易

用户钱包调用 MemeFactory.createToken(params) 并附带签名参数。这是一个 payable 调用——需要支付创建费用。
3

代币部署

MemeFactory 部署 ERC-20 代币,建立 Bonding Curve 池,并发出 Created 事件。

createToken 参数

struct CreateTokenParams {
    string name;           // 代币名称
    string symbol;         // 代币符号
    string metadataUri;    // 元数据 URI
    uint256 creatorBuyAmount; // 可选:创建时同时买入的金额 (wei)
    bytes32 salt;          // 用于确定性地址(vanity address)
    uint256 nonce;         // 防重放
    uint256 deadline;      // 签名过期时间(unix 时间戳)
    bytes signature;       // 平台 EIP-712 签名
}

创建费用

合约收取 KAS 创建费用。查询方式:
const fee = await factory.creationFee();
console.log("创建费用:", ethers.formatEther(fee), "KAS");
如果 creatorBuyAmount > 0,交易 value 必须为 creationFee + creatorBuyAmount

代币地址

所有 KasFun 代币的地址以 7777 结尾(vanity address)。地址是确定性的——由 salt 和创建者地址计算得出:
const predictedAddress = await factory.computeTokenAddress(salt, creatorAddress);

Created 事件

event Created(
    address indexed token,
    address indexed creator,
    uint256 indexed tokenId,
    address pool,
    string name,
    string symbol
);
监听新代币创建:
factory.on("Created", (token, creator, tokenId, pool, name, symbol) => {
  console.log(`新代币: ${name} (${symbol}) 地址 ${token}`);
});