swapToken method

Future<String> swapToken({
  1. required String privateKey,
  2. required String fromAddress,
  3. required String toAddress,
  4. required String data,
  5. BigInt? value,
  6. int? maxGas,
})

此版本有效:

Implementation

Future<String> swapToken({
  required String privateKey,
  required String fromAddress,
  required String toAddress,
  required String data,
  BigInt? value, // chainType=ETH, eth2token, set value //  token2eth, set 0
  int? maxGas,
}) async {
  var cred = await getCredentials(privateKey);

  return sdkWeb3.sendTransactionEx(
    cred,
    Transaction(
      from: EthereumAddress.fromHex(fromAddress),
      to: EthereumAddress.fromHex(toAddress),
      data: hexToBytes(data),
      value: EtherAmount.inWei(value ?? 0 as BigInt),
      maxGas: maxGas ?? 10000000, // todo: need fix
    ),
  );
}