YSExchangeToken.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // import 'package:flutter_dotenv/flutter_dotenv.dart' as dotenv;
  2. // import 'package:flutter_wallet/tools/YSTools.dart';
  3. // import 'package:http/http.dart';
  4. // import 'package:web3dart/web3dart.dart';
  5. // import 'package:web3dart/credentials.dart';
  6. //
  7. // import 'YSBip2.dart';
  8. // Future<void> exchange({required Map wall1,required Map wall2}) async {
  9. // // 要交换的代币合约地址,例如:CAKE
  10. // final tokenIn = EthereumAddress.fromHex('0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82');
  11. //
  12. // // 要接收的代币合约地址,例如:USDT
  13. // final tokenOut = EthereumAddress.fromHex('0x55d398326f99059ff775485246999027b3197955');
  14. // Wbe3Api? wbe3api = await Wbe3Api().getInstances();
  15. // Web3Client? client = Web3Client(YSData().rpc, Client());
  16. // DeployedContract? contract = await wbe3api?.fromAssets('asset/exchange.json', wall1['address']);
  17. // EthereumAddress fromaddress = EthereumAddress.fromHex(from);
  18. // final credentials = EthPrivateKey.fromHex(privatekey);
  19. // final networkId = await client?.getNetworkId();
  20. // final gasprice = await client?.getGasPrice();
  21. // BigInt gaslimit = BigInt.from(double.parse(gas) * pow(10, 0));
  22. // // LogUtil.d('decimals======${gaslimit.toInt()}');
  23. // // BigInt feeValue = BigInt.from(double.parse(fee) * pow(10, decimals));
  24. // LogUtil.d("gaslimit ====${gaslimit.toInt()}\n$parameters\n$gasprice");
  25. // var transaction = Transaction.callContract(
  26. // contract: contract!,
  27. // function: contract.function('swapExactTokensForTokens'),
  28. // parameters: [
  29. // BigInt.from(1000000000000000000), // 要交换的代币数量(注意小数位数)
  30. // BigInt.from(0), // 接收的最少代币数量
  31. // [tokenIn, tokenOut], // 路径
  32. // myAddress, // 接收地址
  33. // (DateTime.now().millisecondsSinceEpoch / 1000).floor() + 60 * 20, // 截止时间
  34. // ],
  35. // from: fromaddress,
  36. // gasPrice: gasprice,
  37. // maxGas: gaslimit.toInt());
  38. // await dotenv.load();
  39. //
  40. // final client = Web3Client(dotenv.env['RPC_URL'], Client(), socketConnector: () {
  41. // return Future.value();
  42. // });
  43. //
  44. // final credentials = await client.credentialsFromPrivateKey(dotenv.env['PRIVATE_KEY']);
  45. // final myAddress = await credentials.extractAddress();
  46. //
  47. // // PancakeSwap Router合约地址
  48. // final pancakeRouter = EthereumAddress.fromHex('0x10ED43C718714eb63d5aA57B78B54704E256024E');
  49. //
  50. // // 要交换的代币合约地址,例如:CAKE
  51. // final tokenIn = EthereumAddress.fromHex('0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82');
  52. //
  53. // // 要接收的代币合约地址,例如:USDT
  54. // final tokenOut = EthereumAddress.fromHex('0x55d398326f99059ff775485246999027b3197955');
  55. //
  56. // // 设置交易参数
  57. // final swapCall = Transaction.callContract(
  58. // contract: contract!,
  59. // function: contract.function('swapExactTokensForTokens'),
  60. // parameters: [
  61. // BigInt.from(1000000000000000000), // 要交换的代币数量(注意小数位数)
  62. // BigInt.from(0), // 接收的最少代币数量
  63. // [tokenIn, tokenOut], // 路径
  64. // myAddress, // 接收地址
  65. // (DateTime.now().millisecondsSinceEpoch / 1000).floor() + 60 * 20, // 截止时间
  66. // ],
  67. // from: myAddress,
  68. // gasPrice: EtherAmount.inWei(BigInt.one),
  69. // maxGas: 200000,
  70. // value: EtherAmount.zero(),
  71. // );
  72. //
  73. // // 发送交易
  74. // final txHash = await client.sendTransaction(credentials, swapCall, fetchChainIdFromNetworkId: true);
  75. //
  76. // LogUtil.d('Transaction hash: $txHash');
  77. // }