Analyze and optimize gas consumption in Solidity smart contracts using proven patterns and best practices.
Analyze and optimize gas consumption in Solidity smart contracts using proven patterns and best practices.
Use this skill when the user:
bytes32 over string when possible for fixed-length datacalldata instead of memory for read-only function parametersrequire chainsunchecked blocks for arithmetic that cannot overflow (Solidity 0.8+)immutable and constant for values set once at deploy timeuint256 len = arr.length++i instead of i++ to save ~5 gas per iteration// Before: ~45,000 gas
function sum(uint256[] memory values) public pure returns (uint256 total) {
for (uint256 i = 0; i < values.length; i++) {
total += values[i];
}
}
// After: ~38,000 gas
function sum(uint256[] calldata values) public pure returns (uint256 total) {
uint256 len = values.length;
for (uint256 i; i < len; ) {
unchecked {
total += values[i];
++i;
}
}
}
npx skills add ZhouXiaoHong/Solidity Gas 优化器下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer
Tags:solidity, gas-optimization, smart-contracts, evm