简体   繁体   中英

Web3 getPastEvents Returned error: limit exceeded

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);

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.

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

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.

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