We covered what a wallet in general looks like in the Accessing Wallets section and then what a wallet connector looks like in the Interacting With Wallets section. However, the wallet connector for Bitcoin wallets is a bit different from the EVM wallets, so we will cover that seperately here.

This is because Bitcoin wallets have different capabilities and requirements. For example, Bitcoin wallets can have multiple addresses associated with them, like payment and ordinal addresses.

Checking if a wallet is a Bitcoin wallet

You can use the isBitcoinWallet helper method to check if a wallet is a Bitcoin wallet. That way, TypeScript will know which methods are available to you.

import { isBitcoinWallet } from '@dynamic-labs/bitcoin';

if (!isBitcoinWallet(wallet)) {
  throw new Error('This wallet is not a Bitcoin wallet');
}

const result = wallet.sendBitcoin({
  amount: 100000000n,
  recipientAddress: 'SOME-ADDRESS',
});

Bitcoin Wallet

MethodDescription
sendRawTransaction(rawTransactionHex: string): Promise<string | undefined>This method submits a raw transaction to the bitcoin blockchain and returns the transaction ID as the response
sendBitcoin(transaction: BitcoinTransaction): Promise<string | undefined>A method to send an amount of satoshis to a recipient bitcoin address
signMessageWithAddress(messageToSign: string, addressType: WalletAddressType): Promise<string\ | undefined>Signs a message with a specific bitcoin address type (ordinals or payment)
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>Signs a PSBT and returns an object with the signed PSBT
signPsbts(request: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>Signs a list of PSBTs and returns an array of signed PSBTs in base64

Type Definitions

type BitcoinSignPsbtRequest = {
  allowedSighash: number[];
  unsignedPsbtBase64: string;
  signature?: {
    address: string;
    signingIndexes: number[] | undefined;
    disableAddressValidation?: boolean; // helpful for multi-sig
  }[];
};

type BitcoinTransaction = {
  amount: bigint;
  recipientAddress: string;
}

type WalletAddressType = 'payment' | 'ordinal';

type WalletAdditionalAddress {
  address: string;
  publicKey?: string;
  type: WalletAddressType;
}

type BitcoinSignPsbtResponse = {
  signedPsbt: Psbt; // see reference below for what a PSBT is
};

What is a satoshi?

This smallest unit allows for transactions involving very small amounts of bitcoin, facilitating microtransactions and improving the granularity of payments in the Bitcoin network.

1 Bitcoin = 100,000,000 Satoshis

What is a PSBT?

A partially signed bitcoin transaction (PSBT) is a standard for transactions that have not fully signed. This allows different participants with different keys/signers to sign a transaction without revealing their private keys to others. Multi-sig wallets utilize these. This allows for a multi-step transaction process which is both safer and more efficient.

Examples

We’ve included a few examples of how to use the Bitcoin wallet connector in this section: