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
Installation and Setup
To get started with the useBitcoin
hook from the Zky Toolkit, follow these steps:
Install the Zky Toolkit package: Ensure you have the toolkit installed in your project by running:
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. See a full example creating PSBTbroadcast
(boolean): The allowed sign hash type. Optional, default = falsesignInputs
(Record<string, number[]>): A mapping of inputs to be signed.the keys are the addresses to use for signing
the values are the indexes of the inputs to sign with each address.
Output: Returns a signed PSBT as a promise.
psbt
(string): The PSBT signed.txId
(string): The transaction id if the transaction was broadcasted.
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