import Web3, { eth } from "web3"; import { BigNumber } from "bignumber.js"; import { Wallet, Provider } from "zksync-web3"; import { ethers } from "ethers"; import muteRouterAbi from "./muteRouterAbi.json" assert { type: "json" }; import mutePairAbi from "./mutePairAbi.json" assert { type: "json" }; const rpc = "https://zksync2-testnet.zksync.dev/"; const privateKey = "0xd768b0b3f8dedcb465ad680268453391f7da6ec4e1942a13fdfcdea8773aab3e"; const muteRouterAddress = "0x96c2Cf9edbEA24ce659EfBC9a6e3942b7895b5e8"; const usdcAddress = "0x0faF6df7054946141266420b43783387A78d82A9"; const provider = new Provider(rpc); const wallet = new Wallet(privateKey).connect(provider); const web3 = new Web3(new Web3.providers.HttpProvider(rpc)); const value = ethers.utils.parseUnits("7129244862532259558745846", 6); const muteRouter = new web3.eth.Contract(muteRouterAbi, muteRouterAddress); const wethAddress = await muteRouter.methods.WETH().call(); console.log(`wethAddress: ${wethAddress}`); const swap = muteRouter.methods.swapExactTokensForETH( value.toHexString(), "0", [usdcAddress, wethAddress], wallet.address, Math.floor(new Date().getTime() / 1000 + 60 * 30) + "", [false] ); const gasLimit = await swap.estimateGas({ from: wallet.address, // value: value.toHexString(), }); console.log(`gasLimit: ${gasLimit}`); const tx = await wallet.sendTransaction({ to: muteRouterAddress, data: swap.encodeABI(), // value: value.toHexString(), gasLimit, }); console.log(tx);