createAccountWithSeed static method
Creates a transaction instruction that creates a new account at an address generated with
fromPubkey
, a seed
, and programId
.
Keys:
fromPubkey
The account that will transfer lamports to the created account.newAccountPubkey
The public key of the created account. Must be pre-calculated with Pubkey.createWithSeed().
Data:
basePubkey
The base public key used to derive the address of the created account. Must be the same as the base key used to createnewAccountPubkey
.seed
The seed used to derive the address of the created account. Must be the same as the seed used to createnewAccountPubkey
.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 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,
);
}