4

When i am going to deploy this code its give error:The contract code couldn't be stored, please check your gas amount.

Solidity CODE:

pragma solidity ^0.4.0;

import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";

contract OraclizeFetch is usingOraclize{

string public ETHXBT;

event newOraclizeQuery(string description);
event price(string price);


function OraclizeFetch() payable{
    oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
    update();
}

function __callback(bytes32 myid, string result, bytes proof) {
    if (msg.sender != oraclize_cbAddress()) throw;
    ETHXBT = result;
    price(ETHXBT);
    update();
}

function update() payable {
    if (oraclize.getPrice("URL") > this.balance) {
        newOraclizeQuery("Oraclize query was NOT sent, please add some ETH to cover for the query fee");
    } else {
        newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
        oraclize_query(60, "URL", "json(https://api.kraken.com/0/public/Ticker?pair=ETHXBT).result.XETHXXBT.c.0");
    }
}

}

My genesis.json file:

{ "nonce": "0xdeadbeefdeadbeef", "timestamp": "0x0", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x0", "gasLimit": "0x8000000", "difficulty": "0x400", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x3333333333333333333333333333333333333333", "alloc": {

}

}

3
  • Hi, Thomas from Oraclize here, on what network are you trying to run this on? Is it a private testnet or what else? Feb 20, 2017 at 17:29
  • Hi Thomas,We are using private network.
    – Anurag
    Feb 21, 2017 at 4:54
  • if you want to use Oraclize within a private chain context, you need to set up and execute the Oraclize ethereum-bridge there. You will find instructions in that repository. If you need any further assistance, feel free to come to our dedicated gitter support channel. Feb 21, 2017 at 11:23

1 Answer 1

2

Here's a working example of your code, testable with Oraclize in a browser:

http://dapps.oraclize.it/browser-solidity/#version=soljson-v0.4.9+commit.364da425.js&optimize=undefined&gist=a5e9d93dbd1fd5beb9fe1d7012834eba

Some issues were that you were trying to call oraclize through oraclize.getPrice before that variable was even initialized and set. To do this you need to either pre-initialize it somehow, one way to pre-initialize is calling oraclize_setProof(proofType_NONE) to get results without proofs, or use the internal getPrice function provided by Oraclize in the API which is oraclize_getPrice.

Secondly, in another iteration of the contract you asked us about, you were setting the gas to include to 50M, yet you weren't doing a price check of that allotted gas amount, and it's a very high and unrealistic gas cost amount especially for this query, which will cost several ether with such a high gas amount.

This contract should work fine on your privatenet, just ensure the OAR is set correctly for it.

1
  • Hi, I have the same problem, but the contract is a bit more complicated. The thing is that everything works, and Truffle migrates successfully when I'm commenting the __callback() function. Do you know anything about that?
    – Ruham
    Oct 24, 2018 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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