简体   繁体   中英

Listen to uniswap events by ethers

I have a simple code that aimed to listen to Uniswap Router V3 protocol events

import { ethers } from "ethers";
import { ALCHEMY_HTTP } from "./const";

async function main() {
  const provider = new ethers.providers.JsonRpcProvider(ALCHEMY_HTTP);

  const filter = {
    address: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
  };
  provider.on(filter, (event: any) => {
    console.log(event);
  });
}

main();

I don't receive any events. If I change the address to for example Metamask Router or DAI contract I receive corresponded events.

I'm sure that the contract address for Uniswap Router version 3 is correct. The contract addresses are as below link: https://docs.uniswap.org/protocol/reference/deployments

And also as I check the etherscan, it has a lot of transactions and events. https://etherscan.io/address/0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45

Is there any difference between smart contracts in listening to events?!

Why I don't receive events only for Uniswap V3 Router?

As I understand it, you don't see events because they simply don't exist. If you open the smartcontract in etherscan and go to the tab of the events, it will be empty. The DAI smartcontract, on the other hand, has a lot of events.

Uniswap SwapRouter02 合约

I also suggest you look at how Uniswap Router smartcontract works - Uniswap Swap Router . I think it can be useful, because if you look there you can also find the answer why there are no events.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM