What You’ll Achieve
By the end of this quickstart, you’ll have built an onchain app by:- Configuring your development environment
- Deploying your smart contracts to Base
- Interacting with your deployed contracts from the frontend
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
1
Bootstrap with OnchainKit
OnchainKit is a library of ready-to-use React components and Typescript utilities for building onchain apps. Run the following command in your terminal and follow the prompts to bootstrap your project.The prompots will ask you for a CDP API Key which you can get here.Once you’ve gone through the prompts, you’ll have a new project directory with a basic OnchainKit app. Run the following to see it live.You should see the following screen.
Once we’ve deployed our contracts, we’ll add a button that lets us interact with our contracts.
Terminal
Terminal

2
Install and initialize Foundry
The total tally will be stored onchain in a smart contract. We’ll use the Foundry framework to deploy our contract to the Base Sepolia testnet.Open the project and find the
- Create a new “contracts” folder in the root of your project
Terminal
- Install and initialize Foundry
Terminal
Counter.sol
contract file in the /contracts/src
folder. You’ll find the simple logic for our tally app.—no-gitBecause
contracts
is a folder in our project, we don’t want to initialize a separate git repository for it, so we add the --no-git
flag.3
Configure Foundry with Base
To deploy your smart contracts to Base, you need two key components:-Load your environment variables
- A node connection to interact with the Base network
- A funded private key to deploy the contract
- Create a
.env
file in yourcontracts
directory and add the Base and Base Sepolia RPC URLs
contracts/.env
Terminal
Base SepoliaBase 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.
4
Secure your private key
A private key with testnet funds is required to deploy the contract. You can generate a fresh private key here.
- Store your private key in Foundry’s secure keystore
Terminal
- 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. The foundry project provides a deploy script that will deploy the Counter.sol contract.1
Run the deploy script
- Use the following command to compile and deploy your contract
Terminal
<contract-path>:<contract-name>
.2
Save the contract address
After successful deployment, the transaction hash will be printed to the console outputCopy the deployed contract address and add it to your
.env
file3
Load the new environment variable
Terminal
4
Verify Your Deployment
To ensure your contract was deployed successfully:This will return the initial value of the Counter contract’s
- 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
.Interacting with your contract
To interact with the smart contract logic, we need to submit an onchain transaction. We can do this easily with theTransaction
component. This is a simplified version of the Transaction
component, designed to streamline the integration process. Instead of manually defining each subcomponent and prop, we can use this shorthand version which renders our suggested implementation of the component and includes the TransactionButton
and TransactionToast
components.
1
Add the Transaction component
Lets add the
Transaction
component to our page.tsx
file. Delete the existing content in the main
tag and replace it with the snippet below.page.tsx
2
Defining the contract calls
In the previous code snippet, you’ll see we imported
calls
from the calls.ts
file. This file provides the details needed to interact with our contract and call the increment
function. Create a new calls.ts
file in the same folder as your page.tsx
file and add the following code.calls.ts
Contract AddressThe
calls.ts
file contains the details of the contract interaction, including the contract address, which we saved in the previous step.3
Testing the component
Now, when you connect a wallet and click on the If the transaction was successful, the tally should have incremented by one!
Transact
button and approve the transaction, it will increment the tally onchain by one.We can verify that the onchain count took place onchain by once again using cast
to call the number
function on our contract.Terminal
- Configured a project with frontend and onchain infrastructure
- Deployed a smart contract to Base Sepolia
- Interacted with the contract from the frontend
Further Improvements
This is just the beginning. There are many ways we can improve upon this app. For example, we could:- Make the
increment
transaction gasless by integrating with Paymaster - Improve the wallet connection and sign up flow with the WalletModal component
- Add onchain Identity so we know who added the most recent tally