[英]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.