Skip to Content

Mint Tokens

The mintTokens function mints tokens from a token mint to a destination account. The mint authority must sign the transaction.

Usage

const signature = await connection.mintTokens( mintAddress, // address of the token mint mintAuthority, // signer with authority to mint tokens amount, // amount of tokens to mint destination, // address to receive the tokens );

Parameters

  • mintAddress: Address - Address of the token mint
  • mintAuthority: KeyPairSigner - Signer with authority to mint tokens
  • amount: bigint - Amount of tokens to mint (in base units)
  • destination: Address - Address to receive the minted tokens
  • useTokenExtensions: boolean (optional) - Use Token Extensions (Token-2022) program instead of classic Token program (default: true)

Returns

Returns a Promise<string> - The transaction signature that can be used to look up the transaction.

Example

// Create a new token mint const mintAuthority = await connection.createWallet({ airdropAmount: lamports(1n * SOL), }); const mintAddress = await connection.createTokenMint({ mintAuthority, decimals: 9, name: "My Token", symbol: "TKN", uri: "https://example.com/token.json", }); // Mint 100 tokens to the mint authority's account const signature = await connection.mintTokens(mintAddress, mintAuthority, 100n, mintAuthority.address);

Error Handling

The function will throw an error if:

  • The mint authority is not the actual authority for the token mint
  • The destination account doesn’t exist
  • The mint authority lacks sufficient SOL to pay for the transaction
  • The RPC connection fails
Last updated on