deleteNameRegistry static method

Future<TransactionInstruction> deleteNameRegistry({
  1. required SolanaRPC rpc,
  2. required String name,
  3. required SolAddress refundTargetKey,
  4. SolAddress? nameClass,
  5. SolAddress? nameParent,
})

Delete the name account and transfer the rent to the target.

Implementation

static Future<TransactionInstruction> deleteNameRegistry({
  /// The solana connection object to the RPC node
  required SolanaRPC rpc,

  /// The name of the name account
  required String name,

  /// The refund destination address
  required SolAddress refundTargetKey,

  /// The class of this name, if it exsists
  SolAddress? nameClass,

  /// The parent name of this name, if it exists
  SolAddress? nameParent,
}) async {
  final hashedName = NameServiceProgramUtils.getHashedName(name);
  final nameAccountKey = NameServiceProgramUtils.getNameAccountProgram(
    hashedName: hashedName,
    nameClass: nameClass,
    nameParent: nameParent,
  );

  SolAddress? nameOwner = nameClass;
  if (nameOwner == null) {
    final account = await rpc
        .request(SolanaRPCNameRegistryAccount(account: nameAccountKey));
    if (account == null) {
      throw const MessageException("Account not found.");
    }
    nameOwner = account.owner;
  }

  return NameServiceProgram.delete(
    nameAccountKey: nameAccountKey,
    refundTargetKey: refundTargetKey,
    nameOwnerKey: nameOwner,
  );
}