Web3 getPastEvents Returned error: limit exceeded

2k views Asked by At

I am using web3 function getPastEvents and I am getting error: Returned error: limit exceeded I also changed RPC url but same error occured their. Is there any other way to get event data ?

this is my code:

const http = require("http");
const cron = require('node-cron');
const { randomBytes } = require("crypto");
const web3 = new Web3("https://bsc-dataseed.binance.org/");
//console.log("Hello This",web3);
//console.log("hello");
const dexABI =contractAbi;
const contract_address = "0xd19EA9d72828444BC7bAE231fBa66F8050e72b1b";
const contract = new web3.eth.Contract(dexABI, contract_address);

async function generateEventQuery(result) {
  console.log(result);
  return ;
}


http
  .createServer((req, res) => {
     web3.eth
      .getBlockNumber()
      .then((d) => {
        let current_block = d;
        console.log(current_block);
       contract
      .getPastEvents({
        fromBlock: Number(23390147),
        toBlock: Number(23390147)+100,
      })
      .then( async(events) => {
      let resu = await generateEventQuery(events);
     
      })
      .catch((e) => {
          console.log("Err",e)
        res.write("Err:" + JSON.stringify(e));
        res.end();
      });
      })
      .catch((e) => e);
    })
  
  
  .listen(8080);
3

There are 3 answers

0
Sumit Sharma On BEST ANSWER

Actually, this is an RPC problem. I replaced https://bsc-dataseed.binance.org/ with https://bscrpc.com. Now it works properly.

0
0xAnthony On

Public RPC URLs like https://bsc-dataseed.binance.org/ or https://bscrpc.com have rate-limiting to prevent people from over using it.

It's fine for testing but in production you should use your own node or a blockchain API like Infura, Alchemy, QuickNode or any other.

0
Chetan Ukani On

in the function getPastEvents() you have to take the first parameter as your event name which you want to fetch the data. The name should be as same as in your contract and passed into a string.