← Protocols
Chainlink
Oracle·EVM · Solana · Multi-chain

Chainlink

01Description

Oracle network providing Data Feeds (price oracles), CCIP (cross-chain messaging + token transfers), VRF (verifiable randomness), Automation (keepers), and Functions.

02Best for
  • 01on-chain price feeds
  • 02verifiable randomness (NFT mints, games)
  • 03scheduled / conditional execution (Automation)
  • 04cross-chain token + message transfers (CCIP)
  • 05off-chain compute (Functions)
03Install
  • pnpm add @chainlink/contracts @chainlink/contracts-ccip
  • pnpm add -D @chainlink/ccip-js
04Environment variables
VariableScopeDescription
CHAINLINK_VRF_SUBSCRIPTION_IDServerVRF v2.5 subscription ID (uint256). Fund it with LINK at vrf.chain.link.
CHAINLINK_VRF_KEY_HASHServerGas-lane key hash for your target chain (per docs.chain.link/vrf/v2-5/supported-networks).
CHAINLINK_AUTOMATION_REGISTRYServerAutomation Registry address for the target chain when using `AutomationCompatibleInterface`.
05Prompt snippet
For price feeds, import `AggregatorV3Interface` from `@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol` and call `latestRoundData()` — always validate `updatedAt` is fresh and `answer > 0`. For VRF v2.5 inherit `VRFConsumerBaseV2Plus`, call `s_vrfCoordinator.requestRandomWords(VRFV2PlusClient.RandomWordsRequest{...})` from a funded subscription, and consume in `fulfillRandomWords`. For CCIP import `IRouterClient` and `Client` from `@chainlink/contracts-ccip`, build `Client.EVM2AnyMessage`, fee-quote via `getFee`, then `ccipSend{value: fee}(destChainSelector, message)` — track via CCIP Explorer. For Automation implement `checkUpkeep`/`performUpkeep` and register at automation.chain.link.
06Gotchas
  • Always staleness-check Data Feeds: revert if `block.timestamp - updatedAt > heartbeat` and if `answer <= 0` — feeds can pause during incidents.
  • Feed decimals are NOT 18 (typically 8 for USD pairs) — read `decimals()` and scale; mixing this up is a top exploit vector.
  • VRF v2.5 uses chain-specific key hashes and chain selectors; copy exact values from the supported-networks page or fulfilment will fail silently.
  • CCIP destination is a `chainSelector`, not a chain ID — and rate limits / lane-specific token caps apply per-token-per-lane.
  • Automation upkeeps run out of LINK and silently stop — wire alerting on `LinkBalance` and add a top-up routine.
  • Sequencer-uptime feeds are mandatory on L2s (Arbitrum, Optimism, Base) — read prices ONLY when the L1 sequencer reports up, otherwise stale prices can be exploited.
07Alternatives