FieldDescription
getBalance(): Promise<string | undefined>A method to fetch the balance for the connected address
getConnectedAccounts(): Promise<string[]>A method to retrieve the current connected address
getAdditionalAddresses(mainAddress: string): Promise<WalletAdditionalAddress[]>A method to return the payment and ordinals address (if applicable) as an array of objects
name: stringThe wallet name
signMessage(messageToSign: string): Promise<string | undefined>A method to sign a message
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(BitcoinTransaction): Promise<string | undefined>A method to send an amount of satoshis to a recipient bitcoin address
signPsbt(request: BitcoinSignPsbtRequest): Promise<BitcoinSignPsbtResponse | undefined>A method to sign a partially signed bitcoin transaction (PSBT)
signPsbts(request: BitcoinSignPsbtRequest[]): Promise<string[] | undefined>A method to sign multiple partially signed bitcoin transactions (PSBTs)
isLedgerAddress(address: string): booleanA method for determining if the connected address is a ledger wallet

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 WalletAdditionalAddress {
  address: string;
  publicKey?: string;
  type: 'payment' | 'ordinal';
}

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.

Send Bitcoin

In this example, we are going to send bitcoin using the wallet connector.

import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isBitcoinConnector } from '@dynamic-labs/wallet-connector-core';

const SendBitcoinButton = () => {
  const { primaryWallet } = useDynamicContext();

  const sendBitcoin = async () => {
    if (!primaryWallet) return;

    if (!isBitcoinConnector(primaryWallet.connector)) {
      return;
    }

    // The first argument is the address you are sending to, the second argument is the amount of BTC in satoshis
    const transactionId = await primaryWallet.connector.sendBitcoin('<bitcoin payment address>', 1);

    console.log('transactionId', transactionId);
  };

  return <button onClick={sendBitcoin}>Send Bitcoin</button>;
};

Sign a message

In this example, we are going to sign a message using the wallet connector.

import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isBitcoinConnector } from '@dynamic-labs/wallet-connector-core';

const SignMessageButton = () => {
  const { primaryWallet } = useDynamicContext();

  const signMessage = async () => {
    if (!primaryWallet) return;

    if (!isBitcoinConnector(primaryWallet.connector)) {
      return;
    }

    const signature = await primaryWallet.connector.signMessage('example');

    console.log('signature', signature);
  };

  return <button onClick={signMessage}>Sign message</button>;
};

Send a raw transaction to the bitcoin network

In this example, we are going to send a raw transaction as a hex value to the bitcoin network. For information on how to construct the transactionHexString, please refer to this example.

import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isBitcoinConnector } from '@dynamic-labs/wallet-connector-core';

const SendRawTransaction = () => {
  const { primaryWallet } = useDynamicContext();

  const signMessage = async () => {
    if (!primaryWallet) return;

    if (!isBitcoinConnector(primaryWallet.connector)) {
      return;
    }

    const transactionId = await primaryWallet.connector.sendRawTransaction('transactionHexString');

    console.log('transactionId', transactionId);
  };

  return <button onClick={SendRawTransaction}>Send Raw Transaction</button>;
};