initializeAccount static method
Initializes a new account to hold tokens. If this account is associated with the native mint then the token balance of the initialized account will be equal to the amount of SOL in the account. If this account is associated with another mint, that mint must be initialized before this command can succeed.
The initializeAccount
instruction requires no signers and MUST be included within the same
Transaction as the system program's createAccount
instruction that creates the account being
initialized. Otherwise another party can acquire ownership of the uninitialized account.
Keys:
[w]
account
- The account to initialize.[]
mint
- The mint this account will be associated with.[]
owner
- The new account's owner/multisignature.
Implementation
static TransactionInstruction initializeAccount({
required final Pubkey account,
required final Pubkey mint,
required final Pubkey owner,
}) {
// 0. `[writable]` The account to initialize.
// 1. `[]` The mint this account will be associated with.
// 2. `[]` The new account's owner/multisignature.
// 3. `[]` Rent sysvar
final List<AccountMeta> keys = [
AccountMeta.writable(account),
AccountMeta(mint),
AccountMeta(owner),
AccountMeta(sysvarRentPubkey),
];
return _instance.createTransactionIntruction(
TokenInstruction.initializeAccount,
keys: keys,
);
}