Overview
The EVM smart contract workflow uses Foundry under the hood — the same toolchain used by Uniswap, OpenSea, and most serious Solidity teams. You getforge for compilation and testing, anvil for local development, and cast for chain interaction, all accessible through the AI chat without touching the terminal.
Project Structure
A standard Foundry project looks like this:foundry.toml
A minimal config:Compiling Contracts
Compile an Entire Project
If you have afoundry.toml:
forge build on the entire project. Dependencies like OpenZeppelin are installed automatically.
Compile a Single Contract
For quick prototyping without a full project:Compilation Output
After compilation you get:- Bytecode — the compiled contract ready for deployment
- ABI — the interface definition for interacting with the contract
- Bytecode file path — used by the deployment tool
OpenZeppelin Imports
Use the standard import format:npm install, no forge install.
Testing Contracts
Tests use Foundry’s testing framework (forge-std). Write tests in Solidity:
Deploying Contracts
To Local (Recommended for Development)
- Starts Anvil if not already running
- Switches wallet to Local EVM
- Funds your account with test ETH
- Deploys the compiled bytecode
- Returns the contract address
To Testnet
To Mainnet
With Constructor Arguments
Interacting with Deployed Contracts
Read Functions (Free, No Gas)
Write Functions (Costs Gas)
Using Cast (Low-Level)
For advanced chain interaction:Gas Estimation
Security Auditing
Common Patterns
| Pattern | Example Prompt |
|---|---|
| ERC-20 Token | "Create an ERC-20 with minting, burning, and pausable" |
| ERC-721 NFT | "Create an NFT with metadata URI and royalties" |
| ERC-1155 Multi-Token | "Create an ERC-1155 for a game with multiple item types" |
| Upgradeable (UUPS) | "Create an upgradeable ERC-20 using UUPS" |
| Access Control | "Add role-based access control to this contract" |
Deployment Checklist
Before deploying to mainnet:- All tests pass with no skipped tests
- Security audit is clean (no high/medium findings)
- Compiled with optimization enabled
- Constructor arguments verified
- Sufficient funds for gas
- Correct network selected
Troubleshooting
Compilation errors
Compilation errors
Common issues: missing semicolons, Solidity version mismatches (use
^0.8.24), import path errors (use @openzeppelin/contracts/... format), type mismatches.Deployment fails
Deployment fails
Check: wallet connected, sufficient gas funds, constructor args match expected types, contract under 24KB size limit.
Contract interaction fails
Contract interaction fails
Verify: correct contract address, correct network, function name and arg types match ABI,
require() conditions satisfied.Tests fail unexpectedly
Tests fail unexpectedly
Check
setUp() initialization, use vm.prank() for different addresses, use vm.expectRevert() before failing calls, run with verbose output.
