How to Retrieve Event Logs Generated by a Smart Contract in Solidity

blockchaincontract-developmenteventssolidity

I'm trying to build a MERN app with a web3 part, I have a typical authentication step in the beginning (centrelized), then the user will connect his wallet and send a transaction to the smart contract through the function createBid.

this is the code of the function of the smart contract:
enter image description here

in findwinner() there is an event that outputs the 2 winning addresses, my question is how I can notify the 2 users related to that addresses, I mean some methodes related to MERN stack and ethers.js because I'm using them for the first time and thank you!

Best Answer

you can listen for events in frontend, I'm assuming you're using ethers for contract interaction, ethers provide helpers for that, e.g.

ethers.provider.on(contract.filters.Approval(), (args) => {
      // args is the data emitted in event, which can be used as required
    });

I hope this may help you further https://docs.ethers.io/v5/concepts/events/

Related Topic