foundry-framework

Expert usage of Foundry (Forge, Cast, Anvil, Chisel) for smart contract development, testing, and deployment. Includes fuzzing, gas reporting, local development, and deployment scripting capabilities.

509 stars

Best use case

foundry-framework is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Expert usage of Foundry (Forge, Cast, Anvil, Chisel) for smart contract development, testing, and deployment. Includes fuzzing, gas reporting, local development, and deployment scripting capabilities.

Teams using foundry-framework should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/foundry-framework/SKILL.md --create-dirs "https://raw.githubusercontent.com/a5c-ai/babysitter/main/library/specializations/cryptography-blockchain/skills/foundry-framework/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/foundry-framework/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How foundry-framework Compares

Feature / Agentfoundry-frameworkStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Expert usage of Foundry (Forge, Cast, Anvil, Chisel) for smart contract development, testing, and deployment. Includes fuzzing, gas reporting, local development, and deployment scripting capabilities.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Foundry Framework Skill

Expert-level usage of Foundry, the blazing fast, portable, and modular toolkit for Ethereum application development.

## Capabilities

- **Forge Testing**: Write and run Solidity tests with fuzzing
- **Gas Optimization**: Generate detailed gas reports and snapshots
- **Local Development**: Use Anvil for local blockchain
- **Chain Interaction**: Execute Cast commands for on-chain operations
- **Project Configuration**: Set up foundry.toml for projects
- **Deployment Scripts**: Write and run forge scripts
- **REPL Debugging**: Use Chisel for Solidity exploration

## Installation

```bash
# Install Foundry
curl -L https://foundry.paradigm.xyz | bash

# Update to latest
foundryup

# Verify installation
forge --version
cast --version
anvil --version
chisel --version
```

## Project Setup

### Initialize Project

```bash
# New project
forge init my_project
cd my_project

# Add dependencies
forge install OpenZeppelin/openzeppelin-contracts
forge install foundry-rs/forge-std
```

### foundry.toml Configuration

```toml
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc = "0.8.20"
optimizer = true
optimizer_runs = 200
via_ir = false

[profile.default.fuzz]
runs = 256
max_test_rejects = 65536
seed = "0x1234"

[profile.default.invariant]
runs = 256
depth = 15
fail_on_revert = false

[profile.ci]
fuzz = { runs = 10000 }
invariant = { runs = 1000, depth = 50 }

[rpc_endpoints]
mainnet = "${MAINNET_RPC_URL}"
sepolia = "${SEPOLIA_RPC_URL}"
arbitrum = "${ARBITRUM_RPC_URL}"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}" }
sepolia = { key = "${ETHERSCAN_API_KEY}" }
```

## Forge Testing

### Basic Test

```solidity
// test/Counter.t.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "forge-std/Test.sol";
import "../src/Counter.sol";

contract CounterTest is Test {
    Counter public counter;

    function setUp() public {
        counter = new Counter();
        counter.setNumber(0);
    }

    function test_Increment() public {
        counter.increment();
        assertEq(counter.number(), 1);
    }

    function testFail_Underflow() public {
        counter.decrement();
    }
}
```

### Fuzz Testing

```solidity
contract FuzzTest is Test {
    function testFuzz_SetNumber(uint256 x) public {
        counter.setNumber(x);
        assertEq(counter.number(), x);
    }

    function testFuzz_BoundedInput(uint256 x) public {
        x = bound(x, 1, 100);
        // x is now between 1 and 100
    }
}
```

### Invariant Testing

```solidity
contract InvariantTest is Test {
    Counter public counter;

    function setUp() public {
        counter = new Counter();
        targetContract(address(counter));
    }

    function invariant_NumberNeverNegative() public {
        assertTrue(counter.number() >= 0);
    }

    function invariant_NumberUnderMax() public {
        assertTrue(counter.number() < type(uint256).max);
    }
}
```

### Fork Testing

```solidity
contract ForkTest is Test {
    function setUp() public {
        // Fork mainnet at specific block
        vm.createSelectFork("mainnet", 18000000);
    }

    function test_MainnetState() public {
        // Interact with mainnet contracts
        IERC20 dai = IERC20(0x6B175474E89094C44Da98b954EescdeCB5c811d7);
        uint256 balance = dai.balanceOf(address(this));
    }
}
```

## Forge Commands

```bash
# Build project
forge build

# Run tests
forge test

# Run tests with verbosity
forge test -vvvv

# Run specific test
forge test --match-test testFuzz_SetNumber

# Run tests with gas report
forge test --gas-report

# Generate gas snapshot
forge snapshot

# Compare gas snapshots
forge snapshot --diff

# Coverage
forge coverage

# Format code
forge fmt
```

## Cast Commands

### Read Chain Data

```bash
# Get ETH balance
cast balance 0x... --rpc-url $RPC

# Read contract storage
cast storage 0x... 0 --rpc-url $RPC

# Call view function
cast call 0x... "balanceOf(address)" 0x... --rpc-url $RPC

# Decode calldata
cast calldata-decode "transfer(address,uint256)" 0x...
```

### Send Transactions

