Getting the wallets

Use the useEmbeddedBitcoinWallet hook from the @privy-io/expo package to get the user’s embedded Bitcoin wallets:

import {useEmbeddedBitcoinWallet} from '@privy-io/expo';

const {wallets} = useEmbeddedBitcoinWallet();

Each entry in the wallets array is an object with the following fields:

chainType
'bitcoin-taproot' | 'bitcoin-segwit'
required

The type of the wallet.

address
string
required

The address (base58-encoded public key) for the wallet.

publicKey
string
required

The public key (hex encoded) for the wallet.

walletIndex
number
required

The HD index for the wallet.

getProvider
Promise<EmbeddedBitcoinWalletProvider>
required

Method to get a provider for interacting with the wallet.

The create method returned by useEmbeddedBitcoinWallet also returns this same type of object.

Getting the address

Once a user has created their embedded Bitcoin wallet, you can get its address by inspecting the address field of the wallet object:

const wallet = await create({chainType: 'bitcoin-taproot'});
console.log(wallet.address);
// bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr

Getting a wallet provider

To send signature and transaction requests to a user’s Bitcoin wallet, you must first get a provider instance for their wallet. This serves as a standardized abstraction to communicate requests from your app to the user’s wallet.

To get a provider for the user’s Bitcoin wallet, call the getProvider method on the wallet interface returned by useEmbeddedBitcoinWallet:

// This assumes you have already created a Bitcoin wallet for the user
const {wallets} = useEmbeddedBitcoinWallet();
const wallet = wallets.find((wallet) => wallet.chainType === 'bitcoin-taproot');
const provider = await wallet.getProvider();

Signing a transaction

To sign a transaction using a Bitcoin wallet, call the signTransaction method on the wallet’s provider. This method will return an object with a signedTransaction field, containing a hex-encoded string for the signed transaction.

// The `transaction` below is a `Transaction` object from `@scure/btc-signer`.
const {signedTransaction} = await provider.signTransaction({
  psbt: bytesToHex(transaction.toPSBT())
});

Parameters

psbt
string
required

A hex-encoded transaction in Partially Signed Bitcoin Transaction format.

Requesting a signature

To request a signature from a user’s Bitcoin wallet, call the sign method on the wallet’s provider. This method will return a signature over the provided hash, encoded as a base64 string.

// The `transaction` below is a `Transaction` object from `@scure/btc-signer`.
const {signature} = await provider.sign({hash: transaction.hash});

Parameters

hash
string
required

The hash of the transaction to sign.