# Create Token

Creates a new token with a bonding curve for initial liquidity.

## Instruction Index

1

## Instruction

```rust
SCBondingCurveInstruction::CreateToken {
    pda_token_nonce: u8,
    uri: String,
    name: String,
    symbol: String,
    after_migration_fee: u16,
    after_migration_burn_bp: u16,
    after_migration_holders_bp: u16,
    after_migration_lp_bp: u16,
    logging_account_bump: u8,
}
```

### Parameters

| Parameter                    | Type     | Description                                                                               |
| ---------------------------- | -------- | ----------------------------------------------------------------------------------------- |
| `pda_token_nonce`            | `u8`     | Nonce for generating the token owner PDA                                                  |
| `uri`                        | `String` | Token metadata URI                                                                        |
| `name`                       | `String` | Token name                                                                                |
| `symbol`                     | `String` | Token symbol                                                                              |
| `after_migration_fee`        | `u16`    | Fee percentage (in basis points) after migration (valid values: 0, 25, 50, 100, 200, 500) |
| `after_migration_burn_bp`    | `u16`    | Percentage of fees allocated to burning (in basis points)                                 |
| `after_migration_holders_bp` | `u16`    | Percentage of fees allocated to token holders (in basis points)                           |
| `after_migration_lp_bp`      | `u16`    | Percentage of fees allocated to liquidity providers (in basis points)                     |
| `logging_account_bump`       | `u8`     | Bump for the logging authority PDA                                                        |

### Account Setup

| #  | Account                           | Description                      | Derivation                                                  |
| -- | --------------------------------- | -------------------------------- | ----------------------------------------------------------- |
| 1  | Properties account                | Platform configuration           | `[Buffer.from("settings")]`                                 |
| 2  | Payer account                     | Transaction signer (User wallet) | -                                                           |
| 3  | Token program                     | SPL Token program                | `TOKEN_PROGRAM_ID`                                          |
| 4  | System program                    | System program                   | `SystemProgram.programId`                                   |
| 5  | Associated token account program  | ATA program                      | `ASSOCIATED_TOKEN_PROGRAM_ID`                               |
| 6  | Token mint                        | New token mint                   | Generated keypair                                           |
| 7  | Token owner PDA                   | Bonding curve account            | `[Buffer.from("token_owner"), mint.toBuffer(), [nonce]]`    |
| 8  | Token owner token account         | Token account for PDA            | `getAssociatedTokenAddress(mint, ownerPDA, true)`           |
| 9  | Metaplex token metadata program   | Metadata program                 | `metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s`               |
| 10 | Metaplex token metadata account   | Metadata account                 | `["metadata", metaplexProgram.toBuffer(), mint.toBuffer()]` |
| 11 | Post migration CC\* WSOL storage  | SOL storage                      | `PublicKey.createWithSeed(mint, "w", TOKEN_PROGRAM_ID)`     |
| 12 | Post migration CC\* token storage | Token storage                    | `PublicKey.createWithSeed(mint, "t", TOKEN_PROGRAM_ID)`     |
| 13 | Rent sysvar                       | Rent program                     | `SYSVAR_RENT_PUBKEY`                                        |
| 14 | Native mint                       | WSOL mint                        | `NATIVE_MINT`                                               |
| 15 | CoolDEX owner                     | Platform owner                   | Fixed address (see Reference section)                       |
| 16 | Program account                   | SC Bonding Curve program         | SC Bonding Curve program ID                                 |
| 17 | Log authority account             | For structured logs              | `[Buffer.from("logging_authority")]`                        |

\*CC - Community Contribution

## Function Logic

1. Validates that fee components sum to 10000 basis points (100%)
2. Verifies that the after\_migration\_fee is one of the allowed values (0, 25, 50, 100, 200, 500)
3. Creates the token mint account
4. Creates the bonding curve data account
5. Initializes the bonding curve with virtual SOL and token amounts
6. Mints the initial token supply to the bonding curve
7. Creates and initializes the token metadata
8. Creates post-migration token and SOL storage accounts
9. Records creation data in logs

## Notes

* The initial mint amount is set to 10,000,000,000.000000 tokens with 6 decimal places
* The token must have a valid name, symbol, and metadata URI
* The fee parameters determine how fees will be distributed after migration to the DEX
* The bonding curve is initialized with virtual SOL and token amounts to establish the initial price

