createAccountWithSeed static method
Creates a transaction instruction that creates a new account at an address generated with
fromPubkey, a seed, and programId.
Keys:
fromPubkeyThe account that will transfer lamports to the created account.newAccountPubkeyThe public key of the created account. Must be pre-calculated with Pubkey.createWithSeed().
Data:
basePubkeyThe base public key used to derive the address of the created account. Must be the same as the base key used to createnewAccountPubkey.seedThe seed used to derive the address of the created account. Must be the same as the seed used to createnewAccountPubkey.lamportsThe amount of lamports to transfer to the created account.spaceThe amount of space in bytes to allocate to the created account.programIdThe public key of the program to assign as the owner of the created account.
Implementation
static TransactionInstruction createAccountWithSeed({
required final Pubkey fromPubkey,
required final Pubkey newAccountPubkey,
required final Pubkey basePubkey,
required final String seed,
required final bu64 lamports,
required final bu64 space,
required final Pubkey programId,
}) {
final List<AccountMeta> keys = [
AccountMeta.signerAndWritable(fromPubkey),
AccountMeta.writable(newAccountPubkey),
if (fromPubkey != basePubkey)
AccountMeta.signer(basePubkey),
];
final List<Iterable<int>> data = [
borsh.pubkey.encode(basePubkey.toBase58()),
borsh.rustString().encode(seed),
borsh.u64.encode(lamports),
borsh.u64.encode(space),
borsh.pubkey.encode(programId.toBase58()),
];
return _instance.createTransactionIntruction(
SystemInstruction.createWithSeed,
keys: keys,
data: data,
);
}