I am new in dapps world and I want to deduct balance/points when a user buys an item currently I am unable to update balance because sometimes transaction got failed, dropped, or successes after 30 seconds to 2 minutes time, so how to subscribe or listen to transaction event than I can perform some action.

redeemPoints(from, to, price, (err, res) => {
      console.log(res) //old value of balance 

Thanks in Advance.

  • Could you please elaborate a bit more on what you are trying to achieve? – Henk Aug 16 '18 at 8:27
  • Actually I wanna deduct point when user buy some product, and I even don't know the transaction is success, fail, or drop transaction taking 1 - 10 minutes time – Umair Ahmed Aug 16 '18 at 8:54
  • @UmairAhmed do you mean that you change the state of another database according to the result of the transaction on the blockchain ? – Nicolas Massart Aug 22 '18 at 9:32

You can use events in the solidity smart contract. In simple terms, the purpose of an Event is to provide JavaScript callbacks in a user interface, which allows you to execute code based on whether or not the event was successful or if it errored.

  • I need to fire an event from ABI and listen on client right ? – Umair Ahmed Aug 16 '18 at 9:23
  • Yes, you need to trigger an event in the smart contract and watch it in a front end. – Soham Lawar Aug 16 '18 at 9:30

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