solidity-style-modern
БесплатноБез исполняемых скриптовНе проверенUse when writing or reviewing Solidity source for compiler 0.8.20 and later. Encodes modern conventions: pinned pragma, SPDX headers, custom errors over…
от idchain-world★ 19 звёзд на GitHubОб этом скилле
Modern Solidity Style (0.8.20+)
You are writing or reviewing a Solidity source file. Follow these conventions before any stylistic preference you learned elsewhere. Consistency across a codebase is worth more than any individual rule.
The Iron Laws
- NO FLOATING PRAGMA.
pragma solidity 0.8.26;— exact, pinned. Not^0.8.20, not>=0.8.20 <0.9.0. The compiler version is a deployed artifact; pin it. (Source: https://docs.soliditylang.org/en/v0.8.26/layout-of-source-files.html) - NO MISSING SPDX HEADER. The first line of every
.solfile is// SPDX-License-Identifier: <id>. Without it, solc emits a warning and you cannot tell licensed code from copied code. - NO
require(cond, "string")IN NEW CODE. Use custom errors:if (!cond) revert Unauthorized(msg.sender);. Saves gas, saves bytecode, gives you typed failure data. - NO STATE MUTATION AFTER AN EXTERNAL CALL. Checks-Effects-Interactions. Validate, update state, then call out. This is not negotiable.
- NO MISSING NATSPEC ON EXTERNAL OR PUBLIC SURFACES. Every
external/publicfunction, every custom error, every event gets at least@notice. Internal helpers can skip it; the surface cannot. - NO INLINE ASSEMBLY WITHOUT A COMMENT EXPLAINING WHY. Every
assembly { ... }block starts with a comment stating the reason (gas, layout trick, missing Solidity feature) and what invariants it preserves. No comment, no assembly. - NO
tx.originFOR AUTHORIZATION, EVER.msg.senderfor auth.tx.originis a footgun with a known CVE-scale exploit pattern. This rule has no exceptions in application code.
File layout order
Every .sol file follows this order exactly:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
// 1. Imports (named, never glob)
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
// 2. File-level custom errors (if shared across contracts in this file)
error ZeroAddress();
// 3. File-level events (rare; usually inside the contract)
// 4. Contracts, in definition order: interfaces, libraries, abstract, concrete
interface IVault { ... }
library VaultLib { ... }
contract Vault is IVault { ... }
Contract element order
Inside a contract, members appear in this order:
using ... for ...directivestypedeclarations (structs, enums)- State variables (constants first, then immutables, then mutable storage)
- Events
- Custom errors
- Modifiers
constructorreceive()if presentfallback()if present- External functions
- Public functions
- Internal functions
- Private functions
Within each function visibility group: view/pure functions after state-mutating ones. This matches the Solidity style guide.
Naming conventions
You MUST use these prefixes. A reviewer scanning the file should know what every identifier is without looking at its declaration.
| Kind | Convention | Example |
|---|---|---|
| Interface | I prefix, PascalCase |
IERC20, IVault |
| Library | PascalCase, no prefix | SafeERC20 |
| Contract | PascalCase, no prefix | Vault, StakingPool |
| Constant (file- or contract-level) | UPPER_SNAKE_CASE |
MAX_SUPPLY, BASIS_POINTS |
| Immutable state var | i_ prefix, camelCase |
i_owner, i_deployTimestamp |
| Storage state var | s_ prefix, camelCase |
s_totalSupply, s_balances |
| Storage mapping | s_ prefix |
s_balanceOf |
| Function parameter | camelCase, no prefix | recipient, amount |
| Local variable | camelCase | currentBalance |
| External / public function | camelCase | transfer, totalSupply |
| Internal / private function | _ prefix, camelCase |
_mint, _beforeTokenTransfer |
| Event | PascalCase, verb-past-tense | Transferred, OwnershipHandedOff |
| Custom error | PascalCase, usually a noun phrase | Unauthorized, InsufficientBalance |
| Modifier | camelCase | onlyOwner, whenNotPaused |
The s_ / i_ convention is not in the official style guide but has become the community default since 2023 for codebases that want storage access to be visually obvious. Adopt it unless the existing codebase clearly does not.
Custom errors
Custom errors replace require(cond, "string") in every new codebase.
DO:
error InsufficientBalance(uint256 requested, uint256 available);
error Unauthorized(address caller);
error ZeroAmount();
function withdraw(uint256 amount) external {
if (amount == 0) revert ZeroAmount();
uint256 bal = s_balances[msg.sender];
if (amount > bal) revert InsufficientBalance(amount, bal);
s_balances[msg.sender] = bal - amount;
_transfer(msg.sender, amount);
}
DON'T:
function withdraw(uint256 amount) external {
require(amount > 0, "ZERO_AMOUNT");
require(amount <= s_balances[msg.sender], "INSUFFICIENT_BALANCE");
// ...
}
Why: custom errors are ~50 bytes per call chea
Установить solidity-style-modern в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл solidity-style-modern?
Use when writing or reviewing Solidity source for compiler 0.8.20 and later. Encodes modern conventions: pinned pragma, SPDX headers, custom errors over require-strings, checks-effects-interactions, NatSpec on external surfaces, storage layout care, and naming discipline (I_ s_ i_ CONSTANT_CASE _underscoreCased). Day-to-day style, not security audit.
Как установить скилл solidity-style-modern?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл solidity-style-modern запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic