External api call from ethereum smart contract
Posted By : Md Imroz Alam | 12-Dec-2016
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.
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
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.