transfer method
转账: 合并 ETH + ETH Tokens TODO: 本地存储+更新 nonce
Implementation
Future<String> transfer({
required String privateKey,
required String toAddress,
required num amount,
String? contractAddress,
}) async {
var txID = '';
/// do tx:
try {
/// 合约 Token:
if (contractAddress != null) {
txID = await sdkWeb3.tokenTransfer(contractAddress, toAddress, amount, privateKey);
logger.i('do wallet token transfer done: $contractAddress, $toAddress, amount:$amount, $txID');
} else {
var amountInWei = toWei(fromEther: amount as double).toInt();
if (amountInWei <= 0) {
logger.e('invalid amount, skip transfer, input amount:$amount, wei:$amountInWei ');
return '';
}
/// 主链 ETH:
txID = await sdkWeb3.transfer(toAddress, amountInWei, privateKey);
logger.i('do wallet transfer done: to:$toAddress, amount:$amount, wei:$amountInWei, $txID');
}
} catch (e, s) {
logger.e('do wallet transfer exception: $e, $s');
}
return txID;
}