// import 'package:flutter_dotenv/flutter_dotenv.dart' as dotenv;
// import 'package:flutter_wallet/tools/YSTools.dart';
// import 'package:http/http.dart';
// import 'package:web3dart/web3dart.dart';
// import 'package:web3dart/credentials.dart';
//
// import 'YSBip2.dart';

// Future<void> exchange({required Map wall1,required Map wall2}) async {
//   // 要交换的代币合约地址，例如：CAKE
//   final tokenIn = EthereumAddress.fromHex('0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82');
//
//   // 要接收的代币合约地址，例如：USDT
//   final tokenOut = EthereumAddress.fromHex('0x55d398326f99059ff775485246999027b3197955');
//   Wbe3Api? wbe3api = await Wbe3Api().getInstances();
//   Web3Client? client = Web3Client(YSData().rpc, Client());
//   DeployedContract? contract = await wbe3api?.fromAssets('asset/exchange.json', wall1['address']);
//   EthereumAddress fromaddress = EthereumAddress.fromHex(from);
//   final credentials = EthPrivateKey.fromHex(privatekey);
//   final networkId = await client?.getNetworkId();
//   final gasprice = await client?.getGasPrice();
//   BigInt gaslimit = BigInt.from(double.parse(gas) * pow(10, 0));
//   // LogUtil.d('decimals======${gaslimit.toInt()}');
//   // BigInt feeValue = BigInt.from(double.parse(fee) * pow(10, decimals));
//   LogUtil.d("gaslimit ====${gaslimit.toInt()}\n$parameters\n$gasprice");
//   var transaction = Transaction.callContract(
//       contract: contract!,
//       function: contract.function('swapExactTokensForTokens'),
//       parameters: [
//         BigInt.from(1000000000000000000), // 要交换的代币数量（注意小数位数）
//         BigInt.from(0), // 接收的最少代币数量
//         [tokenIn, tokenOut], // 路径
//         myAddress, // 接收地址
//         (DateTime.now().millisecondsSinceEpoch / 1000).floor() + 60 * 20, // 截止时间
//       ],
//       from: fromaddress,
//       gasPrice: gasprice,
//       maxGas: gaslimit.toInt());
//   await dotenv.load();
//
//   final client = Web3Client(dotenv.env['RPC_URL'], Client(), socketConnector: () {
//     return Future.value();
//   });
//
//   final credentials = await client.credentialsFromPrivateKey(dotenv.env['PRIVATE_KEY']);
//   final myAddress = await credentials.extractAddress();
//
//   // PancakeSwap Router合约地址
//   final pancakeRouter = EthereumAddress.fromHex('0x10ED43C718714eb63d5aA57B78B54704E256024E');
//
//   // 要交换的代币合约地址，例如：CAKE
//   final tokenIn = EthereumAddress.fromHex('0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82');
//
//   // 要接收的代币合约地址，例如：USDT
//   final tokenOut = EthereumAddress.fromHex('0x55d398326f99059ff775485246999027b3197955');
//
//   // 设置交易参数
//   final swapCall = Transaction.callContract(
//     contract: contract!,
//     function: contract.function('swapExactTokensForTokens'),
//     parameters: [
//       BigInt.from(1000000000000000000), // 要交换的代币数量（注意小数位数）
//       BigInt.from(0), // 接收的最少代币数量
//       [tokenIn, tokenOut], // 路径
//       myAddress, // 接收地址
//       (DateTime.now().millisecondsSinceEpoch / 1000).floor() + 60 * 20, // 截止时间
//     ],
//     from: myAddress,
//     gasPrice: EtherAmount.inWei(BigInt.one),
//     maxGas: 200000,
//     value: EtherAmount.zero(),
//   );
//
//   // 发送交易
//   final txHash = await client.sendTransaction(credentials, swapCall, fetchChainIdFromNetworkId: true);
//
//   LogUtil.d('Transaction hash: $txHash');
// }