muteswap.mjs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import Web3, { eth } from "web3";
  2. import { BigNumber } from "bignumber.js";
  3. import { Wallet, Provider } from "zksync-web3";
  4. import { ethers } from "ethers";
  5. import muteRouterAbi from "./muteRouterAbi.json" assert { type: "json" };
  6. import mutePairAbi from "./mutePairAbi.json" assert { type: "json" };
  7. const rpc = "https://zksync2-testnet.zksync.dev/";
  8. const privateKey = "0xd768b0b3f8dedcb465ad680268453391f7da6ec4e1942a13fdfcdea8773aab3e";
  9. const muteRouterAddress = "0x96c2Cf9edbEA24ce659EfBC9a6e3942b7895b5e8";
  10. const usdcAddress = "0x0faF6df7054946141266420b43783387A78d82A9";
  11. const provider = new Provider(rpc);
  12. const wallet = new Wallet(privateKey).connect(provider);
  13. const web3 = new Web3(new Web3.providers.HttpProvider(rpc));
  14. const value = ethers.utils.parseUnits("7129244862532259558745846", 6);
  15. const muteRouter = new web3.eth.Contract(muteRouterAbi, muteRouterAddress);
  16. const wethAddress = await muteRouter.methods.WETH().call();
  17. console.log(`wethAddress: ${wethAddress}`);
  18. const swap = muteRouter.methods.swapExactTokensForETH(
  19. value.toHexString(),
  20. "0",
  21. [usdcAddress, wethAddress],
  22. wallet.address,
  23. Math.floor(new Date().getTime() / 1000 + 60 * 30) + "",
  24. [false]
  25. );
  26. const gasLimit = await swap.estimateGas({
  27. from: wallet.address,
  28. // value: value.toHexString(),
  29. });
  30. console.log(`gasLimit: ${gasLimit}`);
  31. const tx = await wallet.sendTransaction({
  32. to: muteRouterAddress,
  33. data: swap.encodeABI(),
  34. // value: value.toHexString(),
  35. gasLimit,
  36. });
  37. console.log(tx);