Skip to content
BaseHub by Will Binns Updated

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.

Base is EVM-equivalent, so Solidity and Vyper contracts carry over from Ethereum unchanged — same bytecode, same ABIs, same tooling. The one place that equivalence stops is the precompiles.

Base adds native precompiles at fixed addresses — the B20 token standard, the PolicyRegistry, and the B20 Factory among them. They are built into the node, so those addresses hold no bytecode, and a local EVM that does not know about them reverts the moment a contract calls one.

Stock Foundry now handles this. From v1.8.4, forge, cast, anvil, and chisel implement Base’s precompiles, and from v1.9.0 they also run the Denim rules that are live on Base Mainnet and Base Sepolia. Base support is switched on by choosing a Base hardfork, which this guide does below.

Ordinary token standards need none of this. ERC-20, ERC-721, ERC-1155, ERC-4626 vaults, and permissioned designs such as ERC-3643 are plain contracts and deploy on Base exactly as they do on Ethereum. B20 is the exception because it lives in the node: its method and event signatures are part of consensus, they keep parity with the core ERC-20 surface, and any B20 change ships with a network upgrade.

By the end of this guide you will have:

  • A Foundry v1.9.0+ environment with Base’s precompiles enabled
  • 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 v1.9.0 or later.
Terminal window
curl -L https://foundry.paradigm.xyz | bash
foundryup

Confirm what you got with forge --version. To pin a release, use foundryup --install <version>, for example foundryup --install v1.9.0.

  1. Initialize a Solidity project.
Terminal window
forge init
  1. Turn on Base’s precompiles for local tests. Add a Base hardfork to the [profile.default] section of foundry.toml; base:Denim matches what Base Mainnet and Base Sepolia run today.
hardfork = "base:Denim"

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

Foundry behaves like Ethereum unless told otherwise, and the switch differs by context:

Where it runsHow to enable Base
forge test and forge script locallySet hardfork = "base:Denim" in foundry.toml, or pass --hardfork base:Denim
A local anvil nodeanvil --hardfork base:Denim
A fork of Base Mainnet or Base SepoliaPass --fork-url; Foundry detects Base from the chain ID. Also pass --hardfork base:Denim (see below)
cast against a live Base RPCNothing; the Base node executes the precompiles

The hardfork value picks which upgrade’s rules and precompiles Foundry applies. Match it to the upgrade live on your target network:

ValueBase precompiles
base:AzulNone
base:BerylB20 factory, B20 tokens, PolicyRegistry, ActivationRegistry
base:CobaltBeryl’s precompiles with Cobalt’s B20 changes
base:DenimCobalt’s precompiles with Denim’s B20 and PolicyRegistry changes (requires Foundry v1.9.0 or later)

base-anvil is Base’s own Foundry fork. It installs prefixed binaries next to stock Foundry, with the precompiles on by default, and earlier versions of this guide used it. New projects should use Foundry v1.9.0 or later instead. Some B20 issuance samples still call base-cast (pinned to base-anvil v1.1.1); since those hit a live RPC, plain cast from v1.8.4 onward runs them unchanged.

CommandFoundry v1.9.0+ equivalent
base-forgeforge with hardfork = "base:Denim"
base-castcast
base-anvilanvil --hardfork base:Denim
base-chiselchisel

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 the 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.