Skip to content

Instantly share code, notes, and snippets.

@zh
Created February 20, 2022 12:49
Show Gist options
  • Save zh/6f69f441483c067e316726548c782c4b to your computer and use it in GitHub Desktop.
Save zh/6f69f441483c067e316726548c782c4b to your computer and use it in GitHub Desktop.
refresh with events
const setEventHandlers = () => {
if (!contract || !currentAccount) {
return;
}
console.log('add event contract handlers');
try {
contract.on('DomainMinted', async () => {
console.log('event: domain minted');
await fetchMints();
});
contract.on('MetadataUpdated', async () => {
console.log('event: metadata updated');
await fetchMints();
});
} catch (error) {
console.log(error);
}
};
useEffect(() => {
if (network === 'Polygon Mumbai Testnet') {
fetchMints();
setEventHandlers();
}
}, [!!contract, currentAccount]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment