> ## Documentation Index
> Fetch the complete documentation index at: https://docs.privy.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Using Bitcoin with on-device execution

> Use Bitcoin wallets with on-device execution for signing transactions and messages

<Warning>
  This guide is for using Bitcoin with on-device execution. If your app is using TEE execution, see
  the [Other chains](/wallets/using-wallets/other-chains) guide for details on using Bitcoin, Tron,
  and a multitude of other chains in every platform.

  See the [Bitcoin segwit recipe](/recipes/use-tier-2#bitcoin-segwit) for specifics on codifying and signing a Segwit transaction.
</Warning>

<View title="React Native" icon="react">
  ## Getting the wallets

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

  ```ts theme={"system"}
  import {useEmbeddedBitcoinWallet} from '@privy-io/expo';

  const {wallets} = useEmbeddedBitcoinWallet();
  ```

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

  <ParamField path="chainType" type="'bitcoin-taproot' | 'bitcoin-segwit'" required>
    The type of the wallet.
  </ParamField>

  <ParamField path="address" type="string" required>
    The address (base58-encoded public key) for the wallet.
  </ParamField>

  <ParamField path="publicKey" type="string" required>
    The public key (hex encoded) for the wallet.
  </ParamField>

  <ParamField path="walletIndex" type="number" required>
    The [HD index](/wallets/wallets/create/create-a-wallet#param-opts-create-additional) for the
    wallet.
  </ParamField>

  <ParamField path="getProvider" type="Promise<EmbeddedBitcoinWalletProvider>" required>
    Method to get a provider for interacting with the wallet.
  </ParamField>

  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:

  ```ts theme={"system"}
  import {useEmbeddedBitcoinWallet} from '@privy-io/expo';

  const {create, wallets} = useEmbeddedBitcoinWallet();

  // Create a Bitcoin Taproot wallet for the user
  await create({chainType: 'bitcoin-taproot'});

  const wallet = wallets.find((wallet) => wallet.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`:

  ```tsx theme={"system"}
  // 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](#provider).
  This method will return an object with a `signedTransaction` field, containing a hex-encoded string for the signed transaction.

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

  ### Parameters

  <ParamField path="psbt" type="string" required>
    A hex-encoded transaction in Partially Signed Bitcoin Transaction format.
  </ParamField>

  ## Requesting a signature

  To request a signature from a user's Bitcoin wallet, call the `sign` method on the wallet's [provider](#provider).
  This method will return a signature over the provided `hash`, encoded as a base64 string.

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

  ### Parameters

  <ParamField path="hash" type="string" required>
    The hash of the transaction to sign.
  </ParamField>
</View>
