Skip to main content
This tutorial shows how to set up Foundry for Sei EVM development. It covers environment setup, contract creation, and deployment. You use OpenZeppelin’s pre-built components with the Foundry toolkit to build secure, standardized smart contracts.
Watch the video walkthrough for this topic in the Video Tutorials section.
Deploy to Sei Testnet firstWe highly recommend that you deploy to Sei Testnet first. Make sure that everything works as expected before you deploy to Sei Mainnet. This helps you catch bugs early, avoid unnecessary gas costs, and keep your users safe.

Try it before you install

It takes a few minutes to install Foundry and scaffold a project. If you only want to see a contract deploy to Sei, you can do both of these steps in the browser now. First, confirm that the RPC endpoints you will use in foundry.toml respond: Then add Sei Testnet to your wallet and deploy a minimal Counter.sol from Remix. You do not need forge or a local install. In Remix, compile the contract under Solidity Compiler. Then deploy it under Deploy & Run, with Environment set to Injected Provider - MetaMask.

Table of contents

Prerequisites

Before you start, make sure that 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

If you have not installed Foundry yet, install it first. Follow the installation guide or use the quick install command:
Create a new Foundry project:
This creates a standard Foundry project structure with src/, test/, and script/ directories.

Configuring Foundry for Sei EVM

To configure Foundry for Sei networks, create a foundry.toml file in your project root:
foundry.toml
Create a .env file to store your private key and other sensitive information:
.env
Add .env to your .gitignore file. If you commit sensitive information such as your PRIVATE_KEY, you can lose funds.

Using OpenZeppelin contracts

OpenZeppelin has a library of secure, tested smart contract components. Install the OpenZeppelin contracts:
Create a remappings.txt file to map the imports correctly:

Creating and deploying smart contracts

Each tab below creates a different type of smart contract. Choose the one that matches what you want to build:
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 has built-in support for testing. Create tests for your contracts.
Update test/Counter.t.sol:
test/Counter.t.sol
Run your tests:
For more verbose output, run:

Deploying to Sei Testnet and Mainnet

You can deploy your contracts to the Sei networks with Forge scripts or with direct deployment commands. Deploy to Sei Testnet:
Deploy to Sei Mainnet:

Using direct Forge create commands

Alternatively, you can deploy directly:
A successful deployment prints output similar to this:

Interacting with deployed contracts

After deployment, you can interact with your contracts through Foundry’s cast tool or ethers.js.

Using Cast commands

Using ethers.js

To interact with your contracts programmatically, install ethers.js:
Create a Node.js script to interact with your deployed contracts:
interact.js
Foundry generates contract ABIs in the out folder. You can use these ABIs to interact with contracts from other tools, such as ethers.js or web3.js.