-
Hi everybody! I don't understand how to get events with ethers v6, I tried in this way following the docs if (window.ethereum == null) {
console.log("Metamask is not installed; using read-only defaults");
const provider = ethers.getDefaultProvider();
// ...
} else {
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
const abi = BiteIDNFT_abi;
const contractNFT = new ethers.Contract("contractaddress", abi, signer);
await contractNFT.safeMint("contractaddress", "ipfs://test");
contractNFT.on("*", (from, to, tokenId, event) => {
console.log(`${ from } => ${ to }: ${ tokenId }`)
// Optionally, convenience method to stop listening
event.removeListener();
});
} and the nft was correctly minted on the blockchain with the correct Transfer event. But on the browser console I get this [object Object] => undefined: undefined I'm using Metamask and the contract is on Polygon Testnet. Any tips? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You can’t destruct events that are emitted from So it should look like |
Beta Was this translation helpful? Give feedback.
You can’t destruct events that are emitted from
"*"
, since every event has a potentially different signature. So you only get the Event payload, that object you are getting.So it should look like
provider.on("*", (log, evt) => { console.log(log); })
.