Make a GET Request
This series of guides explains how to make HTTP GET requests to external APIs from smart contracts, using Chainlink's Request & Receive Data cycle.
Make sure to choose an oracle job that supports the data type that your contract needs to consume. Multiple data types are available such as:
uint256- Unsigned integers
int256- Signed integers
bool- True or False values
bytes32- Strings and byte values. If you need to return a string, use
bytes32. Here's one method of converting
string. Currently, any return value must fit within 32 bytes. If the value is bigger than that, make multiple requests.
bytes- Arbitrary-length raw byte data
Setting the LINK token address, Oracle, and JobId
setChainlinkToken function sets the LINK token address for the network you are deploying to. The
setChainlinkOracle function sets a specific Chainlink oracle that a contract makes an API call from. The
jobId refers to a specific job for that node to run.
Each job is unique and returns different types of data. For example, a job that returns a
bytes32 variable from an API would have a different
jobId than a job that retrieved the same data, but in the form of a
Check the Find Existing Jobs page to learn how to find a job suitable to your use case.
Single Word Response
This guide explains how to make an HTTP GET request and parse the json response to retrieve the value of one single attribute.
This guide explains how to make an HTTP GET request and parse the json response to retrieve the values of multiple attributes.
Fetch data from an Array
This guide explains how to make an HTTP GET request that returns a json array and parse it to retrieve the target element's value.
This guide explains how to make an HTTP Get request that returns a json containing an arbitrary-length raw byte data and parse it to return the data as bytes data type.
Make an Existing Job Request
This guide explains how to call a job that leverages External adapters and returns the relevant data to the smart contract. This allows building succinct smart contracts that do not need to comprehend the URL or the response format of the target API.