transferAlias method Null safety

Future<MsgTransferAliasResponse> transferAlias(
  1. String alias,
  2. String currentOwner,
  3. int amount,
  4. [ResponseCallback<MsgTransferAliasResponse>? callback]
)

Transferring a Subdomain

Transfers an existing alias listed for sale from the account which listed it, to the current active account. A succesful transaction will return a MsgTransferAliasResponse, and will return an error if the provided amount is less than the listed price, or if the alias is not listed for sale by the currentOwner.

final res = await MotorFlutter.to.transferAlias('hulahoop', 'did:snr:abc123', 42.0);
if (res == null) {
   throw Exception('Failed to transfer alias');
}

// Print updated domains list
final allOwnedAliases = res.aliases.where((alias) => !alias.isForSale);
print(allOwnedAliases); // prints: [hulahoop.snr] or [hulahoop]

Next Steps

Implementation

Future<MsgTransferAliasResponse> transferAlias(String alias, String currentOwner, int amount,
    [ResponseCallback<MsgTransferAliasResponse>? callback]) async {
  final resp = await MotorFlutterPlatform.instance.transferAlias(MsgTransferAlias(
    alias: alias,
    amount: amount,
    recipient: currentOwner,
    creator: address.value,
  ));
  if (resp == null) {
    throw UnmarshalException<MsgTransferAliasResponse>();
  }
  domains.addAll(resp.whoIs.alias);
  domains.refresh();
  callback?.call(resp);
  return resp;
}