EVM Development
Using Foundry
Deploy and test smart contracts on MANTRA Chain using Foundry
Foundry is a fast, Solidity-native development toolkit for Ethereum smart contracts. It's known for its blazing-fast speed and Solidity-centric approach, making it a great alternative to JavaScript-based tools like Hardhat.
Info
Foundry Tutorial Resources:
Installation
Foundry installation is straightforward. Install using the official installer:
curl -L https://foundry.paradigm.xyz | bashAfter running the installer, follow the instructions to re-open your terminal (or use source to reload environment variables), then run:
foundryupRunning foundryup will automatically install the latest stable version of the precompiled binaries:
forge- Build, test, and deploy toolcast- CLI for interacting with contractsanvil- Local testnet nodechisel- Solidity REPL
Creating a New Project
Initialize a new Foundry project:
forge init my-project
cd my-projectThis creates a standard Foundry project structure with:
src/- Your Solidity contractstest/- Your test filesscript/- Deployment scriptsfoundry.toml- Configuration file
Configuring for MANTRA Chain
Update foundry.toml to configure MANTRA Chain networks:
[rpc_endpoints]
mantra_mainnet = "https://evm.mantrachain.io"
mantra_testnet = "https://evm.dukong.mantrachain.io"
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.23"
[profile.mantra_mainnet]
chain_id = 5888
rpc_url = "https://evm.mantrachain.io"
[profile.mantra_testnet]
chain_id = 5887
rpc_url = "https://evm.dukong.mantrachain.io"Building Contracts
Build your contracts:
forge buildTesting
Write tests in Solidity and run them:
forge testDeploying
Deploy to MANTRA Chain testnet:
forge create MyContract \
--rpc-url https://evm.dukong.mantrachain.io \
--private-key $PRIVATE_KEY \
--chain-id 5887Deployment walkthrough (legacy pattern)
If you prefer keeping deployment config in a .env file (handy for scripts/CI), you can use a pattern like:
FOUNDRY_PROFILE=mantra_testnet
FOUNDRY_PK=<YOUR_PRIVATE_KEY>
RPC_URL_MANTRA_EVM=https://evm.dukong.mantrachain.ioThen:
source .env
forge create --rpc-url "$RPC_URL_MANTRA_EVM" --private-key "$FOUNDRY_PK" src/Counter.sol:CounterNext Steps
- Learn about deploying contracts
- Understand contract verification
- Explore EVM development