Deployment Guide
Prerequisites
- Foundry installed
- A funded deployer wallet
- An RPC endpoint for your target network
- An Etherscan API key for contract verification
Setup
git clone https://github.com/rxbryan/chainlink-price-feed-consumercd chainlink-price-feed-consumerforge installforge 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 = trueoptimizer_runs = 200remappings = [ "@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
| Variable | Required | Default | Description |
|---|---|---|---|
RPC_URL | Yes | n/a | RPC endpoint for target network |
PRIVATE_KEY | Yes | n/a | Deployer private key |
ETHERSCAN_API_KEY | Yes (for verification) | n/a | Block explorer API key |
FEED_ADDRESS | No | Sepolia ETH/USD | Chainlink aggregator address |
STALENESS_SECONDS | No | 3600 | Max acceptable round age |
MAX_DEVIATION_BPS | No | 500 | Max deviation in basis points |
UPTIME_FEED | L2 only | address(0) | Sequencer uptime feed address |
L1 deployment (Sepolia)
-
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> -
Optionally override feed parameters:
Terminal window export FEED_ADDRESS=0x694AA1769357215DE4FAC081bf1f309aDC325306 # Sepolia ETH/USDexport STALENESS_SECONDS=3600export MAX_DEVIATION_BPS=500 -
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.
-
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/USDexport UPTIME_FEED=0xFdB631F5EE196F0ed6FAa767959853A9F217697D # Arbitrum sequencer -
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
- All networks: docs.chain.link/data-feeds/price-feeds/addresses
- Sequencer uptime feeds: docs.chain.link/data-feeds/l2-sequencer-feeds