Web3 Docs
Current patterns and references for EVM development. Covers the full stack: contracts → testing → deployment → frontend integration.
Stack Coverage
| Layer | Tool | Reference |
|---|
| Contracts | Solidity 0.8.x | INLINECODE0 |
| Framework |
Foundry (forge/cast/anvil) |
references/foundry.md |
| Framework (alt) | Hardhat |
references/hardhat.md |
| Standards | OpenZeppelin 5.x |
references/openzeppelin.md |
| Standards | ERC-4626 (tokenized vaults) |
references/erc4626.md |
| Frontend (low-level) | Viem 2.x |
references/viem.md |
| Frontend (React) | Wagmi 2.x |
references/wagmi.md |
| Frontend (legacy) | ethers.js 6.x |
references/ethers.md |
Quick Lookup
Starting a new Foundry project: See references/foundry.md → Project Setup
Starting a Hardhat project: See references/hardhat.md → Installation
Writing an ERC-20: See references/openzeppelin.md → ERC-20
Building a yield vault (ERC-4626): See references/erc4626.md → OpenZeppelin Implementation
First depositor attack on vaults: See references/erc4626.md → First Depositor Attack
Connecting a wallet in React: See references/wagmi.md → Quick Start
Reading contract state with Viem: See references/viem.md → Read Contracts
Common Solidity errors: See references/solidity.md → Error Reference
Deploying to Optimism/Base with Hardhat: See references/hardhat.md → hardhat.config.ts
Fetch Latest Docs
INLINECODE17 pulls live docs from official sources when the reference files may be stale.
CODEBLOCK0
Gas Optimization Quick Rules
- 1. Use
calldata instead of memory for read-only function params - Pack storage variables: multiple
uint128 in one slot beats two separate INLINECODE21 - INLINECODE22 blocks for arithmetic that can't overflow (saves ~30 gas/op)
- INLINECODE23 >
constant > storage for values set once - Events are cheaper than storage for historical data
- Batch operations: one tx touching N items beats N txs
Web3 文档
当前EVM开发的模式与参考。覆盖全栈:合约 → 测试 → 部署 → 前端集成。
技术栈覆盖
| 层 | 工具 | 参考 |
|---|
| 合约 | Solidity 0.8.x | references/solidity.md |
| 框架 |
Foundry (forge/cast/anvil) | references/foundry.md |
| 框架(备选) | Hardhat | references/hardhat.md |
| 标准 | OpenZeppelin 5.x | references/openzeppelin.md |
| 标准 | ERC-4626(代币化金库) | references/erc4626.md |
| 前端(底层) | Viem 2.x | references/viem.md |
| 前端(React) | Wagmi 2.x | references/wagmi.md |
| 前端(旧版) | ethers.js 6.x | references/ethers.md |
快速查询
启动新的Foundry项目: 参见 references/foundry.md → 项目设置
启动Hardhat项目: 参见 references/hardhat.md → 安装
编写ERC-20: 参见 references/openzeppelin.md → ERC-20
构建收益金库(ERC-4626): 参见 references/erc4626.md → OpenZeppelin实现
金库的首个存款人攻击: 参见 references/erc4626.md → 首个存款人攻击
在React中连接钱包: 参见 references/wagmi.md → 快速开始
使用Viem读取合约状态: 参见 references/viem.md → 读取合约
常见Solidity错误: 参见 references/solidity.md → 错误参考
使用Hardhat部署到Optimism/Base: 参见 references/hardhat.md → hardhat.config.ts
获取最新文档
当参考文件可能过时时,scripts/fetch-docs.js 从官方来源拉取实时文档。
bash
node scripts/fetch-docs.js solidity # Solidity文档
node scripts/fetch-docs.js foundry # Foundry手册
node scripts/fetch-docs.js viem # Viem文档
node scripts/fetch-docs.js wagmi # Wagmi文档
node scripts/fetch-docs.js openzeppelin # OZ文档
node scripts/fetch-docs.js hardhat # Hardhat文档
node scripts/fetch-docs.js erc4626 # ERC-4626(OZ金库文档)
Gas优化快速规则
- 1. 对只读函数参数使用 calldata 而非 memory
- 打包存储变量:一个槽位中的多个 uint128 优于两个独立的 uint256
- 对不会溢出的算术运算使用 unchecked 块(每次操作节省约30 gas)
- 对于一次性设置的值:immutable > constant > 存储
- 对于历史数据,事件比存储更便宜
- 批量操作:一次交易处理N个项目优于N次交易