initializeAccount2 static method
Like InitializeAccount, but the owner pubkey is passed via instruction data rather than the
accounts list. This variant may be preferable when using Cross Program Invocation from an
instruction that does not need the owner's AccountInfo
otherwise.
Keys:
[w]
account
- The account to initialize.[]
mint
- The mint this account will be associated with.
Data:
owner
- The new account's owner/multisignature.
Implementation
static TransactionInstruction initializeAccount2({
// Keys
required final Pubkey account,
required final Pubkey mint,
// Data
required final Pubkey owner,
}) {
// 0. `[writable]` The account to initialize.
// 1. `[]` The mint this account will be associated with.
// 2. `[]` Rent sysvar
final List<AccountMeta> keys = [
AccountMeta.writable(account),
AccountMeta(mint),
AccountMeta(sysvarRentPubkey),
];
final List<Iterable<u8>> data = [
borsh.pubkey.encode(owner.toBase58()),
];
return _instance.createTransactionIntruction(
TokenInstruction.initializeAccount2,
keys: keys,
data: data,
);
}