I just started learning ethers
, here is my code:
(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. As I see in the contract name of that event is probably Atomic Match_
or atomicMatch_
in ABI.
For ABI I just copy pasted whole contract to https://remix.ethereum.org/ website and copied abi code. 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...
Ethers contract.on()
(docs) is invoked when an event with the specified name is emitted.
Your snippet is passing a function name (atomicMatch_
), not an event name.
The atomicMatch_
function effectively emits the event named OrdersMatched
. That's why changing the handler to contract.on('OrdersMatched')
fixes the issue.
Also, the sandbox is using a built-in provider under the getDefaultProvider()
, which is communicating with the app over WSS. Your snippet is using a HTTPS provider that is by design unable to listen to events. You'll need to use a WSS provider as well (they are supported by Infura).