I am trying to get the specific past events for my contract, named 'Transfer'; when I try to simply use the following code, it gives empty result.
myContract.getPastEvents("Transfer").then(function (event) {
console.log(event);
})
//output is: []
While when I run with some optional arguments, it gives proper output as expected of two events from my contract.
myContract.getPastEvents("Transfer", { fromBlock: 25635490, toBlock: 25635656 }).then(function (event) {
console.log(event);
})
//output is: Array[2] -- which is array of two events as expected
The contract is hosted on polygon mumbai testnet - https://mumbai.polygonscan.com/address/0x1d7f71e9dd4283B5b4431e7a51498f4C14b18715
And the reference to web3js documentation which cites that fromBlock and toBlock are optional arguments, so as a newbie I assume that it scans from block 0 to the latest block, please help me with this.
Contract.getPastEvents Docs link
fromBlock/toBlock - Number|String|BN|BigNumber (optional): The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as "earliest", "latest" and "pending" can also be used.