> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kas.fun/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Token

> How token creation works on KasFun

## Overview

Token creation on KasFun requires a **platform signature** — you cannot call `createToken()` directly without one. This is by design: all tokens should be created through the [kas.fun](https://kas.fun) website.

<Info>
  Token creation is designed to be done through the KasFun website at [kas.fun/create-token](https://kas.fun/create-token). The platform signature ensures metadata integrity and prevents spam.
</Info>

## How It Works

<Steps>
  <Step title="Prepare (via KasFun)">
    The user fills in token details (name, symbol, icon, description) on kas.fun. The platform generates a signature authorizing the creation.
  </Step>

  <Step title="On-Chain Transaction">
    The user's wallet calls `MemeFactory.createToken(params)` with the signed parameters. This is a **payable** call — it requires a creation fee.
  </Step>

  <Step title="Token Deployed">
    MemeFactory deploys an ERC-20 token, sets up the bonding curve pool, and emits a `Created` event.
  </Step>
</Steps>

## createToken Parameters

```solidity theme={null}
struct CreateTokenParams {
    string name;           // Token name
    string symbol;         // Token symbol
    string metadataUri;    // IPFS/S3 metadata URL
    uint256 creatorBuyAmount; // Optional: buy tokens at creation (wei)
    bytes32 salt;          // For deterministic address (vanity address)
    uint256 nonce;         // Anti-replay
    uint256 deadline;      // Signature expiry (unix timestamp)
    bytes signature;       // Platform EIP-712 signature
}
```

## Creation Fee

The contract charges a creation fee in KAS. Query it via:

```javascript theme={null}
const fee = await factory.creationFee();
console.log("Creation fee:", ethers.formatEther(fee), "KAS");
```

If `creatorBuyAmount > 0`, the transaction value must be `creationFee + creatorBuyAmount`.

## Token Address

All KasFun tokens have addresses ending in `7777` (vanity address). The address is deterministic — computed from the salt and creator address:

```javascript theme={null}
const predictedAddress = await factory.computeTokenAddress(salt, creatorAddress);
```

## Created Event

```solidity theme={null}
event Created(
    address indexed token,
    address indexed creator,
    uint256 indexed tokenId,
    address pool,
    string name,
    string symbol
);
```

Listen for new token creations:

```javascript theme={null}
factory.on("Created", (token, creator, tokenId, pool, name, symbol) => {
  console.log(`New token: ${name} (${symbol}) at ${token}`);
});
```
