Setting up Foundry with Base
In this tutorial, you’ll learn how to set up Foundry, a toolchain for smart contract development. You’ll also learn how to configure it to work with Base.Objectives
By the end of this tutorial, you should be able to:- Install Foundry
- Create a Foundry project
- Compile a smart contract using Foundry
- Configure Foundry to work with Base
Overview
Foundry is a smart contract development toolchain that is composed of multiple small command line tools:- forge: Compile, test, and deploy your smart contracts
- cast: Interact with the Blockchain over RPC. You can make smart contract calls, send transactions, or retrieve any type of chain data
- chisel: A Solidity REPL. You can write Solidity code directly
- anvil: A local Blockchain node for testing and development
Installing Foundry
In order to install Foundry, you can useFoundryup, the Foundry’s toolchain installer.
To install Foundryup you have to run in the terminal:
Foundryup is installed, you can install Foundry by running:
My First Foundry Project
To create a foundry project you can simply run:.gitmodules file — this is because Foundry handles dependencies using Git submodules.
By default the Foundry structure stores smart contracts in the src folder. You can change this in the foundry.toml configuration file.
For instance:
Setting up Foundry with Base
In order to work with Base, you need to configure a couple of settings in the configurationfoundry.toml file.
The first thing is the Solidity version.
You need to configure your config file as follows:
forge build to ensure everything works well.
We also recommend setting up JSON RPC endpoints for Base and the API key for Basescan in the configuration file so that your environment is ready to deploy your smart contracts.
Your configuration file should look like the following:
Base and Base Sepolia and similar for the Etherscan section, we included the configuration for Basescan for Sepolia and Mainnet. Both rely on the same API Key, BASESCAN_API_KEY.
Conclusion
In this tutorial, you’ve embarked on the journey of smart contract development with Base and Foundry. You’ve learned the essential steps, from installing Foundry using the convenientFoundryup toolchain installer to creating your first project and configuring Foundry to seamlessly integrate with Base.