Fetching data from APIs using solidity
Ethereum virtual machine (EVM), by design, cannot read data from the outside world. This restricts achieving certain functionalities in Ethereum blockchain. Since every node runs every calculation, it’s not efficient to make arbitrary network requests from an Ethereum contract.
We can overcome this limitation with the help of oracles. These allow a smart contract to read data from an external source in an intelligent way. In this recipe, you will learn to create an Oracle service and read data from an external API.
Getting ready
You need to have a working Ethereum installation for deploying and testing the smart contract. You can also use the Remix IDE to write and test the solidity code.
It is required to have good knowledge of solidity before stepping through this recipe. Go through Chapter 2, Smart Contract Development, for more information.
How to do it...
- Solidity does not allowyouto pull data from an external API source. Use an Oracle service to achieve...