approve method

Future<String> approve(
  1. String owner_PrivateKey,
  2. dynamic contractadd,
  3. dynamic spenderadd,
  4. dynamic approve_value,
)

Approve the passed address to spend the specified amount of tokens on behalf of owner. owner_PrivateKey : Owner Private key. contractAdd : Token Address. spenderadd : The address which will spend the funds. approve_value : The amount of tokens to be spent.

Implementation

Future<String> approve(
    String owner_PrivateKey, contractadd, spenderadd, approve_value) async {
  final String privateKey = owner_PrivateKey;
  final credentials = await EthPrivateKey.fromHex(privateKey);

  final EthereumAddress contractAddr = EthereumAddress.fromHex(contractadd);

  final contract = DeployedContract(
      ContractAbi.fromJson(abiString, 'XRC20'), contractAddr);
  final tokenApprove = contract.function('approve');
  final EthereumAddress spender = EthereumAddress.fromHex(spenderadd);
  final approve = await Transaction.callContract(
      contract: contract,
      function: tokenApprove,
      parameters: [spender, BigInt.from(approve_value)]);
  final approvel = await client.sendTransaction(credentials, approve,
      chainId: null, fetchChainIdFromNetworkId: true);

  return ('$approvel');
}