createNameRegistry static method
Future<TransactionInstruction>
createNameRegistry({
- required SolanaRPC rpc,
- required String name,
- required int space,
- required SolAddress payerKey,
- required SolAddress nameOwner,
- BigInt? lamports,
- SolAddress? nameClass,
- SolAddress? parentName,
Creates a name account with the given rent budget, allocated space, owner and class
Implementation
static Future<TransactionInstruction> createNameRegistry(
{
/// The solana connection object to the RPC node
required SolanaRPC rpc,
/// The name of the new account
required String name,
/// The space in bytes allocated to the account
required int space,
/// The allocation cost payer
required SolAddress payerKey,
/// The pubkey to be set as owner of the new name account
required SolAddress nameOwner,
/// The budget to be set for the name account. If not specified, it'll be the minimum for rent exemption
BigInt? lamports,
/// The class of this new name
SolAddress? nameClass,
/// The parent name of the new name. If specified its owner needs to sign
SolAddress? parentName}) async {
final hashedName = NameServiceProgramUtils.getHashedName(name);
final nameAccountKey = NameServiceProgramUtils.getNameAccountProgram(
hashedName: hashedName,
nameClass: nameClass,
nameParent: parentName,
);
final BigInt balance = lamports ??
await rpc
.request(SolanaRPCGetMinimumBalanceForRentExemption(size: space));
SolAddress? nameParentOwner;
if (parentName != null) {
final account =
await rpc.request(SolanaRPCNameRegistryAccount(account: parentName));
if (account == null) {
throw const MessageException("Account not found.");
}
nameParentOwner = account.owner;
}
final createNameInstr = NameServiceProgram.create(
nameKey: nameAccountKey,
nameOwnerKey: nameOwner,
payerKey: payerKey,
layout: NameServiceCreateLayout(
lamports: balance, hashedName: hashedName, space: space),
nameClassKey: nameClass,
nameParent: parentName,
nameParentOwner: nameParentOwner,
);
return createNameInstr;
}