1

We are storing user balances on smart contract and as well as on our local db, so that we dont always have to query blockchain for user balance.

For this we use contract events to update balances but we observed that listening contract events are a hit or miss. In our cases 3 out of 5 events were missed by our node js server and thus leading to discrepancy in balances.

What is the correct approach of syncing balances between local db and smart contract balances.

How does these exchange companies manage that?

  • I'd fix the missing events. – Ismael Jun 15 at 4:33
0

As @Ismael pointed out the event is there but some of your procedures is incorrect and needs to be fixed. There is no way for the events to not appear in the transaction information if the events are being emitted - of course it's possible that the transaction never reaches the event emitting part and in that case the contract code may be incorrect.

I'm not sure if you are aware of another approach so I'll explain it here. Blockchain data resides in individual nodes and you are also using some node to connect to the blockchain. Whenever your node sees a new block it stores its data locally so all of the blockchain's data is stored locally. So one option is to just get rid of your extra localdb and just read the blockchain data locally - local reads (calls) don't cost any gas.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.