Skip to main content
This tutorial will guide you through setting up Foundry for Sei EVM development and using OpenZeppelin contracts to build secure, standardized smart contracts. We’ll cover environment setup, contract creation, deployment, and show how to leverage OpenZeppelin’s pre-built components with the powerful Foundry toolkit.
Watch the video walkthrough for this topic in the Video Tutorials section.
Deploy to Testnet FirstIt is highly recommended that you deploy to testnet (atlantic-2) first and verify everything works as expected before committing to mainnet. Doing so helps you catch bugs early, avoid unnecessary gas costs, and keep your users safe.

Try it before you install

Installing Foundry and scaffolding a project takes a few minutes. If you just want to see a contract deploy to Sei, you can do both of these right now in the browser. First, confirm the RPC endpoints you’ll put in foundry.toml respond: Then add Sei testnet to your wallet and deploy a minimal Counter.sol from Remix — no forge, no install. In Remix: compile under Solidity Compiler, then Deploy & Run with Environment set to Injected Provider — MetaMask.

Table of Contents

Prerequisites

Before we begin, ensure you have the following:
  • Foundry installed on your system
  • A basic understanding of Solidity and smart contract development
  • A wallet with SEI tokens for gas
  • Node.js (v18.0.0 or later) for ethers.js interactions

Setting Up Your Development Environment

First, let’s install Foundry if you haven’t already. Follow the installation guide or use the quick install command:
Create a new Foundry project:
This will create a standard Foundry project structure with src/, test/, and script/ directories.

Configuring Foundry for Sei EVM

Create a foundry.toml file in your project root to configure Foundry for Sei networks:
foundry.toml
Create a .env file to store your private key and other sensitive information:
.env
Add .env to your .gitignore file to prevent committing sensitive information such as your PRIVATE_KEY and potentially lose funds.

Using OpenZeppelin Contracts

OpenZeppelin provides a library of secure, tested smart contract components. Let’s install OpenZeppelin contracts:
Create a remappings.txt file to properly map the imports:

Creating and Deploying Smart Contracts

Let’s create different types of smart contracts. Choose from the tabs below based on what you want to build:
Let’s start with a simple counter contract. Update the default src/Counter.sol file:
src/Counter.sol
Create a deployment script in script/DeployCounter.s.sol:
script/DeployCounter.s.sol

Testing Your Smart Contracts

Foundry provides excellent testing capabilities. Let’s create comprehensive tests for our contracts.
Update test/Counter.t.sol:
test/Counter.t.sol
Run your tests with:
For more verbose output:

Deploying to Sei Testnet and Mainnet

Now let’s deploy our contracts to the Sei networks. You can use either Forge scripts or direct deployment commands. Deploy to Sei testnet:
Deploy to Sei mainnet:

Using Direct Forge Create Commands

Alternatively, you can deploy directly:
Successful deployment will output:

Interacting with Deployed Contracts

Once deployed, you can interact with your contracts using Foundry’s cast tool or ethers.js.

Using Cast Commands

Using ethers.js

Install ethers.js to interact with your contracts programmatically:
Create a Node.js script to interact with your deployed contracts:
interact.js
Foundry generates the ABI for contracts in the out folder. You can use this ABI to interact with contracts from other tools like ethers.js or web3.js.