Socket
Socket
Sign inDemoInstall

@dfinity/ledger-icp

Package Overview
Dependencies
22
Maintainers
10
Versions
266
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dfinity/ledger-icp

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


Version published
Weekly downloads
3.2K
decreased by-32.12%
Maintainers
10
Created
Weekly downloads
 

Readme

Source

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:

:factory: AccountIdentifier

:link: Source

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

:link: Source

:gear: fromPrincipal
MethodType
fromPrincipal({ principal, subAccount, }: { principal: Principal; subAccount?: SubAccount or undefined; }) => 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: 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.

: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

:factory: IndexCanister

:link: Source

Methods
:gear: create
MethodType
create({ canisterId: optionsCanisterId, ...options }: CanisterOptions<_SERVICE>) => IndexCanister

:link: Source

:gear: accountBalance

Returns the balance of the specified account identifier.

MethodType
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.

:link: Source

:gear: getTransactions

Returns the transactions and balance of an ICP account.

MethodType
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.

:link: Source

Resources

Keywords

FAQs

Last updated on 29 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc