@dfinity/ledger-icp
TypeScript icon, indicating that this package has built-in type declarations

2.2.3 • Public • Published

ledger-icp-js

A library for interfacing with the ICP ledger on the Internet Computer.

npm version GitHub license

ℹ️ This library is meant to interface with the ICP ledger only. If you are looking to interact with Snses, ckBTC, or other ICRC tokens, use the ledger-icrc-js library.

Table of contents

Installation

You can use ledger-icp-js by installing it in your project.

npm i @dfinity/ledger-icp

The bundle needs peer dependencies, be sure that following resources are available in your project as well.

npm i @dfinity/agent @dfinity/candid @dfinity/principal @dfinity/utils @dfinity/nns-proto

Usage

The features are available through the class LedgerCanister. It has to be instantiated with a canister ID.

e.g. fetching a token metadata.

import { createAgent } from "@dfinity/utils";
import { LedgerCanister } from "@dfinity/ledger-icp";

const agent = await createAgent({
  identity,
  host: HOST,
});

const { metadata } = LedgerCanister.create({
  agent,
  canisterId: MY_LEDGER_CANISTER_ID,
});

const data = await metadata();

Features

ledger-icp-js implements following features:

🏭 AccountIdentifier

🔗 Source

Methods

⚙️ fromHex
Method Type
fromHex (hex: string) => AccountIdentifier

🔗 Source

⚙️ fromPrincipal
Method Type
fromPrincipal ({ principal, subAccount, }: { principal: Principal; subAccount?: SubAccount or undefined; }) => AccountIdentifier

🔗 Source

⚙️ toHex
Method Type
toHex () => string

🔗 Source

⚙️ toUint8Array
Method Type
toUint8Array () => Uint8Array

🔗 Source

⚙️ toNumbers
Method Type
toNumbers () => number[]

🔗 Source

⚙️ toAccountIdentifierHash
Method Type
toAccountIdentifierHash () => { hash: Uint8Array; }

🔗 Source

🏭 SubAccount

🔗 Source

Methods

⚙️ fromBytes
Method Type
fromBytes (bytes: Uint8Array) => SubAccount or Error

🔗 Source

⚙️ fromPrincipal
Method Type
fromPrincipal (principal: Principal) => SubAccount

🔗 Source

⚙️ fromID
Method Type
fromID (id: number) => SubAccount

🔗 Source

⚙️ toUint8Array
Method Type
toUint8Array () => Uint8Array

🔗 Source

🏭 LedgerCanister

🔗 Source

Methods

⚙️ create
Method Type
create (options?: LedgerCanisterOptions) => LedgerCanister

🔗 Source

⚙️ accountBalance

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.

Method Type
accountBalance ({ accountIdentifier: accountIdentifierParam, certified, }: AccountBalanceParams) => Promise<bigint>

Parameters:

  • params: The parameters to get the balance of an account.
  • params.accountIdentifier: The account identifier provided either as hex string or as an AccountIdentifier.
  • params.certified: query or update call.

🔗 Source

⚙️ transactionFee

Returns the transaction fee of the ledger canister

Method Type
transactionFee () => Promise<bigint>

🔗 Source

⚙️ transfer

Transfer ICP from the caller to the destination accountIdentifier. Returns the index of the block containing the tx if it was successful.

Method Type
transfer (request: TransferRequest) => Promise<bigint>

🔗 Source

⚙️ icrc1Transfer

Transfer ICP from the caller to the destination Account. Returns the index of the block containing the tx if it was successful.

Method Type
icrc1Transfer (request: Icrc1TransferRequest) => Promise<bigint>

🔗 Source

🏭 IndexCanister

🔗 Source

Methods

⚙️ create
Method Type
create ({ canisterId: optionsCanisterId, ...options }: CanisterOptions<_SERVICE>) => IndexCanister

🔗 Source

⚙️ accountBalance

Returns the balance of the specified account identifier.

Method Type
accountBalance ({ certified, accountIdentifier, }: AccountBalanceParams) => Promise<bigint>

Parameters:

  • params: The parameters to get the balance of an account.
  • params.accountIdentifier: The account identifier provided either as hex string or as an AccountIdentifier.
  • params.certified: query or update call.

🔗 Source

⚙️ getTransactions

Returns the transactions and balance of an ICP account.

Method Type
getTransactions ({ certified, accountIdentifier, start, maxResults: max_results, }: GetTransactionsParams) => Promise<GetAccountIdentifierTransactionsResponse>

Parameters:

  • params: The parameters to get the transactions.
  • params.certified: query or update call.
  • params.accountIdentifier: The account identifier provided either as hex string or as an AccountIdentifier.
  • params.start: If set then the results will start from the next most recent transaction id after start (start won't be included). If not provided, then the results will start from the most recent transaction id.
  • params.maxResults: Maximum number of transactions to fetch.

🔗 Source

Resources

Package Sidebar

Install

npm i @dfinity/ledger-icp

Weekly Downloads

4,461

Version

2.2.3

License

Apache-2.0

Unpacked Size

525 kB

Total Files

52

Last publish

Collaborators

  • dfx-json
  • dfn_wndlng
  • nathan.mcgrath.dfinity
  • frederikrothenberger
  • bitdivine
  • ielashi
  • dayyildiz
  • eric-swanson-dfinity
  • krpeacock
  • npm-dfinity-org