This is the contract code.I have downloaded the 'Oraclize API' (oraclizeAPI_0.4.sol)from the Oraclize github repo.I have added this file to the truffle contracts folder, and rename the file to usingOraclize.sol.And it is imported in the given contract.

 pragma solidity ^0.4.0;

 import "./usingOraclize.sol";

 contract ApiCall is usingOraclize {

       uint public DieselPriceUSD;

       function DieselPrice() {

                OAR = OraclizeAddrResolverI(0x920cd3f7ed02c5d61e2556308d53a4d9d1e58bf2); 
       }

       function __callback(bytes32 myid, string result) {
                if (msg.sender != oraclize_cbAddress()) throw;
                       DieselPriceUSD = parseInt(result, 2); 
       }

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

}

I have compiled and deployed this contract succesfully. Then tried to call the methods available using the following.

  contract.getCall().then(console.log);

But it returns the following error.

Error: VM Exception while processing transaction: invalid JUMP at 7ed62a9ee27ba25842c0facef792865de53617fe32c09b7eb974a8bca5dd54c0/b8cd3e9aaf13b8823aa83f0f47f235943dac31c6:692

How to call _callback function in this contract with the parameters?What these parameters in this _callback means?

How to use this _callback in index.js in truffle?

  • Which network did you deploy to? – Xavier Leprêtre B9lab Jan 25 '17 at 12:47
  • @Xavier Lepretre B9lab I have used testrpc and truffle for this. – Crissi Mariam Robert Jan 27 '17 at 3:26
  • @Xavier Leprêtre B9lab How to run _callback function using truffle?I didn't have any idea regarding the parameters passed in this _callback function? – Crissi Mariam Robert Jan 27 '17 at 9:24
up vote 1 down vote accepted

I think you have a problem here. You believe that your constructor is function DieselPrice(), while in fact it is not your constructor because your contract is called contract ApiCall.

So your OAR is always null.

Plus, Oraclize's Ethereum networks are only for test net and main net. Not TestRPC of course.

  • I have corrected the constructor.I have to use _callback function in my javascript file.So i have to pass the parameters to the _callback function.what are the parameters in _callback function? – Crissi Mariam Robert Jan 30 '17 at 3:59
  • 1
    Normally, Oraclize call you back on __callback, that's what they do and what you pay them for. Why are you calling __callback? Is it because you are doing tests? – Xavier Leprêtre B9lab Jan 30 '17 at 11:18
  • I have no enough idea regarding it.Now i got the use of _callback function.It worked successfully using truffle and ethereum-bridge. – Crissi Mariam Robert Jan 31 '17 at 3:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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