1.0.0 • Published 7 months ago

@dfinity/ledger v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

ledger-js

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

npm version GitHub license

Table of contents

Installation

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

npm i @dfinity/ledger

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

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 { IcrcLedgerCanister } from "@dfinity/ledger";
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-js implements following features:

:toolbox: Functions

:gear: encodeIcrcAccount

Encodes an Icrc-1 account compatible into a string. Formatting Reference: https://github.com/dfinity/ICRC-1/pull/55/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R238

FunctionType
encodeIcrcAccount({ owner, subaccount, }: IcrcAccount) => string

Parameters:

  • account: : Principal, subaccount?: Uint8Array }

:gear: decodeIcrcAccount

Decodes a string into an Icrc-1 compatible account. Formatting Reference: https://github.com/dfinity/ICRC-1/pull/55/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R268

FunctionType
decodeIcrcAccount(accountString: string) => IcrcAccount

Parameters:

  • accountString: string

:factory: IcrcLedgerCanister

Constructors

public

Methods

:gear: create
MethodType
create(options: IcrcLedgerCanisterOptions<_SERVICE>) => IcrcLedgerCanister
:gear: metadata

The token metadata (name, symbol, etc.).

MethodType
metadata(params: QueryParams) => Promise<IcrcTokenMetadataResponse>
:gear: transactionFee

The ledger transaction fees.

MethodType
transactionFee(params: QueryParams) => Promise<bigint>
:gear: balance

Returns the balance of the given account.

MethodType
balance(params: BalanceParams) => Promise<bigint>

Parameters:

  • params: The parameters to get the balance of an account.
:gear: transfer

Transfers tokens from the sender to the given account.

MethodType
transfer(params: TransferParams) => Promise<bigint>

Parameters:

  • params: The parameters to transfer tokens.

Resources

0.0.15

8 months ago

0.0.11

10 months ago

0.0.12

9 months ago

0.0.13

9 months ago

0.0.14

8 months ago

1.0.0

7 months ago

0.0.9

11 months ago

0.0.8

12 months ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.10

11 months ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago