Member-only story
How to Call APIs From Ethereum Smart Contracts
Find and use oracles to retrieve off-chain data in your smart contracts

Due to the nature of blockchain ecosystems, accessing off-chain data from on-chain smart contracts is not natively possible. However, Chainlink provides a platform for blockchain oracles, which are nodes on the network that act as a bridge between on-chain and off-chain data. Oracles enable smart contracts to retrieve data from the outside world.
Each oracle node can be configured to perform a wide range of tasks depending on the adapters it supports. Some of these adapters include HTTP GET, HTTP POST, JSON Parse, Multiply, and more.
How to Use Chainlink Oracles
Note: We’re using the Ropsten testnet in this example.
Coingecko API is public and free, but if you choose to upgrade, use the promo code
CGALEXROAN
when signing up to receive $500 off your annual subscription!
Let’s assume that we want to create a smart contract that acts upon the USD price of Ethereum, as reported from the popular price analysis site CoinGecko. We know that there is no native way our smart contract can call an external HTTP API, but an oracle node can.
Using the request-and-response cycle, our smart contract can request data from an oracle node, configured to perform HTTP GET requests, and implement a callback function for the oracle to fulfil with a response.

We can’t use any oracle, because each is configured to perform specific tasks depending on their support. To find a high-quality oracle to suit our needs, we must search for one using a listing service like Chainlink Market.
Chainlink market
Listing services enable us to find oracles that can serve our requests. Popular APIs often have oracle implementations of requests to specific endpoints pre-configured, making our development much more straightforward. We can determine if an oracle already implements our desired CoinGecko endpoint by heading to the Chainlink Market…