This question already has an answer here:

Is it possible for an ethereum smart contract to call an external API which then returns a list of value?

Nathan Aw

marked as duplicate by Lauri Peltonen, Richard Horrocks, Ismael, mirg, ivicaa Apr 3 '18 at 8:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Inorder to call external APIs in contract, you have to use oraclize service.

Sample code for your reference....

pragma solidity ^0.4.16;
import "./usingOraclize.sol";  //Importing Oraclize
contract TestOraclizeCall is usingOraclize {
        uint public price;
       event Log(string text);
       function TestOraclizeCall() {
             OAR = OraclizeAddrResolverI(0x5049063e4a7704ac155e4f1f42a4954bbef5bbde);
  function __callback(bytes32 _myid, string _result) {
             require (msg.sender == oraclize_cbAddress());
              price = parseInt(_result, 2);
    function update() payable {


  • just what I needed! many thanks! only REST API JSON supported? – Nathan Aw Apr 2 '18 at 15:38
  • also, is this an async or sync call? – Nathan Aw Apr 2 '18 at 15:39
  • Since in-chain state has to be deterministic and verifiable by all nodes, now and in the future, "Oracles" write something unambiguous to the chain. That way, the nodes that might not be able to agree on what the API says/said, can certainly agree on what the Oracle said. ethereum.stackexchange.com/questions/11589/… – Rob Hitchens - B9lab Apr 2 '18 at 16:54

Sure, read about this service - Oraclize

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