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
    Commented Jun 15, 2020 at 4:33

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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