Every time I try to run the getPairPrice function in the contract bellow I get an out of gas error. My contract always has a balance before I call the function, 2 ethers to be exact, but I still get the out of gas error. Why is that?

pragma solidity ^0.4.3;
import "github.com/oraclize/ethereum-api/oraclizeAPI_0.4.sol";

contract BinaryTrading is usingOraclize {
  // ********* //
  // ********* //
  address minter;

  uint balance;

  string public ethusd;

  function BinaryTrading() {
    minter = msg.sender;
    oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);

  // This function is the fallback function
  function () payable {
    balance += msg.value;

  function updatePrice(string newPrice) {
      ethusd = newPrice;

  // This function is called when the oraclized request results are ready
  function __callback(bytes32 myid, string result, bytes proof) {
    if (msg.sender != oraclize_cbAddress()) throw;
    ethusd = result;

  // IMPORTANT: Add private when in production, so that I can only call what will not give an error
  function getPairPrice() {
    bytes32 myid = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD");


I have also tried running the code changing the gas value to 2000000.

By changing this line:

bytes32 myid = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD");


bytes32 myid = oraclize_query("URL", "json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD", 2000000);

Is 2000000 gas not enough to cover updating a variable?

Please let me know what might be causing this. I am testing it using the online solidity compiler. When I create the contract using MetaMask it says "Transaction Error. Exception thrown in contract code." That same message appears when I call the getPairPrice function but not the others.

Here is one of those test contracts I created using the code above: https://testnet.etherscan.io/address/0x2831899baa68f655764d17e7a65c8e526e4ac53c

1 Answer 1


Is this the failing transaction? https://testnet.etherscan.io/tx/0x369c48423586f5cdffefb2d202d6588e3874b6f1075b3feda205c7718f13dff3

This shows you sending only 78525 gas, which is probably not enough to call your getPairPrice() function, which in turn needs to pay for some initial oraclize functions - I think it'll be a price lookup and an event write, and possibly some storage.

The gas parameter you're adding to oraclize_query() isn't for your call to getPairPrice(), it's for the call that Oraclize will make later to your __callback() function. That will be done in a separate transaction, and that part will need to come out of the value that gets transferred from your contract balance when you send oraclize_query(), not the gas that you send to getPairPrice().

  • On the solidity browser compiler I set the gas limit to 3M gas when calling the getPairPrice function. So I don't see why it is running out of gas to run that function. To confirm that I am understanding this correctly: that gas that is used to pay for the oraclizer comes from the contract, correct? However the contract had a 2 ether balance, so why doesn't it pay for the gas? Do I have to do something for it to send the gas?
    – Pabi
    Commented Dec 20, 2016 at 12:40
  • It does say here that the contract sent an internal transaction worth 0.04 ether, which I am assuming is to orcalize : testnet.etherscan.io/address/…
    – Pabi
    Commented Dec 20, 2016 at 12:55
  • As it turns out there is isn't any problem when I run the getPairPrice function using web3.js. It seems to be a problem with the solidity browser compiler. Successful transaction: testnet.etherscan.io/tx/…
    – Pabi
    Commented Dec 20, 2016 at 13:19

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.