Foundry Starter Kit

September 22, 2026 · View on GitHub

Important

This repository has recently been updated for use with Chainlink contracts v1.5.0. See the dependency installation section for instructions on how to set up v1.5.0 within your own project using forge install.

Foundry Starter Kit


Chainlink Foundry logo


Open in Gitpod

Foundry Starter Kit is a repo that shows developers how to quickly build, test, and deploy smart contracts with one of the fastest frameworks out there, foundry!

Getting Started

Requirements

Please install the following:

  • Git
    • You'll know you've done it right if you can run git --version
  • Foundry / Foundryup
    • This will install forge, cast, and anvil
    • You can test you've installed them right by running forge --version and get an output like: forge 0.2.0 (f016135 2022-07-04T00:15:02.930499Z)
    • To get the latest of each, just run foundryup

Quickstart

git clone https://github.com/smartcontractkit/foundry-starter-kit
cd foundry-starter-kit

Install dependencies as follows:

Run forge install to install dependencies. Foundry uses git submodules as its dependency management system.

⚠️ when running forge install, you may see an error message if you have uncommitted changes in your repo. Read the message carefully - it may inform you that you can add the --no-commit flag to each of these install commands if your workspace has uncommitted changes.

You can update dependencies by running forge update

forge install

Important

For this starter kit, the packages have already been included and can be installed using the above forge install command. This package includes Chainlink contracts v1.5.0.

To add Chainlink contracts to an existing project:

v1.5.0 and above

Step 1: Install >= v1.5.0 and required dependencies

forge install \
  smartcontractkit/chainlink-evm@contracts-v<version> \
  openzeppelin-contracts-4.7.3=openzeppelin/openzeppelin-contracts@v4.7.3 \
  openzeppelin-contracts-4.8.3=openzeppelin/openzeppelin-contracts@v4.8.3 \
  openzeppelin-contracts-4.9.6=openzeppelin/openzeppelin-contracts@v4.9.6 \
  openzeppelin-contracts-5.0.2=openzeppelin/openzeppelin-contracts@v5.0.2 \
  openzeppelin-contracts-5.1.0=openzeppelin/openzeppelin-contracts@v5.1.0

Step 2: Set remappings

Include the following remappings within your project's remappings.txt or foundry.toml.

@chainlink/=lib/chainlink-evm/
@openzeppelin/contracts@4.7.3/=lib/openzeppelin-contracts-4.7.3/contracts/
@openzeppelin/contracts@4.8.3/=lib/openzeppelin-contracts-4.8.3/contracts/
@openzeppelin/contracts@4.9.6/=lib/openzeppelin-contracts-4.9.6/contracts/
@openzeppelin/contracts@5.0.2/=lib/openzeppelin-contracts-5.0.2/contracts/
@openzeppelin/contracts@5.1.0/=lib/openzeppelin-contracts-5.1.0/contracts/
v1.4.0 and below

Step 1: Install <= v1.4.0

forge install smartcontractkit/chainlink-evm@contracts-v<version>

Step 2: Set remappings

Include the following remappings within your project's remappings.txt or foundry.toml.

@chainlink/contracts/=lib/chainlink-evm/contracts/

Testing

To check that everything is compiling and working as intended after cloning and installing dependencies, run

forge test

All tests should pass.

Chainlink Foundry Starter Kit

