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_oficrc1_feeicrc1_total_supplyicrc1_transfericrc2_allowanceicrc2_transfer_from
Public API
Types
Account-{ owner : Principal; subaccount : ?Blob }.AllowanceArgs- Arguments foricrc2_allowance.AllowanceResult- Returned allowance amount and optional expiration.TransferArg- Arguments foricrc1_transfer.TransferResult-#Ok(transaction_index)or an ICRC-1 transfer error.TransferFromArgs- Arguments foricrc2_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 typedLedgeractor 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.Ledgeras the shared interface type for external ICRC ledgers. - Use
ICRCLedger.fromPrincipalwhen a client stores or receives a ledger canisterPrincipal. - The actor interface is intentionally narrow: it includes only the six client-facing ICRC methods listed above.