transferNameOwnership static method

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

Change the owner of a given name account.

Implementation

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

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

    /// The new owner to be set
    required SolAddress newOwner,

    /// 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? currentNameOwner = nameClass;
  if (currentNameOwner == null) {
    final account = await rpc
        .request(SolanaRPCNameRegistryAccount(account: nameAccountKey));
    if (account == null) {
      throw const MessageException("Account not found.");
    }
    currentNameOwner = account.owner;
  }

  return NameServiceProgram.transfer(
    nameAccountKey: nameAccountKey,
    layout: NameServiceTransferLayout(newOwnerKey: newOwner),
    currentNameOwnerKey: currentNameOwner,
    nameClassKey: nameClass,
    nameParent: nameParent,
  );
}