decode.mjs 1.8 KB

123456789101112131415161718192021
  1. import abiDecoder from "abi-decoder";
  2. import SyncSwapRouterAbi from "./SyncSwapRouter.json" assert { type: "json" };
  3. import Web3, { eth } from "web3";
  4. import { Wallet, Provider } from "zksync-web3";
  5. const rpc = "https://zksync2-testnet.zksync.dev/";
  6. const walletAddress = "0x93626e5d46772652a8100a3ffc34d7bad8b29e00";
  7. const privateKey = "0xd768b0b3f8dedcb465ad680268453391f7da6ec4e1942a13fdfcdea8773aab3e";
  8. const data =
  9. "0x94ec6d78000000000000000000000000cfa3d5c02d827c0d1a48b4241700aebf751458fa00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000001fb50b56e2e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000faf6df7054946141266420b43783387a78d82a90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000093626e5d46772652a8100a3ffc34d7bad8b29e000000000000000000000000000000000000000000000000000000000000000000";
  10. const provider = new Provider(rpc);
  11. const wallet = new Wallet(privateKey).connect(provider);
  12. console.log("rpc: ", rpc);
  13. const web3 = new Web3(new Web3.providers.HttpProvider(rpc));
  14. const account = web3.eth.accounts.privateKeyToAccount(privateKey);
  15. console.log("address: ", account.address);
  16. const abi = SyncSwapRouterAbi.find((i) => i.name === "addLiquidity2");
  17. console.log("abi: ", abi.inputs);
  18. const params = web3.eth.abi.decodeParameters(abi.inputs, data);
  19. console.log("params: ", params);