# solidity-gas-optimization

A skill packing 80+ Solidity gas optimization techniques from the RareSkills book. Useful when writing, reviewing or auditing contracts.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 547 installs · ★ 4
- Author: pseudoyu
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/pseudoyu/agent-skills/tree/HEAD/skills/solidity-gas-optimization/SKILL.md
- Updated: 2026-05-19
- HTML: https://affpapa.org/en/nevibecode/skills/solidity-gas-optimization

## What it does

The skill hands your agent a rule set for saving gas in Solidity, split into 8 categories and ordered by impact and risk. Storage work sits at the top: skip zero-to-one writes, pack variables into fewer slots, cache storage reads, move values into constants and immutables. Below that come deployment, calldata, design patterns, cross-contract calls, compiler flags and assembly tricks.

Inside you get a priority table, short bad/good code samples, and pointers to `references/solidity-gas-guidelines.md` plus a `references/rules/` folder with individual patterns per category. Lookup is plain `grep` over those rule files, by storage or assembly or struct.

Some techniques are flagged as unsafe for production: making every function payable, ignoring the return value of `send()`, branching on `gasleft()`. There is also a section on advice that no longer holds — the claim that `external` beats `public` is one of them. The skill tells you to benchmark both versions, since compiler behavior shifts with version and context, and `--via-ir` can make some tricks pointless.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add pseudoyu/agent-skills --skill solidity-gas-optimization -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/solidity-gas-optimization/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/solidity-gas-optimization/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add pseudoyu/agent-skills --skill solidity-gas-optimization -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/solidity-gas-optimization/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add pseudoyu/agent-skills --skill solidity-gas-optimization -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/solidity-gas-optimization/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install pseudoyu/agent-skills solidity-gas-optimization
```

2. **Manually: put the files in place**
- File: `.github/skills/solidity-gas-optimization/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add pseudoyu/agent-skills --skill solidity-gas-optimization -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/pseudoyu/agent-skills --path skills/solidity-gas-optimization
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/solidity-gas-optimization/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add pseudoyu/agent-skills --skill solidity-gas-optimization -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/pseudoyu/agent-skills/tree/HEAD/skills/solidity-gas-optimization/SKILL.md

## When to use it
- lower the deployment cost of a contract
- pack struct fields into fewer storage slots
- swap string revert messages for custom errors
- pick between ERC721 and ERC1155 for an NFT collection
- spot outdated gas advice in an existing contract

## Example prompts
- Review this contract for gas savings and show what can be packed in storage
- Rewrite the loop in `processBatch` following the gas optimization rules
- Compare ERC721 and ERC1155 gas costs for this collection

## Similar
- [solidity](https://affpapa.org/en/nevibecode/skills/solidity.md) — skill · 721 installs
- [solidity-security](https://affpapa.org/en/nevibecode/skills/solidity-security.md) — skill · 15382 installs
- [solidity-auditor](https://affpapa.org/en/nevibecode/skills/solidity-auditor.md) — skill · 830 installs
- [upgrade-solidity-contracts](https://affpapa.org/en/nevibecode/skills/upgrade-solidity-contracts.md) — skill · 472 installs
- [solidity-hardhat-cursorrules-prompt-file](https://affpapa.org/en/nevibecode/rules/solidity-hardhat-cursorrules-prompt-file.md) — rule · ★ 41011
- [use-arc](https://affpapa.org/en/nevibecode/skills/use-arc.md) — skill · 1000 installs

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
