External api call from ethereum smart contract

Posted By : Md Imroz Alam | 12-Dec-2016

Ethereum Smart Contract External API

Step 1.

Demo contract for call api with orcalize
// Save as "orcalize.sol"

pragma solidity ^0.4.0;

import "https://github.com/oraclize/ethereum-api/oraclizeAPI_0.4.sol"; 

contract ApiCall is usingOraclize {

    function DieselPrice() {
      // following code,Ethereum-bridge return value added to constructor 
      OAR = OraclizeAddrResolverI(0x56ad7524c192817b9f78ee117fdac186d5b3c995);
    // this __callback function mandatory to add
    function __callback(bytes32 myid, string result) {
    // user-definde function "update"
    function getCall() payable {
       oraclize_query("URL", "http://domain.com/getData/?data=Testing");

browser-solidity link to test this contract -> http://dapps.oraclize.it/browser-solidity

Step 2. 

Setup Ethereum-bridge for private blockchain ,
    a) First take clone from https://github.com/oraclize/ethereum-bridge
        b) npm install
        c) run this command on terminal, node plugin -H localhost:8000 -a 0 // 0 refer to ethereum blockchain first account(etherbase account)
    d) wait for a some minute, ethereum-bridge will  some following code like , paste that code to constructor of our contract
      OAR = OraclizeAddrResolverI(0x56ad7524c192817b9f78ee117fdac186d5b3c995);

Step 3. 

Create Contract and deploy the Contract on Ethereum blockchain.

and then call getCall method of contract for external api call.
I hope this will helpful.

About Author

Author Image
Md Imroz Alam

Md. Imroz Alam is a bright Web App Developer, he has good knowledge of Java, J2SE, Jsp, Servlet, jdbc. His hobbies are watching movie, playing carom.

Request for Proposal

Name is required

Comment is required

Sending message..