Why does contract event fire when no events have happened? #2353
-
Describe the bug Correct me if I'm wrong, but shouldn't it only fire if an event happens? Meaning that when you call Reproduction steps useEffect(() => {
function newToken(
by: string,
address: string,
symbol: string
) {
window.ethereum.request({
method: 'wallet_watchAsset',
params: {
type: 'ERC20',
options: {
address,
symbol,
decimals: 18
}
}
});
}
factoryContract.on('TokenCreated', newToken);
}, [factoryContract]); Environment: |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
What is the event being shown? Keep in mind in v5 the events are scanned for starting in the current block, so if the current block has that event it will show up. In v6 only future blocks will emit an event. |
Beta Was this translation helpful? Give feedback.
-
Ah, I see. Is there a way to start using v6 already, or is it already out? If not, when does it release? |
Beta Was this translation helpful? Give feedback.
-
No, v6 is still just local on my computer. For v5, the best way to accomplish what you want above is: provider.once("block", () => {
factoryContract.on('TokenCreated', newToken);
}); That will start the event handler after the next block occurs. |
Beta Was this translation helpful? Give feedback.
-
I'm also experiencing this issue. The |
Beta Was this translation helpful? Give feedback.
No, v6 is still just local on my computer. For v5, the best way to accomplish what you want above is:
That will start the event handler after the next block occurs.