
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
@dfinity/ledger-icp
Advanced tools
A library for interfacing with the ICP ledger on the Internet Computer.
A library for interfacing with the ICP ledger on the Internet Computer.
ℹ️ 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.
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
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();
ledger-icp-js
implements following features:
Method | Type |
---|---|
fromHex | (hex: string) => AccountIdentifier |
Method | Type |
---|---|
fromPrincipal | ({ principal, subAccount, }: { principal: Principal; subAccount?: SubAccount or undefined; }) => AccountIdentifier |
Method | Type |
---|---|
toHex | () => string |
Method | Type |
---|---|
toUint8Array | () => Uint8Array |
Method | Type |
---|---|
toNumbers | () => number[] |
Method | Type |
---|---|
toAccountIdentifierHash | () => { hash: Uint8Array; } |
Method | Type |
---|---|
fromBytes | (bytes: Uint8Array) => SubAccount |
Method | Type |
---|---|
fromPrincipal | (principal: Principal) => SubAccount |
Method | Type |
---|---|
fromID | (id: number) => SubAccount |
Method | Type |
---|---|
toUint8Array | () => Uint8Array |
Method | Type |
---|---|
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.
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.Returns:
The balance of the given account.
Fetches the ledger metadata.
Method | Type |
---|---|
metadata | (params: QueryParams) => Promise<[string, Value][]> |
Parameters:
params
: - The parameters used to fetch the metadata, notably query or certified call.Returns:
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.
Returns the transaction fee of the ICP ledger canister.
Method | Type |
---|---|
transactionFee | (params?: QueryParams) => Promise<bigint> |
Parameters:
params
: - Optional query parameters for the request, defaulting to { certified: false }
for backwards compatibility reason.Returns:
A promise that resolves to the transaction fee as a bigint.
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> |
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> |
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
Method | Type |
---|---|
icrc2Approve | (params: Icrc2ApproveRequest) => Promise<bigint> |
Parameters:
params
: - The parameters to approve.Returns:
The block index of the approved transaction.
Fetches the consent message for a specified canister call, intended to provide a human-readable message that helps users make informed decisions.
Method | Type |
---|---|
icrc21ConsentMessage | (params: Icrc21ConsentMessageRequest) => Promise<icrc21_consent_info> |
Parameters:
params
: - The request parameters containing the method name, arguments, and consent preferences (e.g., language).Returns:
Method | Type |
---|---|
create | ({ canisterId: optionsCanisterId, ...options }: CanisterOptions<_SERVICE>) => IndexCanister |
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.Returns:
The balance of the given account.
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.Returns:
The transactions, balance and the transaction id of the oldest transaction the account has.
FAQs
A library for interfacing with the ICP ledger on the Internet Computer.
The npm package @dfinity/ledger-icp receives a total of 4,854 weekly downloads. As such, @dfinity/ledger-icp popularity was classified as popular.
We found that @dfinity/ledger-icp demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 open source maintainers collaborating on the project.
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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.