createNameRegistry static method

Future<TransactionInstruction> createNameRegistry({
  1. required SolanaRPC rpc,
  2. required String name,
  3. required int space,
  4. required SolAddress payerKey,
  5. required SolAddress nameOwner,
  6. BigInt? lamports,
  7. SolAddress? nameClass,
  8. 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;
}