mintAptosName method
Mint a new Aptos name.
account AptosAccount where collection will be created.
domainName Aptos domain name to mint.
years year duration of the domain name.
Return the hash of the pending transaction submitted to the API.
Implementation
Future<String> mintAptosName(
AptosAccount account,
String domainName,{
int years = 1,
BigInt? maxGasAmount,
BigInt? gasUnitPrice,
BigInt? expireTimestamp
}) async {
// check if the name is valid
if (!nameComponentPattern.hasMatch(domainName)) {
throw ArgumentError("Name $domainName is not valid");
}
// check if the name is available
final registration = await getRegistrationForDomainName(domainName);
if (registration != null) {
final now = (DateTime.now().millisecondsSinceEpoch / 1000).ceil();
if (now < registration.$2) {
throw ArgumentError("Name $domainName is not available");
}
}
final buildConfig = ABIBuilderConfig(
sender: account.address,
maxGasAmount: maxGasAmount,
gasUnitPrice: gasUnitPrice,
expSecFromNow: expireTimestamp
);
final builder = TransactionBuilderRemoteABI(aptosClient, buildConfig);
final rawTxn = await builder.build("$contractAddress::domains::register_domain", [], [domainName, years]);
final bcsTxn = AptosClient.generateBCSTransaction(account, rawTxn);
final pendingTransaction = await aptosClient.submitSignedBCSTransaction(bcsTxn);
return pendingTransaction["hash"];
}