ckbtc-js
A library for interfacing with ckBTC on the Internet Computer.
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 LedgerCanister
. It has to be instantiated with a canister ID.
e.g. fetching a token metadata.
import { CkBTCCanister } from "@dfinity/ckbtc";
import { createAgent } from "@dfinity/utils";
const agent = await createAgent({
identity,
host: HOST,
});
const { getBtcAddress } = CkBTCCanister.create({
agent,
canisterId: MY_CKBTC_MINTER_CANISTER_ID,
});
const btcAddress = await getBtcAddress({});
Features
ckbtc-js
implements following features:
:factory: CkBTCMinterCanister
Constructors
public
Methods
:gear: create
Method | Type |
---|
create | (options: CkBTCMinterCanisterOptions<_SERVICE>) => CkBTCMinterCanister |
:gear: getBtcAddress
Returns a BTC address for a given account.
Note: an update call is required by the Minter canister.
Method | Type |
---|
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.
:gear: updateBalance
Notify the minter about the bitcoin transfer.
Upon successful notification, new ckBTC should be available on the targeted address.
Method | Type |
---|
updateBalance | ({ owner, subaccount, }: MinterParams) => Promise<UpdateBalanceResult> |
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.
Resources