approveChecked static method
Approves a delegate. A delegate is given the authority over tokens on behalf of the source account's owner.
This instruction differs from Approve in that the token mint and decimals value is checked by the caller. This may be useful when creating transactions offline or within a hardware wallet.
Keys:
Single owner
[writable]
source
- The source account.[]
mint
- The token mint.[]
delegate
- The delegate.[signer]
owner
- The source account owner.
Multisignature owner
[writable]
source
- The source account.[]
mint
- The token mint.[]
delegate
- The delegate.[]
owner
- The source account's multisignature owner.[s]
signers
- The signer accounts.
Data:
amount
- The amount of tokens the delegate is approved for.decimals
- Expected number of base 10 digits to the right of the decimal place.
Implementation
static TransactionInstruction approveChecked({
// Keys
required final Pubkey source,
required final Pubkey mint,
required final Pubkey delegate,
required final Pubkey owner,
final List<Pubkey> signers = const [],
// Data
required final bu64 amount,
required final u8 decimals,
}) {
// * Single owner
// 0. `[w]` The source account.
// 1. `[]` The token mint.
// 2. `[]` The delegate.
// 3. `[s]` The source account owner.
///
// * Multisignature owner
// 0. `[w]` The source account.
// 1. `[]` The token mint.
// 2. `[]` The delegate.
// 3. `[]` The source account's multisignature owner.
// 4. `[s]` ..4+M, M signer accounts
final List<AccountMeta> keys = [
AccountMeta.writable(source),
AccountMeta(mint),
AccountMeta(delegate),
AccountMeta(owner, isSigner: signers.isEmpty),
for (final Pubkey signer in signers) AccountMeta.signer(signer),
];
final List<Iterable<int>> data = [
borsh.u64.encode(amount),
borsh.u8.encode(decimals),
];
return _instance.createTransactionIntruction(
TokenInstruction.approveChecked,
keys: keys,
data: data,
);
}