burnChecked static method
Burns tokens by removing them from an account. BurnChecked
does not support accounts
associated with the native mint, use closeAccount
instead.
This instruction differs from Burn in that the decimals value is checked by the caller. This may be useful when creating transactions offline or within a hardware wallet.
Keys:
Single owner/delegate
[w]
account
- The account to burn from.[w]
mint
- The token mint.[s]
authority
- The account's owner/delegate.
Multisignature owner/delegate
[w]
account
- The account to burn from.[w]
mint
- The token mint.[]
authority
- The account's multisignature owner/delegate.[s]
signers
- The signer accounts.
Data:
amount
- The amount of tokens to burn.decimals
- Expected number of base 10 digits to the right of the decimal place.
Implementation
static TransactionInstruction burnChecked({
// Keys
required final Pubkey account,
required final Pubkey mint,
required final Pubkey authority,
final List<Pubkey> signers = const [],
// Data
required final bu64 amount,
required final u8 decimals,
}) {
// * Single owner/delegate
// 0. `[writable]` The account to burn from.
// 1. `[writable]` The token mint.
// 2. `[signer]` The account's owner/delegate.
//
// * Multisignature owner/delegate
// 0. `[writable]` The account to burn from.
// 1. `[writable]` The token mint.
// 2. `[]` The account's multisignature owner/delegate.
// 3. ..3+M `[signer]` M signer accounts.
final List<AccountMeta> keys = [
AccountMeta.writable(account),
AccountMeta.writable(mint),
AccountMeta(authority, isSigner: signers.isEmpty),
for (final Pubkey signer in signers)
AccountMeta.signer(signer),
];
final List<Iterable<u8>> data = [
borsh.u64.encode(amount),
borsh.u8.encode(decimals),
];
return _instance.createTransactionIntruction(
TokenInstruction.burnChecked,
keys: keys,
data: data,
);
}