0

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!

Ismael
  • 30,570
  • 21
  • 53
  • 96
Mayyy
  • 3
  • 3

1 Answers1

1

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/

  • thank you for answering, I just edited the question (I added a screenshot of the code), please help me if you have an idea – Mayyy Jun 17 '22 at 22:29
  • Okay, so you want to notify those two winners that they won right? You can still use the above suggested listener, in the callback function however you'll need to check if the currently connected useraddress in one of the addresses emitted in event, if it does that means the user is a winner & you can notify them using something like toast or whatever you like within callback itself. – Himanshu Pal Jun 18 '22 at 04:38