...by Daniel Szego
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Wednesday, January 11, 2017

Communicating with external datasource on the Ethereum Blockchain

Calling external API from a Solidity smart contract is basically not possible. However there is an indirect way to communicate with external data sources via internal variables, functions and events. Let we assume that we want to call an external API with three string parameters, parameter_1, parameter_2 and parameter_3 and expecting returning a ReturnValue string.  The only way to do it is to raise an event, implement and event handler on the client side to make the necessary call for the event and write the resulting variable back to the smart contract. 

A simple smart contract for the implementation can be seen int the followings:
 Certainly the template realizes efficiently only one call. If several calls are executed paralleled than further considerations are required.  

Several considerations have to be done however regarding security. One of the main idea behind Solidity is that everything is controlled by a decentralized consensus. If external data is used by a Blockchain application it is something that is not part of the decentralized consensus, implying a way for cheating or hacking the whole application. As a consequence extensive use of external data is surely not proposed for a Blockchain application.