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 {
// ********* //
// VARIABLES //
// ********* //
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");
to
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