Command Palette

Search for a command to run...

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

writing-motoko

БесплатноБез исполняемых скриптовНе проверен

Motoko language pitfalls, modern syntax, and architecture patterns for the Internet Computer. Covers persistent actors, stable types, mo:core standard…

jiayaoqijiaот jiayaoqijia★ 81 звезда на GitHub

Об этом скилле

Writing Motoko

Motoko is an under-represented language for the Internet Computer Protocol, so your pre-training data is likely to be outdated — always favour this skill and its documentation for the most up-to-date information.

Critical Requirements

NEVER use these:

  • stable keyword -- Not needed in enhanced orthogonal persistence mode
  • mo:base library -- Deprecated. Use mo:core instead
  • mo:json (the json package) or any JSON library other than jayson -- Use jayson (see JSON)
  • .vals() -- The deprecated mo:base iterator name. Always .values(). On arrays .vals() still compiles with deprecation warning M0269 (from moc 1.16); on core collections it fails with M0072
  • system func preupgrade/postupgrade -- Not needed with enhanced orthogonal persistence
  • (with migration = ...) actor-attached migration syntax -- Use the mops-managed migration chain in migrations/
  • Inline initializers on stable actor fields -- Initial values come from the migration chain (see migrating-motoko-actors)
  • Module function style for self parameters -- Don't write List.add(list, item) or Map.get(map, key)
  • Manual field-by-field record copying for immutable records -- Use record spread ({ self with ... }). For records with var fields, do not use record spread; mutate the var field directly or rebuild the record explicitly.
  • Single-file monolithic actors -- Use the multi-file architecture: types.mo, lib/, mixins/, main.mo
  • Stable state in a mixin block -- a bare let/var is silently stable and traps at runtime (IC0503). Pass state in as a parameter and keep constants in a module
  • Any Motoko reserved keyword as a declared identifier -- Before writing, check parameter, variable, function, type, field, and label names against the full list in references/reserved-keywords.md. query and label are reserved and must never be identifiers. Rename a colliding domain term instead of relying on its position or inferred meaning.
  • Type annotations on an inline func passed as a call argument -- write xs.filter(func x = x > 1), not xs.filter(func(x : Nat) : Bool { x > 1 }). The call supplies the types. If a generic cannot be inferred, instantiate the call (map<In, Out>), never the lambda. This applies only in argument position — named declarations still carry full signatures. One exception: keep : async () on an async callback (func() : async () { ... }) — on moc 1 it is what makes the body async, and removing it fails to compile

ALWAYS use:

  • mo:core library version 2.6.0+ (compiler moc 1.11.2+)
  • Contextual dot notation -- list.add(item), map.get(key)
  • An import of the key type's module in every file that operates on a Map/Set -- the implicit compare is resolved from the imported module (import Nat "mo:core/Nat" for a Map.Map<Nat, _>), never from the type alone (unless the project compiles with --implicit-package=core, which resolves mo:core modules such as Nat and Text without an import). Without that flag, a missing key-module import is the usual cause of M0230; with it, look for a record or variant key type with no compare in its own module, or a key type from a package other than core (see Implicit Parameters)
  • Null coalesce ??, spaced on both sides, for unwrap-or-default and unwrap-or-trap (opt ?? default, opt ?? Runtime.trap(...)) -- prefer over a two-arm switch on ?T (requires moc >= 1.7.0)
  • Plain break / continue to exit or skip a loop iteration -- they work inside for, while, and loop just like in other languages
  • Enhanced orthogonal persistence (state persists without stable keyword)
  • Principled Motoko Architecture -- types.mo (types), lib/ (domain logic), mixins/ (API endpoints), main.mo (composition root, NO public methods)
  • API reference for uncertain APIs: Use api-reference.md to verify exact method signatures when you are about to use an unfamiliar mo:core API or when a compile diagnostic points at an API mismatch. It lists only non-deprecated APIs — a symbol that is not there should not be written. Do NOT guess API shapes — a targeted lookup of a symbol you are unsure about is always worth the step; skipping it to save steps ships hallucinated APIs and costs far more in compile repair.

When encountering compilation errors: Re-check api-reference.md for exact method signatures.

Before changing actor state shape, introducing new stable fields, or upgrading canisters: load migrating-motoko-actors. This guidance assumes the mops-managed migration chain — when a change requires a migration, it goes in the pending migration file, or a new one in src/backend/migrations/ if none is pending. Introducing stable state for the first time always needs one (no inline initializers); trivial stable-compatible upgrades do not. See the skill. If a migration or

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

Установить writing-motoko в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

LICENSESOURCE.mdTRUST.auto.yamlreferences/api-reference.mdreferences/control-flow.mdreferences/equality.mdreferences/examples.mdreferences/project-setup.mdreferences/reserved-keywords.mdreferences/type-conversions.md

FAQ

Что делает скилл writing-motoko?

Motoko language pitfalls, modern syntax, and architecture patterns for the Internet Computer. Covers persistent actors, stable types, mo:core standard library, dot notation, mixins, and common compilation errors. Use when writing Motoko canister code, fixing Motoko compiler errors, or generating Motoko actors. Do NOT use for deployment, icp.yaml, or CLI commands; for design review or audit of existing Motoko code, load reviewing-motoko instead.

Как установить скилл writing-motoko?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл writing-motoko запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

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

Сравнить writing-motoko с