【问题标题】:Web3 getPastEvents Returned error: limit exceededWeb3 getPastEvents 返回错误:超出限制
【发布时间】:2022-12-14 16:40:15
【问题描述】:

我正在使用 web3 功能获取过去事件我收到错误:返回错误:超出限制我也更改了 RPC url,但他们发生了同样的错误。 还有其他方法可以获取事件数据吗?

这是我的代码:

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

【问题讨论】:

    标签: node.js blockchain solidity web3js bscscan


    【解决方案1】:

    在函数 getPastEvents() 中,您必须将第一个参数作为您要获取数据的事件名称。该名称应与您的合同中的名称相同,并传递到一个字符串中。

    【讨论】:

      【解决方案2】:

      实际上,这是一个 RPC 问题。我用 https://bscrpc.com 替换了 https://bsc-dataseed.binance.org/。现在它工作正常。

      【讨论】:

        【解决方案3】:

        公共 RPC URL,如 https://bsc-dataseed.binance.org/https://bscrpc.com 具有速率限制,以防止人们过度使用它。

        测试没问题,但在生产中,您应该使用自己的节点或区块链 API,如 Infura、Alchemy、QuickNode 或任何其他 API。

        【讨论】:

          猜你喜欢
          • 2018-05-05
          • 1970-01-01
          • 2016-09-29
          • 2018-10-15
          • 2019-01-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多