Implementation of the following 4 Chainlink services using the [Foundry] (https://book.getfoundry.sh/) smart contract development tooling:

For Chainlink Functions please go to these starter kits: Hardhat | Foundry (coming soon)

For Chainlink CCIP (Cross Chain Interoperability Protocol) please go to these starter kits: Hardhat | Foundry

Deploying to a network

Deploying to a network uses the foundry scripting system, where you write your deploy scripts in solidity!

Setup

We'll demo using the Sepolia testnet. (Go here for testnet sepolia ETH.)

You'll need to add the following variables to a .env file:

  • SEPOLIA_RPC_URL: A URL to connect to the blockchain. You can get one for free from Infura account
  • PRIVATE_KEY: A private key from your wallet. You can get a private key from a new MetaMask account
    • Additionally, if you want to deploy to a testnet, you'll need test ETH and/or LINK. You can get them from faucets.chain.link.
  • Optional ETHERSCAN_API_KEY: If you want to verify on etherscan

When you've added your environment variables to the .env file, run source .env in your terminal (and for each new terminal session) to load the environment variables into your terminal.

Deploying

Deploy scripts are in ./script. The relevant Chainlink Service can be determined from the name of the Contract script. HelperConfig is not meant to be deployed.

To deploy one of the Chainlink Service consumer contracts run the script as follows:

forge script script/${CONTRACT_NAME}.s.sol:Deploy${CONTRACT_NAME} --rpc-url $SEPOLIA_RPC_URL  --private-key PRIVATE_KEY --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY  -vvvv
make deploy-sepolia contract=<CONTRACT_NAME>

For example, to deploy the PriceFeedConsumer contract:

forge script script/PriceFeedConsumer.s.sol:DeployPriceFeedConsumer  --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY -vvvv

If you don't have an ETHERSCAN_API_KEY, you can omit --verify --etherscan-api-key $ETHERSCAN_API_KEY

Working with Anvil local development network

Foundry comes with local network anvil baked in, and allows us to deploy to our local network for quick testing locally.

To start a local network run the following in a new terminal window or tab:

anvil

This will spin up a local blockchain on http://localhost:8545 : (see console output for the mnemonic used, and 10 private keys and their associated wallet address), so you can use the same private key each time.

Then, you can deploy to it with one of those private keys; in this example we use the first one:

forge script script/${contract}.s.sol:Deploy${contract} --rpc-url http://localhost:8545  --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --broadcast 

Working with other chains

To add a chain, you'd just need to pass in the RPC URL for the relevant chain to the --rpc-url flag.

forge script script/${contract}.s.sol:Deploy${contract} --rpc-url ${<OTHER_CHAIN>_RPC_URL}  --private-key ${PRIVATE_KEY} --broadcast -vvvv

Security

This framework comes with slither parameters, a popular security framework from Trail of Bits. To use slither, you'll first need to install python and install slither.

Then, you can run:

make slither

And get your slither output.

Contributing

Contributions are always welcome! Open a PR or an issue! If you do contribute please add solidity.formatter": "forge to your VSCode Settings, or run forge fmt before you commit and push.

Thank You!

Resources

TODO

[ ] Add bash scripts to interact with contracts using cast

[ ] Make deploying contracts to anvil simpler

Disclaimer: Please note, this repo contains community examples only — these are not Chainlink products or services and are not supported or maintained by Chainlink. This code represents an example of using a Chainlink product or service, and is intended for demonstration and educational purposes only. It is provided “AS IS” and “AS AVAILABLE” without warranties of any kind, may not have been audited, and may omit checks or error handling. Each party intending to use this example code does so entirely at their own risk and must perform its own audits, security and code review, key management, and testing before any production deployment and ensure the operation and performance of such code matches expectations. Neither Chainlink Labs nor the Chainlink Foundation deploys, operates, monitors, maintains or endorses any deployment of this code. Note that this is not a Chainlink product, feature or service, and there are no commitments made with respect to the code, including compatibility with future Chainlink releases. You should not rely on this code without first conducting your own technical, engineering, and security review. This code is also outside the scope of any Chainlink bug bounty programs. Neither Chainlink Labs, the Chainlink Foundation, nor Chainlink node operators are responsible for outcomes due to errors in this example or how it is deployed or operated, or liable for any resulting claims or damages. Use of the Chainlink Network is subject to the Chainlink Foundation Terms of Service, which provides important information and disclosures. By using this code, you acknowledge and agree to these terms.