Search code examples
ethereumethers.js

ethers.js listener events fromblock doesn't work


I want to use ethers to listen to some contract events, and specify the starting block, fill in fromBlock according to the documentation but it doesn't work

const { ethers } = require("ethers");
async function main(){

    const provider = new ethers.providers.WebSocketProvider("wss:xxxxx")
    

    filter = {
        fromBlock: 12989984,
        // address: "0x123",
        topics: [
            ethers.utils.id("Transfer(address,address,uint256)")
        ]
    }
    provider.on(filter, (log, event) => {
        console.log(log)
    })

}
main()

The code looks like this, I want to listen to the transfer event from block 12989984, but it actually starts from the latest block


Solution

  • As it is said here : https://github.com/ethers-io/ethers.js/issues/498, the provider event filter object doesn't support fromBlock anymore.