solidity

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Solidity

Solidity

Solidity is the primary language for the Ethereum Virtual Machine (EVM). v0.8.28 (2025) focuses on transient storage (
tstore
) and gas optimization via IR.
Solidity是**以太坊虚拟机(EVM)**的主要编程语言。2025年发布的v0.8.28版本重点关注临时存储(
tstore
)和通过IR实现的Gas优化。

When to Use

适用场景

  • Ethereum/L2s: Developing for Optimism, Arbitrum, Base.
  • DeFi: Writing logic for tokens, AMMs, and lending.
  • NFTs: ERC-721 and ERC-1155 contracts.
  • 以太坊/二层网络(L2s):为Optimism、Arbitrum、Base等网络进行开发。
  • 去中心化金融(DeFi):编写代币、自动做市商(AMMs)及借贷相关逻辑。
  • 非同质化代币(NFTs):开发ERC-721和ERC-1155标准合约。

Core Concepts

核心概念

Gas

Gas

Every operation costs ETH. Optimization is critical.
每一项操作都需要消耗ETH,优化至关重要。

Modifiers

修饰器(Modifiers)

Reusable checks.
modifier onlyOwner { ... }
.
可复用的检查逻辑,例如
modifier onlyOwner { ... }

Events

事件(Events)

Logging on the blockchain.
emit Transfer(from, to, value)
.
在区块链上记录日志,例如
emit Transfer(from, to, value)

Best Practices (2025)

2025年最佳实践

Do:
  • Use Foundry: The 2025 standard for testing (Solidity-based tests).
  • Use Custom Errors:
    error InsufficientBalance();
    is cheaper than string requires.
  • Use OpenZeppelin: Don't roll your own crypto/auth logic.
Don't:
  • Don't ignore reentrancy: Use
    ReentrancyGuard
    or Checks-Effects-Interactions pattern.
建议
  • 使用Foundry:2025年的测试标准(基于Solidity的测试框架)。
  • 使用自定义错误
    error InsufficientBalance();
    比字符串类型的require语句成本更低。
  • 使用OpenZeppelin:不要自行编写加密或授权逻辑。
禁忌
  • 不要忽略重入攻击:使用
    ReentrancyGuard
    或检查-效果-交互模式。

References

参考资料