简体   繁体   English

以太坊合约方法“无数学事件”错误

[英]Ethers contract on method "No mathing event" error

I just started learning ethers , here is my code:我刚开始学习ethers ,这是我的代码:

(async () => {
  const connection = new ethers.providers.JsonRpcProvider(
    "https://mainnet.infura.io/v3/key"
  );

  const contract = new ethers.Contract(
    "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
    abi,
    connection
  );

  contract.on("atomicMatch_", (...args) => {
    console.log(args);
  });
})();

so the contract is opensea main contract - link I would like to listen to sales transactions/events.所以合同是opensea主合同- 链接我想听销售交易/事件。 As I see in the contract name of that event is probably Atomic Match_ or atomicMatch_ in ABI.正如我在该事件的合同名称中看到的那样,ABI 中的Atomic Match_atomicMatch_可能是。 For ABI I just copy pasted whole contract to https://remix.ethereum.org/ website and copied abi code.对于 ABI,我只需将粘贴的整个合约复制到https://remix.ethereum.org/网站并复制 abi 代码。 The problem is I am getting this error now:问题是我现在收到此错误:

Error: no matching event (argument="name", value="atomicMatch_", code=INVALID_ARGUMENT, version=abi/5.5.0)

What is wrong here?这里有什么问题? I tried both names of event but I get the same error over and over...我尝试了两个事件的名称,但我一遍又一遍地得到同样的错误......

@edit here is sandbox for it, what is weird when I change event name to OrdersMatched for example it works totally fine... @edit 这里是它的沙箱,当我将事件名称更改为OrdersMatched时很奇怪,例如它工作得很好......

Ethers contract.on() ( docs ) is invoked when an event with the specified name is emitted.当发出具有指定名称的事件时,将调用 Ethers contract.on() ( docs )。

Your snippet is passing a function name ( atomicMatch_ ), not an event name.您的代码段传递的是 function 名称( atomicMatch_ ),而不是事件名称。

The atomicMatch_ function effectively emits the event named OrdersMatched . atomicMatch_ function 有效地发出名为OrdersMatched的事件。 That's why changing the handler to contract.on('OrdersMatched') fixes the issue.这就是为什么将处理程序更改为contract.on('OrdersMatched')可以解决问题的原因。


Also, the sandbox is using a built-in provider under the getDefaultProvider() , which is communicating with the app over WSS.此外,沙盒使用getDefaultProvider()下的内置提供程序,它通过 WSS 与应用程序通信。 Your snippet is using a HTTPS provider that is by design unable to listen to events.您的代码段正在使用 HTTPS 提供程序,该提供程序在设计上无法侦听事件。 You'll need to use a WSS provider as well (they are supported by Infura).您还需要使用 WSS 提供程序(Infura 支持它们)。

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

相关问题 在 ethers.js 中设置合约方法的气体限制 - Set gas limit on contract method in ethers.js 使用 ethers 库与智能合约交互时出现 ENS 错误 - Getting an ENS error when interacting with a Smart Contract using ethers library 通过以太币与 BSC 上的智能合约进行通信会给出 -32603 错误代码 - Communicating with a Smart Contract on BSC over ethers gives -32603 error code Ethers.js 合约工厂 - Ethers.js Contract Factories 我使用 ethers.js 部署合约,但返回错误:未捕获(承诺)错误:未知交易覆盖 0 - I use ethers.js deployment contract, but returned error: uncaught (in promise) error: unknown transaction override 0 ethers.js 合同 object 出现错误:未捕获类型错误:无法读取未定义的属性(读取“地图”) - ethers.js Contract object gets error: Uncaught TypeError: Cannot read properties of undefined (reading 'map') 如何减少由于 ethers.js 事件监听器而出现的“RPC 方法调用”的频率? - How to reduce the frequency of the "RPC method invocations" arose as a result of ethers.js event listener? 如何使用安全帽和以太币监控 Solidity 智能合约上的事件? - How to monitor events on an Solidity Smart Contract using hardhat and ethers? Ethers js 在使用合约对象时设置 noonce - Ethers js set noonce when using contract object 使用 Ethers.js 检索 Solidity 事件数据 - Retrieving Solidity Event Data with Ethers.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM