solidity-development

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Solidity Development Workflow

Solidity开发工作流

Workflow for Solidity smart contract changes in the
apps/eth-contracts/
Foundry project.
适用于
apps/eth-contracts/
Foundry项目中Solidity智能合约变更的工作流。

Prerequisites

前置要求

Use
git-workflow
Skill
for branch management, commit conventions, and PR creation.
使用
git-workflow
Skill进行分支管理、提交规范遵循和PR创建。

Applicable Directories

适用目录

PathDescription
apps/eth-contracts/contracts/
Smart contract source files
apps/eth-contracts/script/
Foundry deployment scripts
apps/eth-contracts/test/
Foundry test files (
*.t.sol
)
路径说明
apps/eth-contracts/contracts/
智能合约源文件
apps/eth-contracts/script/
Foundry部署脚本
apps/eth-contracts/test/
Foundry测试文件(
*.t.sol

Toolchain

工具链

ToolVersionRole
Foundry (
forge
)
1.6.0-nightlyCompile, test, deploy
Solidity
^0.8.34
Smart contract language
OpenZeppelin Contracts
^5.6.1
ERC-20 / standard base contracts
bunprimarynpm package manager
solhint
^6.0.3
Solidity linter
dprint
^0.52.0
JS/TS formatter
Note:
forge
is installed at
~/.foundry/bin/forge
(may not be in PATH). Run with full path or add
~/.foundry/bin
to
PATH
.
工具版本作用
Foundry (
forge
)
1.6.0-nightly编译、测试、部署
Solidity
^0.8.34
智能合约开发语言
OpenZeppelin Contracts
^5.6.1
ERC-20/标准基础合约
bun首选npm包管理器
solhint
^6.0.3
Solidity代码检查工具
dprint
^0.52.0
JS/TS格式化工具
注意
forge
安装路径为
~/.foundry/bin/forge
(可能不在PATH中),请使用完整路径执行,或将
~/.foundry/bin
添加到
PATH

Setup (first time)

首次环境配置

bash
cd apps/eth-contracts
bash
cd apps/eth-contracts

1. 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
undefined
bun install
undefined

Verification 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 --broadcast
bash
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 (
    import {Foo} from "..."
    ) — no global imports
  • NatSpec tags present (
    @title
    ,
    @author
    ,
    @notice
    ,
    @param
    ) on contracts and public functions
  • 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
  • .env
    added to
    .gitignore
  • Access control properly implemented
  • Integer overflow protection (Solidity ≥0.8 has built-in checks)
  • 无重入漏洞
  • 无硬编码私钥或敏感值——使用环境变量
  • .env
    已添加到
    .gitignore
  • 访问控制已正确实现
  • 整数溢出防护(Solidity ≥0.8内置相关检查)

Testing

测试

  • Foundry test file (
    test/*.t.sol
    ) covers all acceptance criteria
  • forge test
    passes with zero failures
  • bun run lint
    exits 0 with zero solhint errors
  • Foundry测试文件(
    test/*.t.sol
    )覆盖所有验收标准
  • forge test
    运行通过,无失败用例
  • bun run lint
    返回退出码0,无solhint错误

ABI / Go Bindings

ABI / Go绑定

After contract changes, if Go bindings are needed:
bash
undefined
合约变更后如果需要Go绑定:
bash
undefined

1. 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
undefined
make gen-abi
undefined

Related Chain Context

相关链上下文

  • ETH (Ethereum)
  • ERC-20 token standard
  • Local nodes:
    anvil
    ,
    geth
    at
    http://localhost:8545
  • ETH(以太坊)
  • ERC-20代币标准
  • 本地节点:运行在
    http://localhost:8545
    anvil
    geth

Related Skills

相关技能

  • git-workflow
    - Branch, commit, PR workflow
  • github-issue-creation
    - Task classification
  • git-workflow
    - 分支、提交、PR工作流
  • github-issue-creation
    - 任务分类