Lesson 15 moralis server alternatives for Centralized DataBase with NextJS #5104
-
Hello everyone! I have a problem in Lesson 15, in which I am trying to create my own database and server in order to create the marketplace without using moralis. I have created a Listener using Ethers.js, so that when an event is executed, it inserts a JSON object with the information of the event in my mongo DB database. This listener has been introduced in the "getStaticProps()". But when an event occurs, the code runs 2 or more times randomly, sometimes 2, sometimes 4, which saves me in the database several identical objects. I want to send only one object to the database. I have tried everything, but I do not succeed. Could you look at my code and tell me where I am making the mistake? https://github.com/AGMASO/nextjs-app The listerner.js --> https://github.com/AGMASO/nextjs-app/blob/master/listener.js The SmartContract: https://github.com/AGMASO/contract-solidity Thank you in advance. Please a will appreciate if you could bring me some light, as i´m block this point. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@AGMASO Did you first test the same behaviour in your tests? Write a test which listens for the same event twice and see does the second time event emits. If on the contract side, it is not doing this then it is the issue on the frontend side. Frontend side this issue occurs when our components render multiple times and register the same event lister multiple times. |
Beta Was this translation helpful? Give feedback.
@AGMASO Did you first test the same behaviour in your tests? Write a test which listens for the same event twice and see does the second time event emits. If on the contract side, it is not doing this then it is the issue on the frontend side.
Frontend side this issue occurs when our components render multiple times and register the same event lister multiple times.
Also did you check these LINK1, LINK2