createAccount static method

TransactionInstruction createAccount({
  1. required Pubkey fromPubkey,
  2. required Pubkey newAccountPubkey,
  3. required bu64 lamports,
  4. required bu64 space,
  5. required Pubkey programId,
})

Generates a transaction instruction that creates a new account.

Keys:

  • [w,s] fromPubkey - The account that will transfer lamports to the created account.
  • [w,s] newAccountPubkey - The public key of the created account.

Data:

  • lamports - The amount of lamports to transfer to the created account.
  • space - The amount of space in bytes to allocate to the created account.
  • programId - The public key of the program to assign as the owner of the created account.

Implementation

static TransactionInstruction createAccount({
  required final Pubkey fromPubkey,
  required final Pubkey newAccountPubkey,
  required final bu64 lamports,
  required final bu64 space,
  required final Pubkey programId,
}) {
  final List<AccountMeta> keys = [
    AccountMeta.signerAndWritable(fromPubkey),
    AccountMeta.signerAndWritable(newAccountPubkey),
  ];

  final List<Iterable<int>> data = [
    borsh.u64.encode(lamports),
    borsh.u64.encode(space),
    borsh.pubkey.encode(programId.toBase58()),
  ];

  return _instance.createTransactionIntruction(
    SystemInstruction.create,
    keys: keys,
    data: data,
  );
}