### Example Usage

```javascript
// Generate a new mint
const mintKeypair = Keypair.generate()

// Derive PDAs and other accounts
const [propertiesAccount] = PublicKey.findProgramAddressSync(
  [Buffer.from("settings")],
  SC_BONDING_CURVE_PROGRAM_ID
)

const [tokenOwnerPDA, pdaTokenNonce] = PublicKey.findProgramAddressSync(
  [Buffer.from("token_owner"), mintKeypair.publicKey.toBuffer()],
  SC_BONDING_CURVE_PROGRAM_ID
)

const [logAuthority, logAuthorityBump] = PublicKey.findProgramAddressSync(
  [Buffer.from("logging_authority")],
  SC_BONDING_CURVE_PROGRAM_ID
)

// Get token accounts
const ownerTokenAccount = getAssociatedTokenAddressSync(
  mintKeypair.publicKey,
  tokenOwnerPDA,
  true
)

// Create metadata account
const [metadataAccount] = PublicKey.findProgramAddressSync(
  [
    Buffer.from("metadata"),
    METAPLEX_PROGRAM_ID.toBuffer(),
    mintKeypair.publicKey.toBuffer(),
  ],
  METAPLEX_PROGRAM_ID
)

// Create Community Contribution storage accounts
const cultStorageWsol = await PublicKey.createWithSeed(
  mintKeypair.publicKey,
  "w",
  TOKEN_PROGRAM_ID
)

const cultStorageToken = await PublicKey.createWithSeed(
  mintKeypair.publicKey,
  "t",
  TOKEN_PROGRAM_ID
)

const data = Buffer.alloc(1000)
let offset = 0

// Selector = 1, create token
data.writeUint8(1, offset)
offset += 1

// Name, Symbol or URI can not be longer than 255
data.writeUint8(curveBump, offset)
offset += 1
data.writeUint8(urlBuffer.length, offset)
offset += 1
data.write(url, offset, "utf-8")
offset += urlBuffer.length
data.writeUint8(nameBuffer.length, offset)
offset += 1
data.write(name, offset, "utf-8")
offset += nameBuffer.length
data.writeUint8(symbolBuffer.length, offset)
offset += 1
data.write(symbol, offset, "utf-8")
offset += symbolBuffer.length

data.writeUint16LE(fee, offset) // fee, 100 means 1%
offset += 2
data.writeUint16LE(burnFee, offset) // share to burn out of fee, 100 means 1%
offset += 2
data.writeUint16LE(holdersFee, offset) // share to holders out of fee,, 100 means 1%
offset += 2
data.writeUint16LE(lpFee, offset) // share to lp out of fee,, 100 means 1%
offset += 2
data.writeUint8(logAuthorityBump, offset)
offset += 1

const createTokenIx = new TransactionInstruction({
  programId: SC_BONDING_CURVE_PROGRAM_ID,
  keys: [
    { pubkey: propertiesAccount, isSigner: false, isWritable: true },
    { pubkey: wallet.publicKey, isSigner: true, isWritable: true },
    { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
    { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
    { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
    { pubkey: mintKeypair.publicKey, isSigner: true, isWritable: true },
    { pubkey: tokenOwnerPDA, isSigner: false, isWritable: true },
    { pubkey: ownerTokenAccount, isSigner: false, isWritable: true },
    { pubkey: METAPLEX_PROGRAM_ID, isSigner: false, isWritable: false },
    { pubkey: metadataAccount, isSigner: false, isWritable: true },
    { pubkey: cultStorageWsol, isSigner: false, isWritable: true },
    { pubkey: cultStorageToken, isSigner: false, isWritable: true },
    { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
    { pubkey: NATIVE_MINT, isSigner: false, isWritable: false },
    { pubkey: COOLDEX_OWNER, isSigner: false, isWritable: false },
    { pubkey: SC_BONDING_CURVE_PROGRAM_ID, isSigner: false, isWritable: false },
    { pubkey: logAuthority, isSigner: false, isWritable: false },
  ],
  data: data,
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.something.cool/sc-bonding-curve/functions/create-token.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
