6

I use Geth 1.3.6 and a Morden testnet. I am trying to test the Oraclize API for my Ethereum smart contracts.

First, I have compiled and deployed the simple smart contracts as DieselPricePeg.sol and PriceTicker.sol, also using dev.oraclize.it/. I have not any correct output by query, even I don't get id by oraclize_query.

One of the two smart contract is visible at the following link: https://github.com/oraclize/ethereum-examples/blob/master/solidity/DieselPricePeg.sol

(I think that the problem is not in the code of smart Contract.)

Any suggestions?

  • Without seeing your contract, and without more detail on what's going wrong (link to transaction IDs, if you can), there's no way anyone's going to have enough information to answer. – Nick Johnson Apr 14 '16 at 12:27
  • I edited my question. – Fabiola Apr 14 '16 at 12:39
  • You still need to give us a more detailed description of what you're doing, what happens, what you expected to happen, what error messages you get (if any), and so forth. This may be helpful: stackoverflow.com/help/how-to-ask – Nick Johnson Apr 14 '16 at 12:42
  • 1
    Hi Thomas. In "our gitter channel", I found my answer. Thank you. (My solution was to comment the line update(60*10)) – Fabiola Apr 14 '16 at 15:37
  • 1
    If you found the answer, could you post an answer with a summary of what was wrong and how you fixed it, for future askers? – Tjaden Hess Apr 15 '16 at 13:40
2

TL;DR: The contract didn't have enough balance to pay the Oraclize fee required after the first call to Oraclize.

Going to explain this answer since it was never explained:

OP was attempting to use the following Oraclize demo contract:

import "dev.oraclize.it/api.sol";

contract DieselPricePeg is usingOraclize {

    uint public DieselPriceUSD;


    function DieselPricePeg() {
        oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
        update(0); // first check at contract creation
    }

    function __callback(bytes32 myid, string result, bytes proof) {
        if (msg.sender != oraclize_cbAddress()) throw;
        DieselPriceUSD = parseInt(result, 2); // let's save it as $ cents
        // do something with the USD Diesel price
        update(60*10); // schedule another check in 10 minutes
    }

    function update(uint delay) {
        oraclize_query(delay, "URL", "xml(https://www.fueleconomy.gov/ws/rest/fuelprices).fuelPrices.diesel");
    }

}

The constructor calls update(0), which tells oraclize_query to return the value as quickly as possible (just initializing it). When oraclize_query calls __callback, the data is parsed and __callback calls update(60*10). The first call made to Oraclize from any contract (in the constructor or not) is free. Any further calls come at a cost and require the contract (or account) to carry a balance. __callback is calling update(60*10), which will not return a value if the contract is not carrying any balance.

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.