Coffer Network SDK Documentation
Table of Contents
Installation
npm install @coffer-network/api-sdkFor address verification functionality:
npm install @coffer-network/address-verify-sdkCofferClient
Main client class for interacting with the Coffer Network API.
import { CofferClient } from "@coffer-network/api-sdk";
const client = new CofferClient();Set JWT Token
setToken(token: string): CofferClient
Set authentication token.
client.setToken("your-jwt-token");Wallet
Wallet-related operation interfaces.
List wallets
listWallets(): Promise<ApiResponse<WalletItem[]>>
Get list of all wallets.
const wallets = await client.wallet.listWallets();Create Multisig Wallet
createMultisigWallet(data: CreateWalletProps): Promise<ApiResponse<WalletItem>>
Create a new multisig wallet.
const wallet = await client.wallet.createMultisigWallet({
name: "My Multisig Wallet",
addressType: "p2tr",
signers: [
{ name: "Signer 1", address: "bc1..." },
{ name: "Signer 2", address: "bc1..." },
],
network: "mainnet",
threshold: 2,
});Join Multisig Wallet
joinMultiSigWallet(walletId: string): Promise<ApiResponse<WalletAssetItem>>
Join a multisig wallet.
const result = await client.wallet.joinMultiSigWallet("wallet-uuid");Get Wallet Assets
getWalletAssets(address: string): Promise<ApiResponse<WalletAssetItem[]>>
Get wallet assets list.
const assets = await client.wallet.getWalletAssets("bc1...");Transaction
Transaction-related operation interfaces.
Create Multisig Transaction
createMultisigTransaction(props: CreateTransactionProps): Promise<ApiResponse<TransactionItem>>
Create a multisig transaction.
const tx = await client.transaction.createMultisigTransaction({
fromAddress: "bc1...",
toAddress: "bc1...",
amount: 0.01,
network: "mainnet",
assetType: "btc",
assetName: "btc",
FeeRate: 1000,
});Get Multisig Transaction PSBT
getMultisigTransactionPsbt(multisigTxid: string): Promise<ApiResponse<TransactionPsbt>>
Get transaction PSBT.
const psbt = await client.transaction.getMultisigTransactionPsbt("tx-uuid");Confirm Multisig Transaction
confirmMultisigTransaction(uuid: string, props: TransactionConfirmProps): Promise<unknown>
Confirm a multisig transaction.
await client.transaction.confirmMultisigTransaction("tx-uuid", {
action: "approve",
signedPsbt: "psbt-string",
});Chain
Chain-related operation interfaces.
Get FeeRate
getFeeRate(network?: Network): Promise<ApiResponse<FeeRate>>
Get network fee rate.
const feeRate = await client.chain.getFeeRate("mainnet");Estimate Transaction Fee
estimateFee(props: CreateTransactionProps): Promise<ApiResponse<{ fee: number }>>
Estimate transaction fee.
const fee = await client.chain.estimateFee({
fromAddress: "bc1...",
toAddress: "bc1...",
amount: 0.01,
network: "mainnet",
assetType: "btc",
assetName: "btc",
FeeRate: 1000,
});Address
Address toolkit provides multisig address generation and verification functionality.
Generate P2TR Multisig Address
genP2trMultisig(publicKeys: string[], threshold: number, network: NetworkModes): MultiSigInfo
Generate Taproot (P2TR) multisig address.
import { genP2trMultisig } from "@coffer-network/address-verify-sdk";
const p2trAddress = genP2trMultisig(["pubkey1", "pubkey2", "pubkey3"], 2, "mainnet");Generate P2WSH Multisig Address
genP2wshMultisig(publicKeys: string[], threshold: number, network: NetworkModes): MultiSigInfo
Generate P2WSH multisig address.
import { genP2wshMultisig } from "@coffer-network/address-verify-sdk";
const p2wshAddress = genP2wshMultisig(["pubkey1", "pubkey2", "pubkey3"], 2, "mainnet");Check If Address Matches Public Key
checkAddressFromPubKey(publicKey: string, address: string, network: NetworkModes)
Verify the relationship between public key and address.
import { checkAddressFromPubKey } from "@coffer-network/address-verify-sdk";
const result = checkAddressFromPubKey("pubkey-hex", "bc1...", "mainnet");Types
Main type definitions:
export type ConfirmAction = "approve" | "reject";
export type Network = "mainnet" | "testnet";
export type AssetType = "btc" | "runes";
export interface ApiResponse<T> {
code: number;
msg: string;
data: T;
}
export interface CreateWalletProps {
name: string;
addressType: "p2tr" | "p2wsh";
signers: Array<{
name: string;
address: string;
}>;
network: Network;
threshold: number;
description?: string;
}
export interface CreateTransactionProps {
fromAddress: string;
toAddress: string;
amount: number;
network: Network;
assetType: AssetType;
assetName: string;
FeeRate: number;
}
export interface FeeRate {
fastestFee: number;
halfHourFee: number;
hourFee: number;
economyFee: number;
minimumFee: number;
}
export interface QueryTransactionProps {
page?: number;
limit?: number;
txid?: string;
uuid?: string;
assetName?: string;
assetType?: string;
address?: string;
isReceived?: boolean;
isPending?: boolean;
isConfirmed?: boolean;
}
export interface ConfirmTransactionProps {
action: ConfirmAction;
signedPsbt: string;
}
export interface TransactionPsbt {
rawPsbt: string;
signersMapping: { [key: string]: SignersMapping };
}
export interface SignersMapping {
hdPath: string;
xpub: string;
masterKeyFingerprint: string;
}
export interface WalletAssetItem {
assetId: string;
assetName: string;
assetType: string;
assetSpecialName: string;
walletAddress: string;
balance: string;
unconfirmedBalance: string;
provider: string;
network: string;
decimals: number;
}
export interface WalletItem {
uuid: string;
addressType: string;
address: string;
threshold: number;
signerCount: number;
network: string;
creator: string;
createdAt: number;
signers: Signer[];
}
export interface Signer {
name: string;
address: string;
network: string;
joinedAt: number;
isJoined: boolean;
isCreator: boolean;
}
export interface TransactionItem {
uuid: string;
from: string;
to: string;
addressType: string;
assetName: string;
assetType: string;
amount: number;
network: string;
wallet: Wallet;
created: number;
fee: number;
feeRate: number;
confirmed: boolean;
txId: string;
isPending: boolean;
isReceived: boolean;
}
export interface Wallet {
addressType: string;
threshold: number;
signerCount: number;
address: string;
network: string;
}Each interface and type is designed to provide strong typing support for the SDK's functionality. The complete type definitions can be found in the source code.