approve static method
Approves a delegate. A delegate is given the authority over tokens on behalf of the source account's owner.
Keys:
Single owner
[w]
source
- The source account.[]
delegate
- The delegate.[s]
owner
- The source account owner.
Multisignature owner
[w]
source
- The source account.[]
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.
Implementation
static TransactionInstruction approve({
// Keys
required final Pubkey source,
required final Pubkey delegate,
required final Pubkey owner,
final List<Pubkey> signers = const [],
// Data
required final bu64 amount,
}) {
// * Single owner
// 0. `[w]` The source account.
// 1. `[]` The delegate.
// 2. `[s]` The source account owner.
//
// * Multisignature owner
// 0. `[w]` The source account.
// 1. `[]` The delegate.
// 2. `[]` The source account's multisignature owner.
// 3. ..3+M `[s]` M signer accounts
final List<AccountMeta> keys = [
AccountMeta.writable(source),
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),
];
return _instance.createTransactionIntruction(
TokenInstruction.approve,
keys: keys,
data: data,
);
}