Socket
Socket
Sign inDemoInstall

@dfinity/ckbtc

Package Overview
Dependencies
24
Maintainers
10
Versions
571
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dfinity/ckbtc

A library for interfacing with ckBTC.


Version published
Weekly downloads
2.1K
decreased by-44.77%
Maintainers
10
Created
Weekly downloads
 

Readme

Source

ckbtc-js

A library for interfacing with ckBTC on the Internet Computer.

npm version GitHub license

Table of contents

Installation

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

npm i @dfinity/ckbtc

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 CkBTCMinterCanister. It has to be instantiated with a canister ID.

import { CkBTCMinterCanister } from "@dfinity/ckbtc";
import { createAgent } from "@dfinity/utils";

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

const { getBtcAddress } = CkBTCMinterCanister.create({
  agent,
  canisterId: MY_CKBTC_MINTER_CANISTER_ID,
});

const btcAddress = await getBtcAddress({});

Features

ckbtc-js implements following features:

:toolbox: Functions

:gear: parseBtcAddress

Parse a Bitcoin address.

Parse implementation follows strategy implemented in Minter canister.

Credits: Parts of JavaScript code and test values from bitcoin-address-validation.

FunctionType
parseBtcAddress({ address, network, }: BtcAddress) => BtcAddressInfo

Parameters:

  • params: The Bitcoin address and network to parse
  • params.network: Optional. Default BtcNetwork is Mainnet

:link: Source

:factory: CkBTCMinterCanister

:link: Source

Methods
:gear: create
MethodType
create(options: CkBTCMinterCanisterOptions<_SERVICE>) => CkBTCMinterCanister

:link: Source

:gear: getBtcAddress

Returns a BTC address for a given account.

Note: an update call is required by the Minter canister.

MethodType
getBtcAddress({ owner, subaccount, }: MinterParams) => Promise<string>

Parameters:

  • params: The parameters for which a BTC address should be resolved.
  • params.owner: The owner for which the BTC address should be generated. If not provided, the caller will be use instead.
  • params.subaccount: An optional subaccount to compute the address.

:link: Source

:gear: updateBalance

Notify the minter about the bitcoin transfer.

Upon successful notification, new ckBTC should be available on the targeted address.

MethodType
updateBalance({ owner, subaccount, }: MinterParams) => Promise<UpdateBalanceOk>

Parameters:

  • params: The parameters are the address to which bitcoin where transferred.
  • params.owner: The owner of the address. If not provided, the caller will be use instead.
  • params.subaccount: An optional subaccount of the address.

:link: Source

:gear: getWithdrawalAccount

Returns the account to which the caller should deposit ckBTC before withdrawing BTC using the [retrieveBtc] endpoint.

MethodType
getWithdrawalAccount() => Promise<Account>

:link: Source

:gear: retrieveBtc

Submits a request to convert ckBTC to BTC.

Note:

The BTC retrieval process is slow. Instead of synchronously waiting for a BTC transaction to settle, this method returns a request ([block_index]) that the caller can use to query the request status.

Preconditions:

The caller deposited the requested amount in ckBTC to the account that the [getWithdrawalAccount] endpoint returns.

MethodType
retrieveBtc(params: RetrieveBtcParams) => Promise<RetrieveBtcOk>

Parameters:

  • params: The parameters are the bitcoin address and amount to convert.
  • params.address: The bitcoin address.
  • params.amount: The ckBTC amount.

:link: Source

:gear: retrieveBtcWithApproval

Submits a request to convert ckBTC to BTC after making an ICRC-2 approval.

Note

The BTC retrieval process is slow. Instead of synchronously waiting for a BTC transaction to settle, this method returns a request ([block_index]) that the caller can use to query the request status.

Preconditions

The caller allowed the minter's principal to spend its funds using [icrc2_approve] on the ckBTC ledger.

MethodType
retrieveBtcWithApproval({ address, amount, fromSubaccount, }: { address: string; amount: bigint; fromSubaccount?: Uint8Array or undefined; }) => Promise<RetrieveBtcOk>

Parameters:

  • params.address: The bitcoin address.
  • params.amount: The ckBTC amount.
  • params.fromSubaccount: An optional subaccount from which the ckBTC should be transferred.

:link: Source

:gear: retrieveBtcStatus

Returns the status of a specific BTC withdrawal based on the transaction ID of the corresponding burn transaction.

MethodType
retrieveBtcStatus({ transactionId, certified, }: { transactionId: bigint; certified: boolean; }) => Promise<RetrieveBtcStatus>

Parameters:

  • transactionId: The ID of the corresponding burn transaction.
  • certified: query or update call

:link: Source

:gear: retrieveBtcStatusV2ByAccount

Returns the status of all BTC withdrawals for an account.

MethodType
retrieveBtcStatusV2ByAccount({ account, certified, }: RetrieveBtcStatusV2ByAccountParams) => Promise<RetrieveBtcStatusV2WithId[]>

Parameters:

  • certified: query or update call
  • account: an optional account to retrieve the statuses. If not provided, statuses for the caller are retrieved.

:link: Source

:gear: estimateWithdrawalFee

Returns an estimation of the user's fee (in Satoshi) for a retrieve_btc request based on the current status of the Bitcoin network and the fee related to the minter.

MethodType
estimateWithdrawalFee({ certified, amount, }: EstimateWithdrawalFeeParams) => Promise<EstimateWithdrawalFee>

Parameters:

  • params: The parameters to estimate the fee.
  • params.certified: query or update call
  • params.amount: The optional amount for which the fee should be estimated.

:link: Source

:gear: getMinterInfo

Returns internal minter parameters such as the minimal amount to retrieve BTC, minimal number of confirmations or KYT fee.

MethodType
getMinterInfo({ certified }: QueryParams) => Promise<MinterInfo>

Parameters:

  • params: The parameters to get the minter info.
  • params.certified: query or update call

:link: Source

:gear: getKnownUtxos

Returns UTXOs of the given account known by the minter.

MethodType
getKnownUtxos({ owner, subaccount, certified, }: GetKnownUtxosParams) => Promise<Utxo[]>

Parameters:

  • params: The parameters for which the known utxos should be resolved.
  • params.owner: The owner of the account. Note that if not provided, the caller would be used by the minter instead.
  • params.subaccount: An optional subaccount.

: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