Skip to content

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.

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
  1. Create a project directory.
Terminal window
mkdir my-base-project && cd my-base-project
  1. Install Foundry, the framework used throughout this guide.
Terminal window
curl -L https://foundry.paradigm.xyz | bash
foundryup

The installer pulls Foundry and updates it to the latest release.

  1. Initialize a Solidity project.
Terminal window
forge init

The Foundry project is ready. The starter contract sits at src/Counter.sol — this guide uses that contract as the deployment target.

Deploying to Base requires two pieces:

  1. An RPC connection to the network
  2. A funded private key for signing the deployment transaction
  1. Create a .env file at the project root.
  2. Add the Base RPC URLs.
Terminal window
BASE_RPC_URL="https://mainnet.base.org"
BASE_SEPOLIA_RPC_URL="https://sepolia.base.org"
  1. Load the variables into your shell.
Terminal window
source .env
  1. Import your private key into Foundry’s encrypted keystore.
Terminal window
cast wallet import deployer --interactive
  1. Paste the key when prompted and set a password.

The encrypted key is stored at ~/.foundry/keystores, which is excluded from git.

With the environment configured, deploy to Base Sepolia.

  1. (Optional) Run a dry run first to confirm the deployment is well-formed.
Terminal window
forge create ./src/Counter.sol:Counter --rpc-url $BASE_SEPOLIA_RPC_URL --account deployer

This simulates the deploy without broadcasting. You will see the transaction details and ABI; nothing is written onchain.

  1. Add --broadcast to actually deploy.
Terminal window
forge create ./src/Counter.sol:Counter --rpc-url $BASE_SEPOLIA_RPC_URL --account deployer --broadcast

The contract argument follows the format <contract-path>:<contract-name>.

  1. A successful deploy prints output similar to:
Deployer: 0x...
Deployed to: 0x... <-- YOUR CONTRACT ADDRESS
Transaction hash: 0x...
  1. Save the deployed address into .env.
Terminal window
COUNTER_CONTRACT_ADDRESS="0x..."

Replace 0x... with the address from the output.

  1. Reload the variables.
Terminal window
source .env

To confirm the contract is live:

  1. Look up the transaction hash on Sepolia Basescan.
  2. Read the contract directly with cast:
Terminal window
cast call $COUNTER_CONTRACT_ADDRESS "number()(uint256)" --rpc-url $BASE_SEPOLIA_RPC_URL

The call returns the initial value of the Counter’s number storage slot, which is 0.

The contract is now live on Base Sepolia.