Skip to content

Deployment Guide

Prerequisites

  • Foundry installed
  • A funded deployer wallet
  • An RPC endpoint for your target network
  • An Etherscan API key for contract verification

Setup

Terminal window
git clone https://github.com/rxbryan/chainlink-price-feed-consumer
cd chainlink-price-feed-consumer
forge install

forge install reads foundry.toml and installs all library dependencies declared in [dependencies]. No separate npm install required.

Foundry configuration

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
test = "test"
script = "script"
solc_version = "0.8.19"
optimizer = true
optimizer_runs = 200
remappings = [
"@chainlink/contracts/=lib/chainlink/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
]

optimizer_runs = 200 is the standard setting for contracts that will be called frequently. Increase it if your consuming contract calls getPrice in a tight loop; decrease it if deployment cost is the primary concern.

Environment variables

VariableRequiredDefaultDescription
RPC_URLYesn/aRPC endpoint for target network
PRIVATE_KEYYesn/aDeployer private key
ETHERSCAN_API_KEYYes (for verification)n/aBlock explorer API key
FEED_ADDRESSNoSepolia ETH/USDChainlink aggregator address
STALENESS_SECONDSNo3600Max acceptable round age
MAX_DEVIATION_BPSNo500Max deviation in basis points
UPTIME_FEEDL2 onlyaddress(0)Sequencer uptime feed address

L1 deployment (Sepolia)

  1. Set environment variables:

    Terminal window
    export RPC_URL=https://eth-sepolia.g.alchemy.com/v2/<your-key>
    export PRIVATE_KEY=<your-private-key>
    export ETHERSCAN_API_KEY=<your-api-key>
  2. Optionally override feed parameters:

    Terminal window
    export FEED_ADDRESS=0x694AA1769357215DE4FAC081bf1f309aDC325306 # Sepolia ETH/USD
    export STALENESS_SECONDS=3600
    export MAX_DEVIATION_BPS=500
  3. Deploy and verify:

    Terminal window
    forge script script/Deploy.s.sol \
    --rpc-url $RPC_URL \
    --private-key $PRIVATE_KEY \
    --broadcast \
    --verify \
    --etherscan-api-key $ETHERSCAN_API_KEY

L2 deployment (Arbitrum, Optimism, Base)

L2 deployments require the UPTIME_FEED variable. The deploy script sets the sequencer uptime feed address on the deployed contract automatically if this variable is present.

  1. Set environment variables including the uptime feed:

    Terminal window
    export RPC_URL=https://arb-mainnet.g.alchemy.com/v2/<your-key>
    export PRIVATE_KEY=<your-private-key>
    export ETHERSCAN_API_KEY=<your-api-key>
    export FEED_ADDRESS=0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612 # Arbitrum ETH/USD
    export UPTIME_FEED=0xFdB631F5EE196F0ed6FAa767959853A9F217697D # Arbitrum sequencer
  2. Deploy:

    Terminal window
    forge script script/Deploy.s.sol \
    --rpc-url $RPC_URL \
    --private-key $PRIVATE_KEY \
    --broadcast \
    --verify \
    --etherscan-api-key $ETHERSCAN_API_KEY

Post-deployment

After deployment, call updateBaseline() if the constructor price is significantly different from the current market price. This is unlikely but can occur if the feed was stale at deployment time.

If using the deviation guard, establish a process for calling updateBaseline() when the asset price has moved legitimately and the contract needs to accept prices in the new range.

Feed addresses