11

I'm trying to write a contract, which first asks input from user, then makes Oraclize query and after receiving answer from Oraclize compares user input to Oraclize answer.

My problem is, that my code doesn't wait for the answer from Oraclize and because of that, I get Oraclize result after comparison is already done.

How can I make program to wait for Oraclize result and continue running only after result has arrived?

11

Thomas from Oraclize here.

When you call Oraclize the query is asynchronous, this means that one transaction is needed to send the query and another transaction to receive the result - this is the "callback transaction", it's sent by Oraclize and usually comes ~1-2 blocks after the first one.

The "callback transaction" is calling the __callback method as described in our documentation. It is by implementing the __callback method that you can use the data Oraclize sends back as result.

In your use case you want to compare a given user input with the Oraclize answer, so the way to do it is:

  • the user calls (via a transaction) a given contract method which does keep a copy in storage of the user input & which calls Oraclize (via oraclize_query)
  • Oraclize will send back the "callback transaction" with the result, your contract implements the __callback function and checks whether the Oraclize result does match with the user input (we stored it before in the contract storage) or not

In our dedicated github respository you can find some Solidity examples which you might find helpful as well!

If this is not clear enough or if you have any other doubt feel free to comment below or to join our official gitter support channel.

0

you can use your logic inside __callback function for example in my case

function __callback(bytes32 myid, string result, bytes proof) {
    if (msg.sender != oraclize_cbAddress()) throw;
    // result-> we can do somethings with results
    deliverable=parseInt(result);
    if(deliverable==1){
        seller.transfer(budget);
        Status('Ether transfer succsessfully.', seller, block.timestamp);
    }
    else{
        selfdestruct(msg.sender);
        Status('refund because deliverable is not set 1', msg.sender, block.timestamp);
    }

}

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.