```bash
# Send ETH
cast send 0x... --value 1ether --rpc-url $RPC --private-key $KEY

# Call contract function
cast send 0x... "transfer(address,uint256)" 0x... 1000 --rpc-url $RPC --private-key $KEY
```

### Utility Commands

```bash
# Convert units
cast to-wei 1 ether
cast from-wei 1000000000000000000

# Compute function selector
cast sig "transfer(address,uint256)"

# Get ABI
cast abi-encode "transfer(address,uint256)" 0x... 100

# Decode ABI
cast abi-decode "balanceOf(address)(uint256)" 0x...
```

## Anvil Local Node

```bash
# Start local node
anvil

# Start with specific chain ID
anvil --chain-id 31337

# Fork mainnet
anvil --fork-url $MAINNET_RPC

# Fork at specific block
anvil --fork-url $MAINNET_RPC --fork-block-number 18000000

# Preload accounts
anvil --accounts 20 --balance 10000
```

### Anvil RPC

```bash
# Impersonate account
cast rpc anvil_impersonateAccount 0x... --rpc-url http://localhost:8545

# Set balance
cast rpc anvil_setBalance 0x... 0x1000000000000000000 --rpc-url http://localhost:8545

# Mine blocks
cast rpc anvil_mine 10 --rpc-url http://localhost:8545

# Set block timestamp
cast rpc evm_setNextBlockTimestamp 1700000000 --rpc-url http://localhost:8545
```

## Deployment Scripts

### Script Example

```solidity
// script/Deploy.s.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "../src/Counter.sol";

contract DeployScript is Script {
    function setUp() public {}

    function run() public {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");

        vm.startBroadcast(deployerPrivateKey);

        Counter counter = new Counter();
        counter.setNumber(42);

        vm.stopBroadcast();

        console.log("Counter deployed at:", address(counter));
    }
}
```

### Run Scripts

```bash
# Simulate deployment
forge script script/Deploy.s.sol --rpc-url $RPC

# Deploy to network
forge script script/Deploy.s.sol --rpc-url $RPC --broadcast

# Verify on Etherscan
forge script script/Deploy.s.sol --rpc-url $RPC --broadcast --verify
```

## Chisel REPL

```bash
# Start Chisel
chisel

# In REPL
> uint256 x = 100
> x * 2
200
> address(this)
0x...
```

## Process Integration

| Process | Purpose |
|---------|---------|
| `smart-contract-development-lifecycle.js` | Full development |
| `smart-contract-fuzzing.js` | Fuzzing and invariant testing |
| `invariant-testing.js` | Property-based testing |
| `gas-optimization.js` | Gas profiling |
| All DeFi processes | Testing and deployment |

## Best Practices

1. Use `forge fmt` before committing
2. Maintain gas snapshots for regression testing
3. Use fork testing for integration tests
4. Set appropriate fuzz runs for CI
5. Use profile-based configuration
6. Keep foundry.toml in version control

## See Also

- `skills/hardhat-framework/SKILL.md` - Alternative framework
- `skills/echidna-fuzzer/SKILL.md` - Advanced fuzzing
- `skills/gas-optimization/SKILL.md` - Gas optimization
- [Foundry Book](https://book.getfoundry.sh/)

Related Skills

contract-test-framework

509
from a5c-ai/babysitter

Consumer-driven contract testing for SDK-API compatibility. Generate Pact consumer tests, verify provider contracts, configure Pact broker, and implement can-i-deploy checks.

cli-framework-builder

509
from a5c-ai/babysitter

Build command-line interfaces for SDK interaction

Mobile Testing Frameworks

509
from a5c-ai/babysitter

Comprehensive mobile testing framework expertise

unreal-gamesframework

509
from a5c-ai/babysitter

Unreal Engine Gameplay Ability System (GAS) skill for attributes, abilities, and gameplay effects.

ethical-framework-application

509
from a5c-ai/babysitter

Apply multiple ethical frameworks (deontological, consequentialist, virtue ethics, care ethics) systematically to moral problems and generate reasoned recommendations

data-flow-analysis-framework

509
from a5c-ai/babysitter

Design and implement data-flow analyses for compiler optimization

aiml-validation-framework

509
from a5c-ai/babysitter

AI/ML medical device validation skill implementing FDA's GMLP principles

gap-analysis-framework

509
from a5c-ai/babysitter

Structured gap analysis with automated comparison and prioritization for current vs future state analysis

qt-installer-framework-config

509
from a5c-ai/babysitter

Configure Qt Installer Framework for cross-platform installers with component management, online updates, and custom UI

hardhat-framework

509
from a5c-ai/babysitter

Expert usage of Hardhat for smart contract development, testing, and deployment. Includes TypeChain generation, plugin ecosystem, network forking, and deployment management.

framework-compatibility-checker

509
from a5c-ai/babysitter

Check codebase compatibility with target framework versions and generate migration paths

process-builder

509
from a5c-ai/babysitter

Scaffold new babysitter process definitions following SDK patterns, proper structure, and best practices. Guides the 3-phase workflow from research to implementation.

Workflow & Productivity