useBitcoin Hook
The useBitcoin hook is a part of the Zky Toolkit that allows you to interact with Bitcoin-related functionalities, including signing messages, signing PSBTs, and sending Bitcoin transfers.
Overview
The useBitcoin
hook provides methods that require the wallet name to be set in order to perform various actions with a connected Bitcoin wallet. The hook internally manages the walletName
retrieval and throws an error if no wallet is connected.
Available Methods
The useBitcoin
hook returns an object with the following methods:
signMessage: Signs a message using the connected Bitcoin wallet.
signPsbt: Signs a Partially Signed Bitcoin Transaction (PSBT).
sendTransfer: Sends a Bitcoin transfer to a specified recipient.
Example Usage
Here is an example of how to use the useBitcoin
hook in your components:
Method Details
signMessage
Input:
message
(string) - The message you want to sign.Output: Returns a signed message as a promise.
Example:
signPsbt
Input:
psbtBase64
(string): The PSBT in base64 format.allowedSignHash
(number): The allowed sign hash type.signInputs
(Record<string, number[]>): A mapping of inputs to be signed.
Output: Returns a signed PSBT as a promise.
Example:
sendTransfer
Input:
recipient
(string): The recipient's Bitcoin address.amount
(string): The amount to send in satoshis.
Output: Returns a transaction ID as a promise.
Example:
Prerequisites
To use the useBitcoin
hook, ensure that:
Zky Toolkit is set up as described in the Quickstart section.
A wallet is connected using the
ZkyToolkitProvider
Last updated