NEW

Join us at SmartCon 2023—where Web3 gets real. Get your ticket.

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.

Response Types

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
  • string - String
  • bytes32 - Strings and byte values. If you need to return a string, use bytes32. Here's one method of converting bytes32 to 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

The 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 uint256 variable.

Check the Find Existing Jobs page to learn how to find a job suitable to your use case.

Examples

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.

Multi-Variable Responses

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.

Large Responses

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.

What's next

Stay updated on the latest Chainlink news