Watch the video walkthrough for this topic in the Video Tutorials section.
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 infoundry.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
- Try it before you install
- Prerequisites
- Setting Up Your Development Environment
- Configuring Foundry for Sei EVM
- Using OpenZeppelin Contracts
- Creating and Deploying Smart Contracts
- Testing Your Smart Contracts
- Deploying to Sei Testnet and Mainnet
- Interacting with Deployed Contracts
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:src/, test/, and script/ directories.
Configuring Foundry for Sei EVM
Create afoundry.toml file in your project root to configure Foundry for Sei networks:
foundry.toml
.env file to store your private key and other sensitive information:
.env
Using OpenZeppelin Contracts
OpenZeppelin provides a library of secure, tested smart contract components. Let’s install OpenZeppelin contracts: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:- Counter Contract
- ERC20 Token
- ERC721 NFT
Let’s start with a simple counter contract. Update the default Create a deployment script in
src/Counter.sol file:src/Counter.sol
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.- Counter Tests
- ERC20 Tests
- ERC721 Tests
Update
test/Counter.t.sol:test/Counter.t.sol
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.Using Forge Scripts (Recommended)
Deploy to Sei testnet:Using Direct Forge Create Commands
Alternatively, you can deploy directly:Interacting with Deployed Contracts
Once deployed, you can interact with your contracts using Foundry’scast tool or ethers.js.
Using Cast Commands
Using ethers.js
Install ethers.js to interact with your contracts programmatically: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.