transfer function
Sends an transfer transaction to an ERC 20 contract for a certain amount of tokens
@param {BigInt} amount - Amount of tokens to be approved by the ERC 20 contract @param {String} accountAddress - The Ethereum address of the transaction sender @param {String} tokenContractAddress - The token smart contract address @param {String} tokenContractName - The token smart contract name @param {String} providerUrl - Network url (i.e, http://localhost:8545). Optional @param {Object} signerData - Signer data used to build a Signer to send the transaction
@returns {Promise} transaction
Implementation
Future<bool> transfer(
BigInt amount,
String fromAddress,
String toAddress,
String tokenContractAddress,
String tokenContractName,
Credentials credentials,
{gasLimit = GAS_LIMIT_HIGH,
gasPrice = GAS_MULTIPLIER}
/*{TransferEvent onTransfer,
Function onError}*/
) async {
EthereumAddress from = EthereumAddress.fromHex(fromAddress);
EthereumAddress to = EthereumAddress.fromHex(toAddress);
final contract = await ContractParser.fromAssets(
'ERC20ABI.json', tokenContractAddress.toString(), tokenContractName);
/*StreamSubscription event;
// Workaround once sendTransacton doesn't return a Promise containing confirmation / receipt
if (onTransfer != null) {
event = listenTransfer(
(from, to, value) async {
onTransfer(from, to, value);
await event.cancel();
},
contract,
take: 1,
);
}*/
try {
Transaction transaction = Transaction.callContract(
contract: contract,
function: _transfer(contract),
parameters: [to, amount],
from: from,
);
String txHash = await HermezSDK.currentWeb3Client!.sendTransaction(
credentials, transaction,
chainId: getCurrentEnvironment()!.chainId);
print(txHash);
return true;
} catch (e) {
print(e.toString());
/*if (onError != null) {
onError(ex);
}
return null;*/
return false;
}
}