What You’ll Achieve
By the end of this quickstart, you’ll be able to:- Set up your development environment to deploy on Base
- Deploy your smart contracts to Base
- Connect your frontend to your smart contracts
Why Base?Base is a fast, low-cost, builder-friendly Ethereum L2 built to bring the next billion users onchain. By following this guide, you’ll join a vibrant ecosystem of developers, creators, and innovators who are building a global onchain economy.
Set Up Your Development Environment
- Create a new project directory
- Install Foundry, a powerful framework for smart contract development
- Initialize a new Solidity project
src
directory, which you can replace with your own contracts. For the purposes of this guide, we’ll use the Counter contract provided in /src/Counter.sol
Foundry provides a suite of tools for Ethereum application development, including Forge (for testing), Cast (for interacting with the chain), and Anvil (for setting up a local node). You can learn more about Foundry here.
Configure Foundry with Base
To deploy your smart contracts to Base, you need two key components:- A node connection to interact with the Base network
- A funded private key to deploy the contract
1. Set up your node connection
- Create a
.env
file in your project’s root directory - Add the Base network RPC URL to your
.env
file
- Load your environment variables
Base Sepolia is the test network for Base, which we will use for the rest of this guide. You can obtain free Base Sepolia ETH from one of the faucets listed here.
2. Secure your private key
- Store your private key in Foundry’s secure keystore
- When prompted enter your private key and a password.
~/.foundry/keystores
which is not tracked by git.
Never share or commit your private key. Always keep it secure and handle with care.
Deploy Your Contracts
Now that your environment is set up, let’s deploy your contracts to Base Sepolia.- Use the following command to compile and deploy your contract
<contract-path>:<contract-name>
.
- After successful deployment, the transaction hash will be printed to the console output
-
Copy the deployed contract address and add it to your
.env
file
- Load the new environment variable
Verify Your Deployment
To ensure your contract was deployed successfully:- Check the transaction on Sepolia Basescan.
- Use the
cast
command to interact with your deployed contract from the command line
number
storage variable, which will be 0
.
Congratulations! You’ve deployed your smart contracts to Base Sepolia!
Next Steps
- Use Onchainkit to connect your frontend to your contracts! Onchainkit is a library of ready-to-use React components and Typescript utilities.
- Learn more about interacting with your contracts in the command line using Foundry from our Foundry tutorial.