icrc-ledger
БесплатноБез исполняемых скриптовНе проверенDeploy and interact with ICRC-1/ICRC-2 token ledgers (ICP, ckBTC, ckETH). Covers transfers, balances, approve/transferFrom allowances, fee handling, and…
от jiayaoqijia★ 81 звезда на GitHubОб этом скилле
ICRC Ledger Standards
What This Is
ICRC-1 is the fungible token standard on Internet Computer, defining transfer, balance, and metadata interfaces. ICRC-2 extends it with approve/transferFrom (allowance) mechanics, enabling third-party spending like ERC-20 on Ethereum.
Prerequisites
- For Motoko: mops with
core = "2.3.1"in mops.toml - For Rust:
ic-cdk = "0.19",candid = "0.10",icrc-ledger-types = "0.1"in Cargo.toml
Canister IDs
| Token | Ledger Canister ID | Decimals |
|---|---|---|
| ICP | ryjl3-tyaaa-aaaaa-aaaba-cai |
8 |
| ckBTC | mxzaz-hqaaa-aaaar-qaada-cai |
8 |
| ckETH | ss2fx-dyaaa-aaaar-qacoq-cai |
18 |
Index canisters (for transaction history):
- ICP Index:
qhbym-qaaaa-aaaaa-aaafq-cai - ckBTC Index:
n5wcd-faaaa-aaaar-qaaea-cai - ckETH Index:
s3zol-vqaaa-aaaar-qacpa-cai
All ICRC-1 ledgers expose icrc1_fee : () -> (nat) query to return the current transfer fee. Fees are denominated in the token's smallest unit (e8s for ICP where 1 ICP = 10⁸ e8s, satoshis for ckBTC, wei for ckETH). Each ledger sets its own fee, and fees can change at runtime.
Common Pitfalls
Assuming all ledgers share the same fee -- Each ledger sets its own fee (e.g., ICP = 10000 e8s, ckBTC = 10 satoshis). Never copy a fee value from one ledger and use it for another. Look up the fee via
icrc1_fee(on-chain query oricp canister call <ledger> icrc1_fee '()'via CLI). Fees can also change at runtime, so always handleBadFee { expected_fee }— the ledger tells you the correct fee in the error response.Forgetting approve before transferFrom -- ICRC-2 transferFrom will reject with
InsufficientAllowanceif the token owner has not calledicrc2_approvefirst. This is a two-step flow: owner approves, then spender calls transferFrom.Not handling Err variants --
icrc1_transferreturnsResult<Nat, TransferError>, not justNat. The error variants are:BadFee,BadBurn,InsufficientFunds,TooOld,CreatedInFuture,Duplicate,TemporarilyUnavailable,GenericError. You must match on every variant or at minimum propagate the error.Using wrong Account format -- An ICRC-1 Account is
{ owner: Principal; subaccount: ?Blob }, NOT just a Principal. The subaccount is a 32-byte blob. Passing null/None for subaccount uses the default subaccount (all zeros).Omitting created_at_time -- Without
created_at_time, you lose deduplication protection. Two identical transfers submitted within 24h will both execute. Setcreated_at_timetoTime.now()(Motoko) oric_cdk::api::time()(Rust) for dedup.Hardcoding canister IDs as text -- Always use
Principal.fromText("ryjl3-tyaaa-aaaaa-aaaba-cai")(Motoko) orPrincipal::from_text("ryjl3-tyaaa-aaaaa-aaaba-cai")(Rust). Never pass raw strings where a Principal is expected.Calling ledger from frontend -- ICRC-1 transfers should originate from a backend canister, not directly from the frontend. Frontend-initiated transfers expose the user to reentrancy and can bypass business logic. Use a backend canister as the intermediary.
Shell substitution in
--argument-file/init_args.path-- Expressions like$(icp identity principal)do NOT expand inside files referenced byinit_args: { path: ... }or--argument-file. The file is read as literal text. Either use--argumenton the command line (where the shell expands variables), or pre-generate the file withenvsubst/sedbefore deploying.Minting account cannot call
icrc2_approve-- If the ledger'sminting_accountandinitial_balancesuse the same principal, that principal cannot callicrc2_approve— the ledger traps with "the minting account cannot delegate mints." Always use a separate principal forminting_accountand different ones forinitial_balances. In production, the minting account is typically a dedicated minter canister (e.g., the ckBTC minter); for local development, any principal that differs from your funded accounts works.Transfers to/from the minting account have zero fee -- A transfer TO the minting account is a burn, and a transfer FROM the minting account is a mint. Both require
fee = null(orfee = ?0). Passing the regular transfer fee (e.g.,fee = ?10000for ICP) will fail withBadFee { expected_fee = 0 }. The error message gives no indication that burn/mint semantics are involved — it just says the expected fee is 0.
Implementation
Motoko
Imports and Types
import Principal "mo:core/Principal";
import Nat "mo:core/Nat";
import Nat8 "mo:core/Nat8";
import Nat64 "mo:core/Nat64";
import Blob "mo:core/Blob";
import Time "mo:core/Time";
import Int "mo:core/Int";
import Runtime "mo:core/Runtime";
Define the ICRC-1 Actor Interface
persistent actor {
type Account = {
owner : Principal;
subaccount : ?Blob;
};
type TransferArg = {
from_subaccount : ?Blob;
Установить icrc-ledger в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл icrc-ledger?
Deploy and interact with ICRC-1/ICRC-2 token ledgers (ICP, ckBTC, ckETH). Covers transfers, balances, approve/transferFrom allowances, fee handling, and ledger deployment. Use when working with ICP transfers, token transfers, balances, ICRC-1, ICRC-2, approve, allowance, or any fungible token on IC. Do NOT use for ckBTC minting or BTC deposit/withdrawal flows — use ckbtc instead.
Как установить скилл icrc-ledger?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл icrc-ledger запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
ci-review
The scan that the plugin's GitHub Action runs.
от Anthropicazure-static-web-apps
Helps create, configure, and deploy Azure Static Web Apps using the SWA CLI. Use when deploying static sites to Azure, setting up SWA local development…
от GitHubai-ready
Make any repo AI-ready — analyzes your codebase and generates AGENTS.md, copilot-instructions.md, CI workflows, issue templates, and more. Mines your PR…
от GitHubaws-cdk-python-setup
Setup and initialization guide for developing AWS CDK (Cloud Development Kit) applications in Python. This skill enables users to configure environment…
от GitHub