Skip to main content
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.

Installation

Foundry installation is straightforward. Install using the official installer:
curl -L https://foundry.paradigm.xyz | bash
After running the installer, follow the instructions to re-open your terminal (or use source to reload environment variables), then run:
foundryup
Running foundryup will automatically install the latest stable version of the precompiled binaries:
  • forge - Build, test, and deploy tool
  • cast - CLI for interacting with contracts
  • anvil - Local testnet node
  • chisel - Solidity REPL

Creating a New Project

Initialize a new Foundry project:
forge init my-project
cd my-project
This creates a standard Foundry project structure with:
  • src/ - Your Solidity contracts
  • test/ - Your test files
  • script/ - Deployment scripts
  • foundry.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 build

Testing

Write tests in Solidity and run them:
forge test

Deploying

Deploy to MANTRA Chain testnet:
forge create MyContract \
  --rpc-url https://evm.dukong.mantrachain.io \
  --private-key $PRIVATE_KEY \
  --chain-id 5887

Deployment 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.io
Then:
source .env
forge create --rpc-url "$RPC_URL_MANTRA_EVM" --private-key "$FOUNDRY_PK" src/Counter.sol:Counter

Next Steps