Burn Instruction
Permanently destroys tokens by removing them from circulation. This reduces the total supply of the token.
Before we can mint any token, we'll need to already have:
- Initialized a
Mint
account. - A
Token
account orAssociated Token
account that already has at least the amount we want to burn.
The amount of tokens we burn are "normalized" for decimals. This means that if we want to burn 1 token that has 6 decimals, we'll need to actually put
1e6
as amount
Raw Instruction
By using just "raw" instruction without any abstraction, this is how burning a token would look like:
// Burn tokens to ATA
const burnInstruction = createBurnInstruction(
tokenAccount, // token account
mint, // mint
keypair.publicKey // owner
1e6, // amount
);
const transaction = new Transaction().add(burnInstruction);
const signature = await sendAndConfirmTransaction(connection, transaction, [keypair]);
console.log(`Tokens Burned! Check out your TX here: https://explorer.solana.com/tx/${signature}?cluster=devnet`);
Abstracted Instruction
This is how the same instructions would look like abstracted away with the burn()
instruction:
let tx = await burn(
connection, // connection
keypair, // payer
tokenAccount, // token account
keypair.publicKey, // owner of the token account
1e6, // amount to transfer
);
console.log(`Succesfully Burned!. Transaction Here: https://explorer.solana.com/tx/${tx}?cluster=devnet`)