solidity-development
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSolidity Development Workflow
Solidity开发工作流
Workflow for Solidity smart contract changes in the Foundry project.
apps/eth-contracts/适用于 Foundry项目中Solidity智能合约变更的工作流。
apps/eth-contracts/Prerequisites
前置要求
Use Skill for branch management, commit conventions, and PR creation.
git-workflow使用 Skill进行分支管理、提交规范遵循和PR创建。
git-workflowApplicable Directories
适用目录
| Path | Description |
|---|---|
| Smart contract source files |
| Foundry deployment scripts |
| Foundry test files ( |
| 路径 | 说明 |
|---|---|
| 智能合约源文件 |
| Foundry部署脚本 |
| Foundry测试文件( |
Toolchain
工具链
| Tool | Version | Role |
|---|---|---|
Foundry ( | 1.6.0-nightly | Compile, test, deploy |
| Solidity | | Smart contract language |
| OpenZeppelin Contracts | | ERC-20 / standard base contracts |
| bun | primary | npm package manager |
| solhint | | Solidity linter |
| dprint | | JS/TS formatter |
Note:is installed atforge(may not be in PATH). Run with full path or add~/.foundry/bin/forgeto~/.foundry/bin.PATH
| 工具 | 版本 | 作用 |
|---|---|---|
Foundry ( | 1.6.0-nightly | 编译、测试、部署 |
| Solidity | | 智能合约开发语言 |
| OpenZeppelin Contracts | | ERC-20/标准基础合约 |
| bun | 首选 | npm包管理器 |
| solhint | | Solidity代码检查工具 |
| dprint | | JS/TS格式化工具 |
注意:安装路径为forge(可能不在PATH中),请使用完整路径执行,或将~/.foundry/bin/forge添加到~/.foundry/bin。PATH
Setup (first time)
首次环境配置
bash
cd apps/eth-contractsbash
cd apps/eth-contracts1. Install forge-std (Foundry testing/scripting library)
1. 安装forge-std(Foundry测试/脚本库)
forge install foundry-rs/forge-std
forge install foundry-rs/forge-std
2. Install npm dependencies (@openzeppelin/contracts, solhint, dprint)
2. 安装npm依赖(@openzeppelin/contracts、solhint、dprint)
bun install
undefinedbun install
undefinedVerification Commands
校验命令
bash
cd apps/eth-contracts
forge build # Compile all contracts (artifacts → out/)
forge test -v # Run Foundry unit tests
bun run lint # Solidity lint via solhint (must exit 0, zero errors)
bun run fmt # Format JS/TS files via dprint (must exit 0)bash
cd apps/eth-contracts
forge build # 编译所有合约(产物输出到out/目录)
forge test -v # 运行Foundry单元测试
bun run lint # 通过solhint执行Solidity代码检查(必须返回退出码0,无错误)
bun run fmt # 通过dprint格式化JS/TS文件(必须返回退出码0)Deployment (local)
本地部署
bash
cd apps/eth-contracts
export PRIVATE_KEY=0x<deployer-private-key>
forge script script/DeployHYC.s.sol --rpc-url http://localhost:8545 --broadcastbash
cd apps/eth-contracts
export PRIVATE_KEY=0x<部署账户私钥>
forge script script/DeployHYC.s.sol --rpc-url http://localhost:8545 --broadcast→ outputs contract address, tx hash, gas usage
输出合约地址、交易哈希、Gas消耗量
Compatible with both `anvil` and `geth` nodes at `http://localhost:8545`.
兼容运行在`http://localhost:8545`的`anvil`和`geth`节点。Self-Review Checklist
自评检查清单
Code Quality
代码质量
- Named imports used () — no global imports
import {Foo} from "..." - NatSpec tags present (,
@title,@author,@notice) on contracts and public functions@param - Explicit visibility on all functions (constructors exempt in Solidity ≥0.8)
- Gas optimization considered
- Events emitted for state changes
- 使用命名导入()——禁止全局导入
import {Foo} from "..." - 合约和公共函数上带有NatSpec标签(、
@title、@author、@notice)@param - 所有函数都有显式可见性声明(Solidity ≥0.8版本的构造函数除外)
- 已考虑Gas优化
- 状态变更时会触发对应事件
Security
安全
- No reentrancy vulnerabilities
- No hardcoded private keys or sensitive values — use env vars
- added to
.env.gitignore - Access control properly implemented
- Integer overflow protection (Solidity ≥0.8 has built-in checks)
- 无重入漏洞
- 无硬编码私钥或敏感值——使用环境变量
- 已添加到
.env.gitignore - 访问控制已正确实现
- 整数溢出防护(Solidity ≥0.8内置相关检查)
Testing
测试
- Foundry test file () covers all acceptance criteria
test/*.t.sol - passes with zero failures
forge test - exits 0 with zero solhint errors
bun run lint
- Foundry测试文件()覆盖所有验收标准
test/*.t.sol - 运行通过,无失败用例
forge test - 返回退出码0,无solhint错误
bun run lint
ABI / Go Bindings
ABI / Go绑定
After contract changes, if Go bindings are needed:
bash
undefined合约变更后如果需要Go绑定:
bash
undefined1. Compile
1. 编译
cd apps/eth-contracts
forge build
cd apps/eth-contracts
forge build
2. Regenerate Go bindings (if target ABI changed)
2. 重新生成Go绑定(如果目标ABI发生变更)
make gen-abi
undefinedmake gen-abi
undefinedRelated Chain Context
相关链上下文
- ETH (Ethereum)
- ERC-20 token standard
- Local nodes: ,
anvilatgethhttp://localhost:8545
- ETH(以太坊)
- ERC-20代币标准
- 本地节点:运行在的
http://localhost:8545、anvilgeth
Related Skills
相关技能
- - Branch, commit, PR workflow
git-workflow - - Task classification
github-issue-creation
- - 分支、提交、PR工作流
git-workflow - - 任务分类
github-issue-creation