writing-motoko
БесплатноБез исполняемых скриптовНе проверенMotoko language pitfalls, modern syntax, and architecture patterns for the Internet Computer. Covers persistent actors, stable types, mo:core standard…
от 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:
stablekeyword -- Not needed in enhanced orthogonal persistence modemo:baselibrary -- Deprecated. Usemo:coreinsteadmo:json(thejsonpackage) or any JSON library other thanjayson-- Usejayson(see JSON).vals()-- The deprecatedmo:baseiterator name. Always.values(). On arrays.vals()still compiles with deprecation warning M0269 (from moc 1.16); on core collections it fails with M0072system func preupgrade/postupgrade-- Not needed with enhanced orthogonal persistence(with migration = ...)actor-attached migration syntax -- Use the mops-managed migration chain inmigrations/- Inline initializers on stable actor fields -- Initial values come from the migration chain (see
migrating-motoko-actors) - Module function style for
selfparameters -- Don't writeList.add(list, item)orMap.get(map, key) - Manual field-by-field record copying for immutable records -- Use record spread (
{ self with ... }). For records withvarfields, do not use record spread; mutate thevarfield 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
mixinblock -- a barelet/varis 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.
queryandlabelare 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
funcpassed as a call argument -- writexs.filter(func x = x > 1), notxs.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:corelibrary version 2.6.0+ (compilermoc1.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 implicitcompareis resolved from the imported module (import Nat "mo:core/Nat"for aMap.Map<Nat, _>), never from the type alone (unless the project compiles with--implicit-package=core, which resolvesmo:coremodules such asNatandTextwithout 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 nocomparein its own module, or a key type from a package other thancore(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-armswitchon?T(requiresmoc >= 1.7.0) - Plain
break/continueto exit or skip a loop iteration -- they work insidefor,while, andloopjust like in other languages - Enhanced orthogonal persistence (state persists without
stablekeyword) - 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:coreAPI 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
Установить writing-motoko в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
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), без исполняемых скриптов.
Похожие скиллы
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