2

I have an Oraclize query like the following:

function __callback(bytes32 myid, string result) onlyOraclize { 
    // do things
    update();
}

function update() payable onlyOwnerOrOraclize {

    string memory part1 = "[URL] ['json(https://api.random.org/json-rpc/1/invoke).result.random.data.0', '\\n{\"jsonrpc\":\"2.0\",\"method\":\"generateIntegers\",\"params\":{\"apiKey\":${[decrypt] BAKDeam1gVg++DgtVnOA3WuDkzbAaRgY4xOXmdvSQSteMyI94gNWyWcc0uDpVJtikYyzClR6Kvw5xbEswpJryBwNirC7sKsP23rQovooh1xQxBlId6cNgwb5UBzidOB0dVvl7EntjRxRZmSVBihSjpSEa7TRPjU=},\"n\":1,\"min\":0,\"max\":";

    string memory maxRandomNumber = uint2str(3);

    string memory part2 = ",\"replacement\":true,\"base\":10${[identity] \"}\"},\"id\":1${[identity] \"}\"}']";

    string query = strConcat(part1, maxRandomNumber, part2);

    bytes32 rngId = oraclize_query(60, "nested", query);

}

While I have a contract with plenty of Ether in it, the default gas limit for Oraclize calls (200000) isn't enough (unless I comment out update(); in the callback so the query only runs once). Per the docs (https://docs.oraclize.it/#ethereum-quick-start-custom-gas-limit-and-gas-price) setting the gas limit should just be the 4th parameter in the oraclize_query. But if I try the following (to set gas at 500000):

bytes32 rngId = oraclize_query(60, "nested", query, 500000);

The query doesn't get run at all. Why would this be?

As a sidenote, without a nested query with encrypted API key, and just doing it as follows:

oraclize_query(60, "URL", "json(https://api.random.org/json-rpc/1/invoke).result.random.data.0", '\n{"jsonrpc":"2.0","method":"generateIntegers","params":{"apiKey":"my-api-key","n":1,"min":0,"max":3,"replacement":true,"base":10},"id":1}');

200000 gas is enough for it to run as many times as it needs as long as the contract has Ether in it. But with a nested/encrypted query it needs more gas.

2 Answers 2

1

Looking at your last reply, that's the possible answer, if you haven't got any ether on the contract yet, it's not possible to do the query, because __callback will never trigger (as Oracle knows you haven't got enough ether to pay for the query result).

Maybe another point to look at is the fact that if you set a gas prize which is too low for the query, the response and it's corresponding __callback can be delayed a lot looking like the query doesn't work.

Don't know on whitch testnet you are, but if is a PoW testnet.. The delay will be massive.

  • So try to call update() after the constructor finnishes and you have some ether on your contract.
  • Try to set a higher GasPrice in order to recieve the query results a bit earlier if you are on a PoW envoirment. By using: oraclize_setCustomGasPrice(xxxxx);

Hope it helps!

0

I think the issue is I was calling update() in the constructor function and creating the contract without sending Ether (only adding to the contract balance after the contract had deployed). I instead called update() manually after deploying the contract, sending some Ether with it:

contractInstance.update({from: web3.eth.accounts[0], gas:1000000, value: web3.toWei(0.1, "ether")})

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.