UNPKG

@dfinity/ledger-icrc

Version:

A library for interfacing with ICRC ledgers on the Internet Computer.

90 lines (89 loc) 4.98 kB
import type { QueryParams } from "@dfinity/utils"; import { Canister } from "@dfinity/utils"; import type { Allowance, BlockIndex, GetBlocksResult, _SERVICE as IcrcLedgerService, Tokens, icrc21_consent_info } from "../candid/icrc_ledger"; import type { IcrcLedgerCanisterOptions } from "./types/canister.options"; import type { AllowanceParams, ApproveParams, BalanceParams, GetBlocksParams, Icrc21ConsentMessageParams, TransferFromParams, TransferParams } from "./types/ledger.params"; import type { IcrcTokenMetadataResponse } from "./types/ledger.responses"; export declare class IcrcLedgerCanister extends Canister<IcrcLedgerService> { static create(options: IcrcLedgerCanisterOptions<IcrcLedgerService>): IcrcLedgerCanister; /** * The token metadata (name, symbol, etc.). */ metadata: (params: QueryParams) => Promise<IcrcTokenMetadataResponse>; /** * The ledger transaction fees. * * @returns {Tokens} The ledger transaction fees in Tokens */ transactionFee: (params: QueryParams) => Promise<Tokens>; /** * Returns the balance for a given account provided as owner and with optional subaccount. * * @param {BalanceParams} params The parameters to get the balance of an account. * @returns {Promise<Tokens>} The balance of the given account. */ balance: (params: BalanceParams) => Promise<Tokens>; /** * Transfers tokens from the sender to the given account. * * @param {TransferArg} params The parameters to transfer tokens. * * @throws {IcrcTransferError} If the transfer fails. */ transfer: (params: TransferParams) => Promise<BlockIndex>; /** * Returns the total supply of tokens. */ totalTokensSupply: (params: QueryParams) => Promise<Tokens>; /** * Transfers a token amount from the `from` account to the `to` account using the allowance of the spender's account (`SpenderAccount = { owner = caller; subaccount = spender_subaccount }`). The ledger draws the fees from the `from` account. * * Reference: https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-2/README.md#icrc2_transfer_from * * @param {TransferFromParams} params The parameters to transfer tokens from to. * * @throws {IcrcTransferError} If the transfer from fails. */ transferFrom: (params: TransferFromParams) => Promise<BlockIndex>; /** * This method entitles the `spender` to transfer token `amount` on behalf of the caller from account `{ owner = caller; subaccount = from_subaccount }`. * * Reference: https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-2/README.md#icrc2_approve * * @param {ApproveParams} params The parameters to approve. * * @throws {IcrcTransferError} If the approval fails. */ approve: (params: ApproveParams) => Promise<BlockIndex>; /** * Returns the token allowance that the `spender` account can transfer from the specified `account`, and the expiration time for that allowance, if any. * * Reference: https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-2/README.md#icrc2_allowance * * @param {AllowanceParams} params The parameters to call the allowance. * * @returns {Allowance} The token allowance. If there is no active approval, the ledger MUST return `{ allowance = 0; expires_at = null }`. */ allowance: (params: AllowanceParams) => Promise<Allowance>; /** * Fetches the consent message for a specified canister call, intended to provide a human-readable message that helps users make informed decisions. * * @link: https://github.com/dfinity/wg-identity-authentication/blob/main/topics/ICRC-21/icrc_21_consent_msg.md * * @param {Icrc21ConsentMessageParams} params - The request parameters containing the method name, arguments, and consent preferences (e.g., language). * @returns {Promise<icrc21_consent_info>} - A promise that resolves to the consent message response, which includes the consent message in the specified language and other related information. * * @throws {InsufficientPaymentError} - This error is reserved for future use, in case payment extensions are introduced. For example, if consent messages, which are currently free, begin to require payments. * @throws {UnsupportedCanisterCallError} - If the specified canister call is not supported. * @throws {ConsentMessageUnavailableError} - If there is no consent message available. * @throws {GenericError} - For any other generic errors. */ consentMessage: (params: Icrc21ConsentMessageParams) => Promise<icrc21_consent_info>; /** * Fetches the blocks information from the ledger canister, * * @param {GetBlocksParams} params The parameters to get the blocks. * @returns {Promise<GetBlocksResult>} The list of blocks. */ getBlocks: (params: GetBlocksParams) => Promise<GetBlocksResult>; }