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: WalletAddresses

    • btcAddress: Bitcoin address as string or null.

    • ordinalsAddress: Bitcoin Ordinals address as string or null.

    • evmAddress: EVM address as string or null.

  • connection: WalletConnection

    • isConnected: boolean indicating if a wallet is connected.

    • chain: Contains id, name, and nativeCurrency.

  • balance: WalletBalance

    • btcBalance: number representing the Bitcoin balance in satoshis.

    • evmBalance: Object with chainName and balance as a bigint.

  • publicKeys: PublicKeys

    • btcPublicKey: Bitcoin public key as string or null.

    • ordinalsPublicKey: Bitcoin Ordinals public key as string or null.

    • evmPublicKey: EVM public key as string or null.

With this setup, you can quickly access and display wallet information within your application using the useZky hook.

Last updated