Deploy on Base
Set up a Foundry project, point it at Base, and deploy a contract to Base Sepolia in a single end-to-end workflow.
What you build
Section titled “What you build”By the end of this guide you will have:
- A Foundry-based development environment configured for Base
- A smart contract deployed to Base Sepolia
- A connection pattern your frontend can reuse against your contracts
Set up your development environment
Section titled “Set up your development environment”- Create a project directory.
mkdir my-base-project && cd my-base-project- Install Foundry, the framework used throughout this guide.
curl -L https://foundry.paradigm.xyz | bashfoundryupThe installer pulls Foundry and updates it to the latest release.
- Initialize a Solidity project.
forge initThe Foundry project is ready. The starter contract sits at src/Counter.sol — this guide uses that contract as the deployment target.
Configure Foundry for Base
Section titled “Configure Foundry for Base”Deploying to Base requires two pieces:
- An RPC connection to the network
- A funded private key for signing the deployment transaction
1. Set up your RPC connection
Section titled “1. Set up your RPC connection”- Create a
.envfile at the project root. - Add the Base RPC URLs.
BASE_RPC_URL="https://mainnet.base.org"BASE_SEPOLIA_RPC_URL="https://sepolia.base.org"- Load the variables into your shell.
source .env2. Secure your private key
Section titled “2. Secure your private key”- Import your private key into Foundry’s encrypted keystore.
cast wallet import deployer --interactive- Paste the key when prompted and set a password.
The encrypted key is stored at ~/.foundry/keystores, which is excluded from git.
Deploy your contract
Section titled “Deploy your contract”With the environment configured, deploy to Base Sepolia.
- (Optional) Run a dry run first to confirm the deployment is well-formed.
forge create ./src/Counter.sol:Counter --rpc-url $BASE_SEPOLIA_RPC_URL --account deployerThis simulates the deploy without broadcasting. You will see the transaction details and ABI; nothing is written onchain.
- Add
--broadcastto actually deploy.
forge create ./src/Counter.sol:Counter --rpc-url $BASE_SEPOLIA_RPC_URL --account deployer --broadcastThe contract argument follows the format <contract-path>:<contract-name>.
- A successful deploy prints output similar to:
Deployer: 0x...Deployed to: 0x... <-- YOUR CONTRACT ADDRESSTransaction hash: 0x...- Save the deployed address into
.env.
COUNTER_CONTRACT_ADDRESS="0x..."Replace 0x... with the address from the output.
- Reload the variables.
source .envVerify your deployment
Section titled “Verify your deployment”To confirm the contract is live:
- Look up the transaction hash on Sepolia Basescan.
- Read the contract directly with
cast:
cast call $COUNTER_CONTRACT_ADDRESS "number()(uint256)" --rpc-url $BASE_SEPOLIA_RPC_URLThe call returns the initial value of the Counter’s number storage slot, which is 0.
The contract is now live on Base Sepolia.
Next steps
Section titled “Next steps”- Wire a frontend to your contracts using wagmi or viem.
- Dive deeper into Foundry workflows in the Foundry deployment tutorial.