I am using testrpc as client and truffle as development framework.And also using ethereum-bridge for Oraclize.

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 ApiCall() {

                OAR = OraclizeAddrResolverI(0x9851eb2d10b765d8857e7e1b060bc1eb166e89f2);
        }

        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");
         }

     }

The XML file in the link 'https://www.fueleconomy.gov/ws/rest/fuelprices' is as follows.

     <fuelPrices>
          <cng>2.06</cng>
          <diesel>2.57</diesel>
          <e85>1.93</e85>
          <electric>0.13</electric>
          <lpg>2.68</lpg>
          <midgrade>2.58</midgrade>
          <premium>2.82</premium>
          <regular>2.33</regular>
  </fuelPrices>

I have compiled the contract using 'truffle' enter image description here The Oraclize return the result diesel price as '2.57' using ethereum-bridge.

enter image description here

I want to use the result in index.js file to display it in frontend.How to use the result in dapp frontend?

up vote 2 down vote accepted

When you get the result in your contract, log it as an event. Using web3.js or ethjs, make JavaScript code to listen for that event (see the docs for watch or filter), and display it on your HTML page.

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.