# Mint Tokens

This guide explains how to create and mint a token using the KeetaNet SDK. You'll learn how to build and publish a token account, set its supply, and adjust balances.

### Step-by-Step <a href="#step-by-step-minting-a-token" id="step-by-step-minting-a-token"></a>

{% stepper %}
{% step %}

### Initialize the Transaction Builder

Start by creating a transaction builder from your user client. This builder is used to queue up all operations before publishing to the network.

```typescript
const builder = userClient.initBuilder();
```

{% endstep %}

{% step %}

### Generate the Token Account

Use the builder to create a new token account:

```typescript
const pendingTokenAccount = builder.generateIdentifier(KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN);
await builder.computeBlocks();
const tokenAccount = pendingTokenAccount.account;
console.log("tokenAccount.publicKey =", tokenAccount.publicKeyString.toString());
```

{% endstep %}

{% step %}

### Set Token Information & Permissions

Configure the basic information and default permissions for your token:

```typescript
builder.setInfo(
    {
        name: '',                 // Token name
        description: '',          // Short description
        metadata: '',             // Arbitrary metadata
        defaultPermission: new KeetaNet.lib.Permissions([
            'ACCESS', // Public token
        ]),
    },
    { account: tokenAccount },
);
```

{% endstep %}

{% step %}

### Mint Token Supply

Define the total supply for the new token and mint tokens into the liquidity account:

```typescript
builder.modifyTokenSupply(10_000n, { account: tokenAccount }); // Set total supply
builder.send(account, 10_000n, tokenAccount, undefined, { account: tokenAccount });             // Distribute token amount to the liquidity account
```

{% endstep %}

{% step %}

### Publish the Operation

Send the queued operations to the network:

```typescript
await builder.publish();
console.log("Token account created and minted.");
```

{% endstep %}
{% endstepper %}

## Full Code Example

```typescript
import * as KeetaNet from "@keetanetwork/keetanet-client";

// Function to create and mint a new token
async function createToken(userClient: KeetaNet.UserClient) {
    const builder = userClient.initBuilder();

    // Generate the token account identifier
    const pendingTokenAccount = builder.generateIdentifier(KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN);
    await builder.computeBlocks();
    const tokenAccount = pendingTokenAccount.account;

    // Set token info and permissions
    builder.setInfo(
        {
            name: '', // Token name (add as needed)
            description: '', // Description (add as needed)
            metadata: '', // Metadata (add as needed)
            defaultPermission: new KeetaNet.lib.Permissions([
                'ACCESS', // Public token
            ]),
        },
        { account: tokenAccount },
    );

    // Increase (mint) total token supply and distribute the tokens
    builder.modifyTokenSupply(10_000n, { account: tokenAccount });
    builder.send(account, 10_000n, tokenAccount, undefined, { account: tokenAccount });

    // Publish the transaction to the network
    await builder.publish();

    console.log("Token account created and minted.");
    return tokenAccount;
}

// Main function demonstrating token creation
async function main() {
    // Generate a random seed for account creation
    const seed = KeetaNet.lib.Account.generateRandomSeed({ asString: true });
    console.log("seed =", seed);

    // Create a liquidity provider account from the seed
    const liquidityProviderAccount = KeetaNet.lib.Account.fromSeed(seed, 0);

    // Instantiate a user client connected to the test network
    const liquidityProviderClient = KeetaNet.UserClient.fromNetwork("test", liquidityProviderAccount);

    // Create and mint the token
    const tokenAccount = await createToken(liquidityProviderClient);

    // Log the token identifier that was created
    console.log("Token Account =", tokenAccount.publicKeyString.get());

    // Log balances of the liquidity provider
    console.log("liquidityProviderClient.balances[] =", await liquidityProviderClient.allBalances());
}

main()
    .then(() => {
        console.log("Done");
        process.exit(0);
    })
    .catch((err) => {
        console.error("Error:", err);
        process.exit(1);
    });

```


---

# 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.keeta.com/features/native-tokenization/token-creation/mint-tokens.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.
