2

I'm using oraclize to fetch some data from the outside world. Oraclize calls the __callback method of my smart contract. For this call oraclize have to pay gas and there is a function to set the gas limit for this call.

My problem is now: If I set the gas limit to 150000 the transaction will fail with the message VM Exception while processing transaction: out of gas. If I put the gas limit to 300,000 the transaction succeeds but it only uses 90,000 gas. The gas limit is shown correctly in the transaction logs.

  • 1
    Does your callback always produce the same output, or it depends on received data? I had this problem too, that i had provide more gas because depending on the data received from Oraclize my function would use either 150000 or 500000. Sadly there's nothing you can change if that's the case. Also it would change from time to time how much gas is used, not really sure what causes this. – Maxpeinas Aug 13 '18 at 16:45
  • 2
    probably you are deleting some registers during the execution, which will be returned but after execution. The problem with oraclize is that in cases like this the users will lose the gas because they state in their website that they do not return the unused gas. – Jaime Aug 13 '18 at 17:10
  • @Maxpeinas for testing I ignored the parameters of the __callback function and got the same result. – MarcS82 Aug 13 '18 at 17:41
  • @Jaime I'm using a delete inside the callback. Maybe that's the reason. I will do more research. – MarcS82 Aug 13 '18 at 17:42
1

Sounds like you are receiving a gas refund.

If during the execution of a transaction, you end up freeing up some storage (setting variables to zero-values, or delete operations), you receive a refund in gas proportional to the amount of storage you have freed up.

This refund is only applied at the end of the execution cycle. Thus, while the transaction executes, you require a gas limit large enough to accommodate all the operations without the refund being accounted for.

There is no way around this, and you will end up spending less gas than your gas limit, but it must still be set high enough to cover everything without the refund.

  • 1
    Just to add to this: gas used with __callback function is not refunded to the user, but the Oraclize itself, so the user doesn't get any refund for unused gas. – Maxpeinas Aug 14 '18 at 17:29

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.