2.2.3 • Published 13 days ago

@dfinity/ledger-icp v2.2.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
13 days ago

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";

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:

:factory: AccountIdentifier

:link: Source

Methods

:gear: fromHex
MethodType
fromHex(hex: string) => AccountIdentifier

:link: Source

:gear: fromPrincipal
MethodType
fromPrincipal({ principal, subAccount, }: { principal: Principal; subAccount?: SubAccount; }) => AccountIdentifier

:link: Source

:gear: toProto
MethodType
toProto() => Promise<AccountIdentifier>

:link: Source

:gear: toHex
MethodType
toHex() => string

:link: Source

:gear: toUint8Array
MethodType
toUint8Array() => Uint8Array

:link: Source

:gear: toNumbers
MethodType
toNumbers() => number[]

:link: Source

:gear: toAccountIdentifierHash
MethodType
toAccountIdentifierHash() => { hash: Uint8Array; }

:link: Source

:factory: SubAccount

:link: Source

Methods

:gear: fromBytes
MethodType
fromBytes(bytes: Uint8Array) => SubAccount or Error

:link: Source

:gear: fromPrincipal
MethodType
fromPrincipal(principal: Principal) => SubAccount

:link: Source

:gear: fromID
MethodType
fromID(id: number) => SubAccount

:link: Source

:gear: toUint8Array
MethodType
toUint8Array() => Uint8Array

:link: Source

:factory: LedgerCanister

:link: Source

Methods

:gear: create
MethodType
create(options?: LedgerCanisterOptions) => LedgerCanister

:link: Source

:gear: 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.

MethodType
accountBalance({ accountIdentifier, certified, }: { accountIdentifier: AccountIdentifier; certified?: boolean; }) => Promise<bigint>

:link: Source

:gear: transactionFee

Returns the transaction fee of the ledger canister

MethodType
transactionFee() => Promise<bigint>

:link: Source

:gear: transfer

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

MethodType
transfer(request: TransferRequest) => Promise<bigint>

:link: Source

:gear: icrc1Transfer

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

MethodType
icrc1Transfer(request: Icrc1TransferRequest) => Promise<bigint>

:link: Source

Resources

2.2.3

13 days ago

2.2.2

2 months ago

2.2.1

3 months ago

2.2.0

3 months ago

2.1.2

3 months ago

2.1.1

4 months ago

2.1.0

5 months ago

2.0.0

6 months ago

1.1.0

6 months ago

1.0.0

7 months ago