allocateWithSeed static method

TransactionInstruction allocateWithSeed({
  1. required Pubkey accountPubkey,
  2. required Pubkey basePubkey,
  3. required String seed,
  4. required bu64 space,
  5. required Pubkey programId,
})

Generates a transaction instruction that allocates space in an account without funding.

Keys:

  • [w] accountPubkey The public key of the account which will be assigned a new owner.
  • [s] basePubkey The base public key used to derive the address of the assigned account.

Data:

  • basePubkey The base public key used to derive the address of the assigned account.
  • seed The seed used to derive the address of the assigned account.
  • space The amount of space in bytes to allocate.
  • programId The public key of the program to assign as the owner.

Implementation

static TransactionInstruction allocateWithSeed({
  required final Pubkey accountPubkey,
  required final Pubkey basePubkey,
  required final String seed,
  required final bu64 space,
  required final Pubkey programId,
}) {
  final List<AccountMeta> keys = [
    AccountMeta.writable(accountPubkey),
    AccountMeta.signer(basePubkey),
  ];

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

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