useZky Hook
The useZky hook is a utility provided by the Zky Toolkit that allows you to easily access information about the connected wallet, including addresses, connection status, and balances (both Bitcoin and
1. Overview
The useZky hook provides the following details:
Addresses: Includes Bitcoin, Ordinals and EVM addresses.
Connection: Indicates whether a wallet is connected and provides details about the current blockchain network.
Balance: Includes the Bitcoin balance and EVM balance on the connected network.
Public Keys: Includes Bitcoin, Ordinals and EVM public keys.
2. Installation
Ensure that you have Zky Toolkit installed as outlined in the Quickstart section above.
3. Example Usage
Here's an example of how to use the useZky hook in your components:
import { useZky } from "@kondor-finance/zky-toolkit";
export default function WalletInfo() {
const { addresses, publicKeys, connection, balance } = useZky();
return (
<div>
<h2>Wallet Information</h2>
<div>
<p><strong>Bitcoin Address:</strong> {addresses.btcAddress || "Not connected"}</p>
<p><strong>Ordinals Address:</strong> {addresses.ordinalsAddress || "Not connected"}</p>
<p><strong>EVM Address:</strong> {addresses.evmAddress || "Not connected"}</p>
<p><strong>Bitcoin Public Key:</strong> {publicKeys.btcPublicKey || "Not connected"}</p>
<p><strong>Ordinals Public Key:</strong> {publicKeys.ordinalsPublicKey || "Not connected"}</p>
<p><strong>EVM Public Key:</strong> {publicKeys.evmPublicKey || "Not connected"}</p>
</div>
<div>
<h3>Connection</h3>
<p><strong>Connected:</strong> {connection.isConnected ? "Yes" : "No"}</p>
<p><strong>Chain Name:</strong> {connection.chain.name || "Unknown"}</p>
</div>
<div>
<h3>Balances</h3>
<p><strong>Bitcoin Balance:</strong> {balance.btcBalance} sats</p>
<p><strong>{balance.evmBalance.chainName} Balance:</strong> {balance.evmBalance.balance.toString()} wei</p>
</div>
</div>
);
}
4. useZky Hook API
The useZky hook returns an object containing:
addresses:
WalletAddressesbtcAddress: Bitcoin address asstringornull.ordinalsAddress: Bitcoin Ordinals address asstringornull.evmAddress: EVM address asstringornull.
connection:
WalletConnectionisConnected:booleanindicating if a wallet is connected.chain: Containsid,name, andnativeCurrency.setChain(chainId: number) => void: Set a specific Chain to the user's wallet.
balance:
WalletBalancebtcBalance:numberrepresenting the Bitcoin balance in satoshis.evmBalance: Object withchainNameandbalanceas abigint.
publicKeys:
PublicKeysbtcPublicKey: Bitcoin public key asstringornull.ordinalsPublicKey: Bitcoin Ordinals public key asstringornull.evmPublicKey: EVM public key asstringornull.
With this setup, you can quickly access and display wallet information within your application using the useZky hook.
Last updated