Using Bitcoin
Getting the wallets
Use the useEmbeddedBitcoinWallet
hook from the @privy-io/expo
package to get the user’s embedded Bitcoin wallets:
Each entry in the wallets
array is an object with the following fields:
The type of the wallet.
The address (base58-encoded public key) for the wallet.
The public key (hex encoded) for the wallet.
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:
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
:
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.
Parameters
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.
Parameters
The hash of the transaction to sign.
Was this page helpful?