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 mintmintAuthority
:KeyPairSigner
- Signer with authority to mint tokensamount
:bigint
- Amount of tokens to mint (in base units)destination
:Address
- Address to receive the minted tokens
Returns
Returns a Promise<Signature>
- 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,
9, // decimals
"My Token",
"TKN",
"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