Watch the video walkthrough for this topic in the Video Tutorials section.
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 infoundry.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
- 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 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:src/, test/, and script/ directories.
Configuring Foundry for Sei EVM
To configure Foundry for Sei networks, create afoundry.toml file in your project root:
foundry.toml
.env file to store your private key and other sensitive information:
.env
Using OpenZeppelin contracts
OpenZeppelin has a library of secure, tested smart contract components. Install the OpenZeppelin contracts: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:- Counter Contract
- ERC20 Token
- ERC721 NFT
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 has built-in support for testing. Create tests for your contracts.- Counter Tests
- ERC20 Tests
- ERC721 Tests
Update
test/Counter.t.sol:test/Counter.t.sol
Deploying to Sei Testnet and Mainnet
You can deploy your contracts to the Sei networks with Forge scripts or with 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
After deployment, you can interact with your contracts through Foundry’scast tool or ethers.js.
Using Cast commands
Using ethers.js
To interact with your contracts programmatically, install ethers.js: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.