Skip to main content

pattern/ICRCLedger

Reference for mo:core/pattern/ICRCLedger in the core library.

Import

mo:core/pattern/ICRCLedger

Status

  • Runtime interface pattern module
  • Provides a typed actor interface for ICRC-1 and ICRC-2 ledger calls used by Sector9 clients

Purpose

ICRCLedger standardizes the ledger actor surface that client canisters use when they need to call an external ICRC ledger and build proofs around those calls. It intentionally exposes only the minimal ICRC-1 and ICRC-2 methods used by clients:

  • icrc1_balance_of
  • icrc1_fee
  • icrc1_total_supply
  • icrc1_transfer
  • icrc2_allowance
  • icrc2_transfer_from

Public API

Types

  • Account - { owner : Principal; subaccount : ?Blob }.
  • AllowanceArgs - Arguments for icrc2_allowance.
  • AllowanceResult - Returned allowance amount and optional expiration.
  • TransferArg - Arguments for icrc1_transfer.
  • TransferResult - #Ok(transaction_index) or an ICRC-1 transfer error.
  • TransferFromArgs - Arguments for icrc2_transfer_from.
  • TransferFromResult - #Ok(transaction_index) or an ICRC-2 transfer-from error.
  • Ledger - Actor interface containing the supported ICRC methods.

Pure Functions

  • fromPrincipal(ledgerPrincipal : Principal) : Ledger - Converts a ledger canister principal into the typed Ledger actor reference.

Usage

import ICRCLedger "mo:core/pattern/ICRCLedger";

let ledger = ICRCLedger.fromPrincipal(ledgerPrincipal);
let balance = await ledger.icrc1_balance_of({
owner = owner;
subaccount = null
});

Summary

  • Use ICRCLedger.Ledger as the shared interface type for external ICRC ledgers.
  • Use ICRCLedger.fromPrincipal when a client stores or receives a ledger canister Principal.
  • The actor interface is intentionally narrow: it includes only the six client-facing ICRC methods listed above.