setSubdomainAddress method

Future<String> setSubdomainAddress(
  1. AptosAccount account,
  2. String subdomainName,
  3. String domainName,
  4. String target, {
  5. BigInt? maxGasAmount,
  6. BigInt? gasUnitPrice,
  7. BigInt? expireTimestamp,
})

account AptosAccount the owner of the domain name. subdomainName subdomain name to mint. domainName Aptos domain name to mint. target the target address for the subdomain. Return the hash of the pending transaction submitted to the API.

Implementation

Future<String> setSubdomainAddress(
  AptosAccount account,
  String subdomainName,
  String domainName,
  String target,{
  BigInt? maxGasAmount,
  BigInt? gasUnitPrice,
  BigInt? expireTimestamp
}) async {
  final standardizeAddress = AccountAddress.standardizeAddress(target);

  // check if the name is valid
  if (!nameComponentPattern.hasMatch(domainName)) {
    throw ArgumentError("Name $domainName is not valid");
  }
  // check if the name is valid
  if (!nameComponentPattern.hasMatch(subdomainName)) {
    throw ArgumentError("Name $subdomainName is not valid");
  }

  final buildConfig = ABIBuilderConfig(
    sender: account.address,
    maxGasAmount: maxGasAmount,
    gasUnitPrice: gasUnitPrice,
    expSecFromNow: expireTimestamp
  );
  final builder = TransactionBuilderRemoteABI(aptosClient, buildConfig);
  final rawTxn = await builder.build(
    "$contractAddress::domains::set_subdomain_address",
    [],
    [subdomainName, domainName, standardizeAddress]
  );

  final bcsTxn = AptosClient.generateBCSTransaction(account, rawTxn);
  final pendingTransaction = await aptosClient.submitSignedBCSTransaction(bcsTxn);

  return pendingTransaction["hash"];
}