Using Foundry
Overview
Foundry is a fast, Rust-based toolkit for developing, testing, and deploying EVM-compatible smart contracts. It includes:
forge— for building, testing, and deploying contractscast— for interacting with deployed contractsanvil— for running a local Ethereum-compatible node
Foundry is well-suited for advanced developers who prefer Solidity-based tests and fast iteration.
Official Foundry repository: https://github.com/foundry-rs/foundry
Deployment Guide
Prerequisites
Before you begin, ensure you have:
- A Unix-like terminal (Linux, macOS, or WSL on Windows)
- A funded wallet private key with SHM. You can claim test SHM from faucet
- Access to Shardeum RPC endpoint
Step 1: Install Foundry
Restart your terminal (or reload your shell), then run:
Verify installation:
Step 2: Create a Foundry Project
Step 3: Write the SimpleStorage Contract
Create src/SimpleStorage.sol:
Step 4: Add a Simple Test
Create test/SimpleStorage.t.sol:
Run tests:
Step 5: Set Environment Variables
Create a .env file in the project root (or export variables in your shell):
SHARDEUM_RPC=YOUR_SHARDEUM_RPC_URL PRIVATE_KEY=YOUR_PRIVATE_KEY
Security note:
- Never commit private keys
- Add
.envto.gitignore
Step 6: Deploy to Shardeum Using Foundry
Foundry uses EIP-1559 transactions by default. If your Shardeum network requires legacy-style gas parameters, include --legacy in deployments.
If deployment succeeds, Foundry prints the contract address.
Step 7: Verify Deployment on the Explorer
Search the contract address on Shardeum Explorers
(Optional) Interact Using Cast
Read value:
Set a new value:
Summary
- Use
forge testfor local validation before deploying - Deploy with
forge create(include--legacyif required by the network) - Use explorers to confirm contract creation and activity
- Use
cast call/cast sendto interact from the terminal