0
pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";

    contract DieselPrice is usingOraclize {
        event one(string description);
        event newDieselPrice(string price);


        function DieselPrice() {
            update(); // first check at contract creation
        }

        function __callback(bytes32 myid, string result) {
            require(msg.sender != oraclize_cbAddress()); // Note: better approach 
            newDieselPrice(result);
            //DieselPriceUSD = parseInt(result, 2); // let's save it as $ cents
            // do something with the USD Diesel price
        }

        function update() payable {
            one("Oraclize query was sent, standing by for the answer..");
            oraclize_query("URL", "xml(https://www.fueleconomy.gov/ws/rest/fuelprices).fuelPrices.diesel");
        }

    }
1
  • Is there a certain function that throws this error?
    – Malone
    Nov 11, 2017 at 11:30

1 Answer 1

1

The probable cause for the error is that you modified the original code in the wrong way.

Originally, it says:

if (msg.sender != oraclize_cbAddress()) throw;

So, if msg.sender is different than oraclize_cbAddress() the execution will fail.

You changed it to

require(msg.sender != oraclize_cbAddress()); // Note: better approach 

Now you are dictating that msg.sender be different that oraclize_cbAddress()

You should change it to

require(msg.sender == oraclize_cbAddress());

Also, have in mind that Oraclize will give you the first execution of each contract for free, but then it charges you, so if you try this a second time, you should make sure the contract has balance to pay for the service.

0

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.