BAiSEDagent

foundry

0
0
# Install this skill:
npx skills add BAiSEDagent/openclaw-skills --skill "foundry"

Install specific skill from multi-skill repository

# Description

Foundry toolkit for Solidity development. Forge testing, Cast interactions, Anvil local node, deployment scripts. Use when building or testing smart contracts.

# SKILL.md


name: foundry
description: "Foundry toolkit for Solidity development. Forge testing, Cast interactions, Anvil local node, deployment scripts. Use when building or testing smart contracts."
metadata:
openclaw:
emoji: "🔨"


Foundry

Blazing fast Solidity development toolkit. Forge (test), Cast (interact), Anvil (local node), Chisel (REPL).

Quick Start

forge init my-project
cd my-project
forge build
forge test

Project Structure

my-project/
├── src/           # Contracts
├── test/          # Tests (Solidity)
├── script/        # Deployment scripts
├── lib/           # Dependencies (git submodules)
└── foundry.toml   # Configuration

foundry.toml (Base Config)

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc = "0.8.24"
optimizer = true
optimizer_runs = 200

[rpc_endpoints]
base = "${BASE_RPC_URL}"
base_sepolia = "https://sepolia.base.org"

[etherscan]
base = { key = "${BASESCAN_API_KEY}", url = "https://api.basescan.org/api" }
base_sepolia = { key = "${BASESCAN_API_KEY}", url = "https://api-sepolia.basescan.org/api" }

Testing

// test/MyContract.t.sol
pragma solidity ^0.8.20;
import "forge-std/Test.sol";
import "../src/MyContract.sol";

contract MyContractTest is Test {
    MyContract c;

    function setUp() public {
        c = new MyContract();
    }

    function test_basicFunction() public {
        assertEq(c.getValue(), 42);
    }

    function testFuzz_setValue(uint256 x) public {
        c.setValue(x);
        assertEq(c.getValue(), x);
    }

    function testFail_unauthorized() public {
        vm.prank(address(0xdead));
        c.adminOnly(); // Should revert
    }
}

Key Cheatcodes

Cheatcode Purpose
vm.prank(addr) Next call from addr
vm.deal(addr, amt) Set ETH balance
vm.warp(ts) Set block.timestamp
vm.roll(num) Set block.number
vm.expectRevert() Expect next call reverts
vm.sign(pk, digest) Sign with private key
vm.createFork(rpc) Fork live chain

Fork Testing

# Test against live Base state
forge test --fork-url https://mainnet.base.org

Deployment

// script/Deploy.s.sol
pragma solidity ^0.8.20;
import "forge-std/Script.sol";
import "../src/MyContract.sol";

contract Deploy is Script {
    function run() external {
        vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
        new MyContract();
        vm.stopBroadcast();
    }
}
# Deploy to Base Sepolia
forge script script/Deploy.s.sol --rpc-url base_sepolia --broadcast --verify

# Deploy to Base mainnet
forge script script/Deploy.s.sol --rpc-url base --broadcast --verify

Cast (CLI Interaction)

# Read contract
cast call $CONTRACT "balanceOf(address)" $ADDR --rpc-url base

# Send transaction
cast send $CONTRACT "transfer(address,uint256)" $TO $AMT --rpc-url base --private-key $PK

# Get balance
cast balance $ADDR --rpc-url base

# Decode calldata
cast decode-calldata "transfer(address,uint256)" $CALLDATA

Gas Optimization

forge test --gas-report
forge snapshot          # Save gas snapshot
forge snapshot --diff   # Compare with previous

References

  • references/full-reference.md — Complete Foundry guide with detailed examples, advanced patterns, invariant testing, and deployment workflows

Cross-References

  • solidity: Language patterns
  • smart-contract-security: Security testing
  • testing-patterns: Test methodology
  • deployment-ops: Production deployment

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.