createAndInitializeAccount static method

List<Instruction> createAndInitializeAccount({
  1. required Ed25519HDPublicKey mint,
  2. required Ed25519HDPublicKey address,
  3. required Ed25519HDPublicKey owner,
  4. required int rent,
  5. required int space,
})

Create an account with address and owned by owner. The rent

You can use RPCClient.getMinimumBalanceForRentExemption to determine rent for the required space.

This is a convenience method that would initialize the account and associate it with mint. This method also issues a SystemInstruction to actually create the account before linking it with the mint.

You must call this method and create an account before attempting to use it in the TokenProgram.mintTo as destination.

This transaction must be signed by owner and address.

Implementation

static List<Instruction> createAndInitializeAccount({
  required Ed25519HDPublicKey mint,
  required Ed25519HDPublicKey address,
  required Ed25519HDPublicKey owner,
  required int rent,
  required int space,
}) =>
    [
      SystemInstruction.createAccount(
        newAccount: address,
        fundingAccount: owner,
        lamports: rent,
        space: space,
        owner: Ed25519HDPublicKey.fromBase58(TokenProgram.programId),
      ),
      TokenInstruction.initializeAccount(
        mint: mint,
        account: address,
        owner: owner,
      ),
    ];