Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

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от 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

  1. 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)
  2. NO MISSING SPDX HEADER. The first line of every .sol file is // SPDX-License-Identifier: <id>. Without it, solc emits a warning and you cannot tell licensed code from copied code.
  3. 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.
  4. NO STATE MUTATION AFTER AN EXTERNAL CALL. Checks-Effects-Interactions. Validate, update state, then call out. This is not negotiable.
  5. NO MISSING NATSPEC ON EXTERNAL OR PUBLIC SURFACES. Every external / public function, every custom error, every event gets at least @notice. Internal helpers can skip it; the surface cannot.
  6. 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.
  7. NO tx.origin FOR AUTHORIZATION, EVER. msg.sender for auth. tx.origin is 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:

  1. using ... for ... directives
  2. type declarations (structs, enums)
  3. State variables (constants first, then immutables, then mutable storage)
  4. Events
  5. Custom errors
  6. Modifiers
  7. constructor
  8. receive() if present
  9. fallback() if present
  10. External functions
  11. Public functions
  12. Internal functions
  13. 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

Полный SKILL.md на GitHub

Установить 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), без исполняемых скриптов.

Похожие скиллы

Сравнить solidity-style-modern с