SDKs overview
Chainlink provides a suite of software development kits (SDKs) and libraries designed to facilitate the integration of its decentralized oracle services into smart contracts and decentralized applications (dApps). These tools abstract the complexities of direct smart contract interaction, enabling developers to access real-world data, off-chain computation, and secure cross-chain communication. The primary focus of Chainlink's SDKs is to simplify the consumption of its core products, including Data Feeds, Verifiable Random Function (VRF), Chainlink Keepers, Chainlink Functions, and the Cross-Chain Interoperability Protocol (CCIP) (Chainlink API reference).
The developer experience with Chainlink is characterized by extensive documentation and a large ecosystem of integrations across various blockchain platforms. Developers primarily interact with smart contracts on supported blockchains to consume oracle services. Chainlink supports multiple Ethereum Virtual Machine (EVM) compatible chains, such as Ethereum, Polygon, Avalanche, Arbitrum, Optimism, and BNB Chain, as well as non-EVM chains like Solana and Starknet (Chainlink supported chains). This broad compatibility allows developers to build dApps that require external data and computation across a diverse blockchain landscape.
Official SDKs by language
Chainlink's official SDKs and related tools primarily focus on smart contract development and front-end interaction with these contracts. While there isn't a single monolithic SDK for all languages, the ecosystem provides specific libraries and interfaces tailored to different development needs.
Solidity (Smart Contract Development)
For smart contract development, Chainlink provides a set of Solidity interfaces and libraries. These are crucial for integrating Chainlink services directly into smart contracts. Developers typically import these contracts to interact with Chainlink Data Feeds, VRF coordinators, Keepers registries, and CCIP routers.
@chainlink/contracts: This npm package contains the core Solidity contracts and interfaces for integrating Chainlink services. It includes interfaces for Data Feeds (e.g.,AggregatorV3Interface), VRF (e.g.,VRFConsumerBaseV2), Keepers (e.g.,KeeperCompatibleInterface), and CCIP (e.g.,CCIPReceiver).
JavaScript/TypeScript (Front-end & Off-chain Interaction)
For interacting with Chainlink-enabled smart contracts from off-chain applications, front-ends, or backend services, standard web3 libraries are used in conjunction with Chainlink's contract addresses and ABI definitions.
ethers.jsorweb3.js: These are not Chainlink-specific but are essential for any JavaScript/TypeScript application interacting with EVM blockchains. Developers use these libraries to connect to blockchain nodes, sign transactions, and call functions on deployed Chainlink-enabled smart contracts. Chainlink's documentation often provides examples usingethers.jsfor contract interaction (Chainlink Data Feeds setup guide).@chainlink/functions-toolkit: A JavaScript/TypeScript library specifically designed to simplify interactions with Chainlink Functions. It helps in preparing requests, handling responses, and managing subscriptions for off-chain computation tasks.
Python (Off-chain Interaction & Scripting)
Python is commonly used for scripting, data analysis, and backend services that interact with blockchains. Similar to JavaScript, standard web3 libraries are used.
web3.py: The Python equivalent ofweb3.js, used for interacting with EVM blockchains. Developers can useweb3.pyto read data from Chainlink Data Feeds, request verifiable randomness, or trigger Keeper-compatible smart contracts from Python applications (Chainlink Data Feeds environment setup).
Official SDKs and Libraries Table
| Language | Package/Tool | Description | Typical Installation | Maturity |
|---|---|---|---|---|
| Solidity | @chainlink/contracts |
Solidity interfaces and libraries for integrating Chainlink services directly into smart contracts. | npm install @chainlink/contracts |
Stable |
| JavaScript/TypeScript | @chainlink/functions-toolkit |
Toolkit for interacting with Chainlink Functions from off-chain environments. | npm install @chainlink/functions-toolkit |
Stable |
| JavaScript/TypeScript | ethers.js / web3.js |
General-purpose libraries for EVM blockchain interaction (not Chainlink-specific but essential). | npm install ethers / npm install web3 |
Stable |
| Python | web3.py |
General-purpose library for EVM blockchain interaction (not Chainlink-specific but essential). | pip install web3 |
Stable |
Installation
Installation procedures vary depending on the specific library and development environment. The following outlines common installation steps for the primary Chainlink-related development tools.
Solidity Contracts
To use Chainlink's Solidity contracts in your smart contract project, typically managed with tools like Hardhat or Foundry:
npm install @chainlink/contracts
# or with yarn
yarn add @chainlink/contracts
After installation, you can import the necessary contracts in your Solidity files:
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
JavaScript/TypeScript Libraries
For front-end or backend JavaScript/TypeScript applications, install the relevant packages using npm or yarn:
# For ethers.js
npm install ethers
# For @chainlink/functions-toolkit
npm install @chainlink/functions-toolkit
Python Libraries
For Python applications, use pip to install web3.py:
pip install web3
Quickstart example
This quickstart demonstrates how to read data from a Chainlink Data Feed using Solidity, a common task for dApps requiring external price information. This example uses the AggregatorV3Interface from @chainlink/contracts to get the latest price of ETH/USD on the Sepolia testnet.
Prerequisites
- Node.js and npm installed.
- Hardhat or Foundry project initialized. This example assumes Hardhat.
- Basic understanding of Solidity.
Step 1: Install Hardhat and Chainlink Contracts
If you haven't already, set up a Hardhat project and install the Chainlink contracts:
mkdir chainlink-data-feed-example
cd chainlink-data-feed-example
npx hardhat init
npm install @chainlink/contracts
Step 2: Create a Solidity Contract (PriceConsumerV3.sol)
Create a new file contracts/PriceConsumerV3.sol and add the following code. This contract will fetch the latest price from a Chainlink Data Feed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Network: Sepolia
* Aggregator: ETH/USD
* Address: 0x694AA1769357215Ee4f0fFfEdfB8Pfbc6e510fDo
*/
constructor() {
priceFeed = AggregatorV3Interface(
0x694AA1769357215Ee4f0fFfEdfB8Pfbc6e510fDo // Sepolia ETH/USD Data Feed address
);
}
/**
* Returns the latest price
*/
function getLatestPrice() public view returns (int256) {
(,
int256 price,
,
,
) = priceFeed.latestRoundData();
return price;
}
}
Note: The address 0x694AA1769357215Ee4f0fFfEdfB8Pfbc6e510fDo is a specific Chainlink Data Feed for ETH/USD on the Sepolia testnet. Always verify the correct address for your chosen network and asset from the Chainlink Price Feed addresses documentation.
Step 3: Compile and Deploy the Contract (using Hardhat)
You'll need a Hardhat configuration to compile and deploy. Ensure your hardhat.config.js is set up for Sepolia with an RPC URL and a private key (for deployment).
// hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL || "https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY";
const PRIVATE_KEY = process.env.PRIVATE_KEY || "0x...";
module.exports = {
solidity: "0.8.19",
networks: {
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 11155111,
},
},
};
Create a deployment script (e.g., scripts/deploy.js):
// scripts/deploy.js
const { ethers } = require("hardhat");
async function main() {
const PriceConsumerV3 = await ethers.getContractFactory("PriceConsumerV3");
console.log("Deploying PriceConsumerV3...");
const priceConsumer = await PriceConsumerV3.deploy();
await priceConsumer.waitForDeployment();
console.log(`PriceConsumerV3 deployed to: ${priceConsumer.target}`);
// Interact with the deployed contract
const latestPrice = await priceConsumer.getLatestPrice();
console.log(`Latest ETH/USD price (raw): ${latestPrice.toString()}`);
console.log(`Latest ETH/USD price (formatted): ${ethers.formatUnits(latestPrice, 8)}`); // Price feeds typically use 8 decimals
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Run the deployment script:
npx hardhat run scripts/deploy.js --network sepolia
This will deploy the contract to Sepolia and then call getLatestPrice() to fetch and log the current ETH/USD price. The output will show the raw price and a formatted version (dividing by 108, as Chainlink Price Feeds typically use 8 decimal places (Chainlink Price Feed decimals)).
Community libraries
Beyond the official contracts and toolkits, the Chainlink ecosystem benefits from a variety of community-contributed libraries and tools. These often extend functionality, provide language bindings for less common environments, or offer specialized integrations.
- Brownie Mixes: For Python developers using the Brownie framework for smart contract development, several Chainlink Brownie Mixes are available. These provide pre-configured project templates with Chainlink integrations for various services (e.g., Data Feeds, VRF, Keepers), streamlining the setup process (Brownie Mixes documentation).
- Hardhat Plugins: The Hardhat ecosystem includes various plugins that can enhance Chainlink development, such as those for local fork testing with Chainlink data or for deploying Chainlink nodes.
- Subgraphs for The Graph: While not an SDK in the traditional sense, many Chainlink-enabled protocols deploy subgraphs on The Graph network. Developers can use GraphQL queries to access historical Chainlink oracle data indexed by these subgraphs, providing an alternative way to consume Chainlink data off-chain (The Graph quick start).
- Language-Specific Wrappers: Community members occasionally develop wrappers or client libraries in languages like Go, Rust, or Java to interact with Chainlink smart contracts or Chainlink node APIs, although these are less officially supported compared to Solidity, JavaScript, and Python.
Developers are encouraged to explore the broader Chainlink community forums and GitHub repositories for the latest community-driven tools and integrations (Chainlink community resources).