0

I have a smart contract inside which I have used Oraclize to get current time stamp. On few occasions the Oraclize callback fails due to out of Gas exception. How can one catch this failure and display error message on my dapp front end?

I tried below options :

  1. Monitor an event to catch if Oraclize returns any value or not. In my case it returns the current time stamp and moves ahead to logic inside the callback function. So here I could not catch the exception.
  2. Monitor a second event which is triggered when computations using the timestamp returned by Oraclize are complete. Here also I am unable to catch the exception as it runs out of gas before reaching the logic to trigger the success event.

As per my understanding the out of gas exception happens in between the above two events i.e. after sending value and before completing the processing it looses all the gas.

Please help to suggest what is the preferred way to handle this error and communicate to user on the frond end.

  • If the transaction fails none of the events will be triggered. – Jaime Aug 17 '18 at 14:54
  • then what is the ideal way to inform a user about it on the front end? – tanmay Aug 17 '18 at 14:57
  • can you show me the oraclize transaction that fails, in etherscan? – Jaime Aug 17 '18 at 15:01
  • sorry but I am testing locally using Ganache. Below is error message : } [2018-08-17T11:55:47.960Z] INFO sending __callback tx... { "contract_myid": "0x58a88cebdf576344bff17f2caa61d373f7a3beb619f71538a6e58dbd017405d1", "contract_address": "0x98d9f9e8debd4a632682ba207670d2a5acd3c489" } [2018-08-17T11:55:48.643Z] ERROR callback tx error, contract myid: 0x58a88cebdf576344bff17f2caa61d373f7a3beb619f71538a6e58dbd017405d1 { "message": "VM Exception while processing transaction: out of gas", – tanmay Aug 17 '18 at 15:05
  • I do not understand, what fails? the oraclize transaction to your contract? if so, how are you testing this locally?. – Jaime Aug 17 '18 at 15:17
0

A solution to this is to set in your app as compulsory gas amount the minimum that is necessary to run the function without running out of gas.

Also, If the call fails you can just check for transactions to your contract on each block. Identify which one is from oraclize and check if it failed or not.

Hope this helps

  • I did read about computing gas amount before calling the function but could not find any sample code which does so, would you be able to provide some references that I can use ? – tanmay Aug 17 '18 at 15:26

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.