foundry-solidity
/foundry-solidity
Build and test Solidity contracts with Foundry. Use when developing Ethereum contracts, writing Forge tests, deploying with scripts, or debugging with Cast/Anvil. Triggers on forge, cast, anvil, foundry.toml, *.t.sol, or *.s.sol.
Assessment and security
- Files in this package
- 17
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 1
No signals detected. Repository changed on 24.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Build and test Solidity contracts with Foundry. Use when developing Ethereum contracts, writing Forge tests, deploying with scripts, or debugging with Cast/Anvil. Triggers on forge, cast, anvil, foundry.toml, *.t.sol, or *.s.sol.
Original author description
Build and test Solidity contracts with Foundry. Use when developing Ethereum contracts, writing Forge tests, deploying with scripts, or debugging with Cast/Anvil. Triggers on forge, cast, anvil, foundry.toml, *.t.sol, or *.s.sol.
How it works
- When to Use This Skill
- Quick Start
- Project Structure
- Core Commands
- Basic Test Contract
- Essential Cheatcodes
- Deploy Script
- Modern Solidity Patterns (0.8.30)
- Configuration (foundry.toml)
- References
SKILL.md preview
---
name: foundry-solidity
description: Build and test Solidity contracts with Foundry. Use when developing Ethereum contracts, writing Forge tests, deploying with scripts, or debugging with Cast/Anvil. Triggers on forge, cast, anvil, foundry.toml, *.t.sol, or *.s.sol.
metadata:
version: "0.2.5"
categories: "development"
topics: "solidity, foundry, forge, smart-contracts, ethereum"
openclaw:
homepage: https://github.com/tenequm/skills/tree/main/skills/foundry-solidity
emoji: "⚒️"
primaryEnv: PRIVATE_KEY
requires:
anyBins:
- forge
- cast
install:
- kind: brew
formula: foundry
bins:
- forge
- cast
- anvil
envVars:
- name: PRIVATE_KEY
required: false
description: Deployer signing key. Use throwaway/testnet keys.
- name: ETHERSCAN_API_KEY
required: false
description: Etherscan verification API key.
- name: MAINNET_RPC_URL
required: false
description: Ethereum mainnet RPC endpoint.
- name: SEPOLIA_RPC_URL
required: false
description: Sepolia testnet RPC endpoint.
- name: ARBITRUM_RPC_URL
required: false
description: Arbitrum RPC endpoint.
- name: OPTIMISM_RPC_URL
required: false
description: Optimism RPC endpoint.
- name: ARBISCAN_API_KEY
required: false
description: Arbiscan verification key.
- name: OPTIMISTIC_ETHERSCAN_API_KEY
required: false
description: Optimistic Etherscan verification key.
- name: POLYGONSCAN_API_KEY
required: false
description: Polygonscan verification key.
- name: BASESCAN_API_KEY
required: false
description: Basescan verification key.
- name: DEPLOYER_PRIVATE_KEY
required: false
description: Alternative deployer key alias.
- name: TEST_ADMIN
required: false
description: Test admin address used in fork tests.
---
# Foundry Solidity Development
Complete guide for building secure, efficient smart contracts with **Foundry 1.5.0** and **Solidity 0.8.30**.
## When to Use This Skill
- Developing Ethereum/EVM smart contracts
- Writing Forge tests (unit, fuzz, invariant, fork)
- Deploying contracts with scripts
- Using Foundry tools (forge, cast, anvil, chisel)
- Working with `foundry.toml`, `*.t.sol`, `*.s.sol` files
- Debugging transactions and contract interactions
## Quick Start
```bash
# Create new project
forge init my-project && cd my-project
# Build contracts
forge build
# Run tests
forge test
# Deploy (dry-run)
forge script script/Deploy.s.sol --rpc-url sepolia
# Deploy (broadcast)
forge script script/Deploy.s.sol --rpc-url sepolia --broadcast --verify
```
## Project Structure
```
my-project/
├── foundry.toml # Configuration
├── src/ # Contracts
│ └── Counter.sol
├── test/ # Tests (*.t.sol)
│ └── Counter.t.sol
├── script/ # Deploy scripts (*.s.sol)
│ └── Deploy.s.sol
└── lib/ # Dependencies
└── forge-std/
```
## Core Commands
### Build & Test
```bash
forge build # Compile
forge test # Run all tests
forge test -vvvv # With traces
forge test --match-test testDeposit # Filter by test name
forge test --match-contract Vault # Filter by contract
forge test --fork-url $RPC_URL # Fork testing
forge test --gas-report # Gas usage report
```
### Deployment
```bash
# Single contract
forge create src/Token.sol:Token --rpc-url sepolia --private-key $KEY --broadcast
# Script deployment (recommended)
forge script script/Deploy.s.sol:Deploy --rpc-url sepolia --broadcast --verify
# Verify existing contract
forge verify-contract $ADDRESS src/Token.sol:Token --chain sepolia
```
### Cast - Blockchain Interactions
```bash
cast call $CONTRACT "balanceOf(address)" $USER --rpc-url mainnet
cast send $CONTRACT "transfer(address,uint256)" $TO $AMOUNT --private-key $KEY
cast decode-tx $TX_HASH
cast storage $CONTRACT 0 --rpc-url mainnet
```
### Anvil - Local Node
```bash
anvil # Start local node
anvil --fork-url $RPC_URL # Fork mainnet
anvil --fork-block-number 18000000
```
## Basic Test Contract
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
import {Test, console} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";
contract CounterTest is Test {
Counter public counter;
address public user;
function setUp() public {
counter = new Counter();
user = makeAddr("user");
deal(user, 10 ether);
}
function test_Increment() public {
counter.increment();
assertEq(counter.number(), 1);
}
function test_RevertWhen_Unauthorized() public {
vm.expectRevert("Unauthorized");
vm.prank(user);
counter.adminFunction();
}
function testFuzz_SetNumber(uint256 x) public {
x = bound(x, 0, 1000);
counter.setNumber(x);
assertEq(counter.number(), x);
}
}
```
## Essential Cheatcodes
```solidity
// Identity & ETH
address alice = makeAddr("alice"); // Create labeled address
deal(alice, 10 ether); // Give ETH
deal(address(token), alice, 1000e18); // Give ERC20
// Impersonation
vm.prank(alice); // Next call as alice
vm.startPrank(alice); // All calls as alice
vm.stopPrank();
// Time & Block
vm.warp(block.timestamp + 1 days); // Set timestamp
vm.roll(block.number + 100); // Set block number
// Assertions
vm.expectRevert("Error message"); // Expect revert
vm.expectRevert(CustomError.selector); // Custom error
vm.expectEmit(true, true, false, true); // Expect event
emit Transfer(from, to, amount); // Must match next emit
// Storage
vm.store(addr, slot, value); // Write storage
vm.load(addr, slot); // Read storage
```
## Deploy Script
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
import {Script, console} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
contract Deploy is Script {
function run() external {
uint256 deployerKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerKey);
Counter counter = new Counter();
counter.setNumber(42);
vm.stopBroadcast();
console.log("Deployed to:", address(counter));
}
}
```
## Modern Solidity Patterns (0.8.30)
```solidity
// Custom errors (gas efficient)
error InsufficientBalance(uint256 available, uint256 required);
// Transient storage (0.8.28+) - cheap reentrancy guard
bool transient locked;
modifier nonReentrant() {
require(!locked, "Reentrancy");
locked = true;
_;
locked = false;
}
// Immutable variables (cheap reads)
address public immutable owner;
// Named mapping parameters
mapping(address user => uint256 balance) public balances;
// require with custom error (0.8.26+)
require(amount <= balance, InsufficientBalance(balance, amount));
```
## Configuration (foundry.toml)
```toml
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc = "0.8.30"
optimizer = true
optimizer_runs = 200
evm_version = "prague"
fuzz.runs = 256
invariant.runs = 256
invariant.depth = 50
[rpc_endpoints]
mainnet = "${MAINNET_RPC_URL}"
sepolia = "${SEPOLIA_RPC_URL}"
[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}" }
sepolia = { key = "${ETHERSCAN_API_KEY}" }
[profile.ci]
fuzz.runs = 10000
invariant.runs = 1000
```
## References
For detailed guides, see:
- **Testing**: See `references/testing.md` for complete testing patterns (unit, fuzz, invariant, fork), all cheatcodes, and best practices
- **forge-std API**: See `references/forge-std-api.md` for complete library reference (150+ functions)
- **Solidity 0.8.30**: See `references/solidity-modern.md` for new features and modern syntax
- **Deployment**: See `references/deployment.md` for scripting, verification, and multi-chain deployment
- **Configuration**: See `references/configuration.md` for all foundry.toml options
- **Gas Optimization**: See `references/gas-optimization.md` for storage packing, compiler settings, and profiling
- **Patterns**: See `references/patterns.md` for access control, reentrancy guards, factories, and common idioms
- **Security**: See `references/security.md` for vulnerabilities, defensive patterns, and audit preparation
- **Resources**: See `references/resources.md` for official docs, libraries, security tools, and learning paths
- **Debugging**: See `references/debugging.md` for traces, breakpoints, console.log, and the interactive debugger
- **Dependencies**: See `references/dependencies.md` for forge install, remappings, and Soldeer package manager
- **CI/CD**: See `references/cicd.md` for GitHub Actions workflows, caching, and gas tracking
- **Chisel**: See `references/chisel.md` for the interactive Solidity REPL
- **Cast Advanced**: See `references/cast-advanced.md` for decoding, encoding, wallet management, and batch operations
- **Anvil Advanced**: See `references/anvil-advanced.md` for impersonation, state manipulation, and mining modes
Files in this package (17)
- LICENSE.txt 9 KB
- SKILL.md 9 KB
- references/anvil-advanced.md 5 KB
- references/cast-advanced.md 5 KB
- references/chisel.md 2 KB
- references/cicd.md 6 KB
- references/configuration.md 8 KB
- references/debugging.md 5 KB
- references/dependencies.md 4 KB
- references/deployment.md 14 KB
- references/forge-std-api.md 13 KB
- references/gas-optimization.md 7 KB
- references/patterns.md 13 KB
- references/resources.md 4 KB
- references/security.md 12 KB
- references/solidity-modern.md 15 KB
- references/testing.md 14 KB
Versions
The database has no other skills named foundry-solidity.
Identical content appears in 1 other GitHub folders. We show one copy with the highest score.
Database snapshot: 13.11.2026 · package version 7270b711b78d (SHA-256 digest of the entire package)
Downloads in the last 30 days: 3 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100solidity-smart-contract-security-and-foundry
Advanced Solidity smart contract development, security hardening, vulnerability defense, and testing framework using Foundry (Forge, Cast, Anvil). Use when writing, auditing, testing, or securing Ethereum/EVM smart contracts. - 100solidity
Solidity is the programming language for smart contracts on Ethereum and other EVM chains. This skill covers contracts, ERC-20 tokens, Hardhat and Foundry. Use when a user asks to create a smart contract, build an ERC-20 token, deploy to Ethereum, write NFT contracts, or develop DeFi protocols. - 86ds-solidity
Use when changing Solidity contracts, Foundry tests, upgrade layouts, or fork-dependent behavior in an existing contract project. - 100solidity-guide
Solidity/Ethereum guardrails, patterns, and best practices for AI-assisted development. Use when working with Solidity files (.sol), or when the user mentions Solidity/Ethereum/smart contracts. Provides gas optimization patterns, reentrancy prevention, upgradeable contract… - 100web3-testing
Test smart contracts comprehensively using Hardhat and Foundry with unit tests, integration tests, and mainnet forking. Use when testing Solidity contracts, setting up blockchain test suites, or va... - 100web3-testing
Test smart contracts comprehensively using Hardhat and Foundry with unit tests, integration tests, and mainnet forking. Use when testing Solidity contracts, setting up blockchain test suites, or validating DeFi protocols.