tokenTransfer method

Future<String> tokenTransfer(
  1. String tokenAddress,
  2. String receiverAddress,
  3. num tokensAmount,
  4. String privateKey,
)

Implementation

Future<String> tokenTransfer(
  String tokenAddress,
  String receiverAddress,
  num tokensAmount,
  String privateKey,
) async {
  EthereumAddress receiver = EthereumAddress.fromHex(receiverAddress);

  ///
  dynamic tokenDetails = await getTokenDetails(tokenAddress);
  int tokenDecimals = int.parse(tokenDetails["decimals"].toString());
  Decimal tokensAmountDecimal = Decimal.parse(tokensAmount.toString());
  Decimal decimals = Decimal.parse(pow(10, tokenDecimals).toString());
  BigInt amount = BigInt.parse((tokensAmountDecimal * decimals).toString());

  ///
  return await _callContract(
    'BasicToken',
    tokenAddress,
    'transfer',
    [receiver, amount],
    privateKey,
  );
}