简体   繁体   English

Web3 getPastEvents 返回错误:超出限制

[英]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.我正在使用 web3 function getPastEvents并且出现错误:返回错误:超出限制我也更改了 RPC url 但他们发生了同样的错误。 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.在 function getPastEvents() 中,您必须将第一个参数作为您要获取数据的事件名称。 The name should be as same as in your contract and passed into a string.该名称应与您的合同中的名称相同,并传递到一个字符串中。

Actually, this is an RPC problem.实际上,这是一个 RPC 问题。 I replaced https://bsc-dataseed.binance.org/ with https://bscrpc.com .我将https://bsc-dataseed.binance.org/替换为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.公共 RPC URL,如https://bsc-dataseed.binance.org/https://bscrpc.com具有速率限制,以防止人们过度使用它。

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.测试没问题,但在生产中,您应该使用自己的节点或区块链 API,例如 Infura、Alchemy、QuickNode 或任何其他节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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