@dfinity/ledger-icp
Version:
A library for interfacing with the ICP ledger on the Internet Computer.
75 lines (74 loc) • 4.6 kB
TypeScript
import { Canister, type QueryParams } from "@dfinity/utils";
import type { Icrc1BlockIndex, _SERVICE as LedgerService, Value, icrc21_consent_info } from "../candid/ledger";
import type { BlockHeight } from "./types/common";
import type { LedgerCanisterOptions } from "./types/ledger.options";
import type { AccountBalanceParams } from "./types/ledger.params";
import type { Icrc1TransferRequest, Icrc21ConsentMessageRequest, Icrc2ApproveRequest, TransferRequest } from "./types/ledger_converters";
export declare class LedgerCanister extends Canister<LedgerService> {
static create(options?: LedgerCanisterOptions): LedgerCanister;
/**
* Returns the balance of the specified account identifier.
*
* If `certified` is true, the request is fetched as an update call, otherwise
* it is fetched using a query call.
*
* @param {AccountBalanceParams} params The parameters to get the balance of an account.
* @param {AccountIdentifierParam} params.accountIdentifier The account identifier provided either as hex string or as an AccountIdentifier.
* @param {boolean} params.certified query or update call.
* @returns {Promise<bigint>} The balance of the given account.
* @throws {@link Error}
*/
accountBalance: ({ accountIdentifier: accountIdentifierParam, certified, }: AccountBalanceParams) => Promise<bigint>;
/**
* Fetches the ledger metadata.
*
* @param {QueryParams} params - The parameters used to fetch the metadata, notably query or certified call.
* @returns {Promise<Array<[string, Value]>>} The metadata of the ICP ledger. A promise that resolves to an array of metadata entries, where each entry is a tuple consisting of a string and a value.
*/
metadata: (params: QueryParams) => Promise<Array<[string, Value]>>;
/**
* Returns the transaction fee of the ICP ledger canister.
*
* @param {QueryParams} [params={certified: false}] - Optional query parameters for the request, defaulting to `{ certified: false }` for backwards compatibility reason.
* @returns {Promise<bigint>} A promise that resolves to the transaction fee as a bigint.
*/
transactionFee: (params?: QueryParams) => Promise<bigint>;
/**
* Transfer ICP from the caller to the destination `accountIdentifier`.
* Returns the index of the block containing the tx if it was successful.
*
* @throws {@link TransferError}
*/
transfer: (request: TransferRequest) => Promise<BlockHeight>;
/**
* Transfer ICP from the caller to the destination `Account`.
* Returns the index of the block containing the tx if it was successful.
*
* @throws {@link TransferError}
*/
icrc1Transfer: (request: Icrc1TransferRequest) => Promise<BlockHeight>;
/**
* 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 {Icrc2ApproveRequest} params - The parameters to approve.
* @throws {ApproveError} If the approval fails.
* @returns {Promise<Icrc1BlockIndex>} The block index of the approved transaction.
*/
icrc2Approve: (params: Icrc2ApproveRequest) => Promise<Icrc1BlockIndex>;
/**
* 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 {Icrc21ConsentMessageRequest} 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.
*/
icrc21ConsentMessage: (params: Icrc21ConsentMessageRequest) => Promise<icrc21_consent_info>;
}