Honeycomb

Hooks

Access the Hive blockchain connection, chain object, and account data through framework-specific hooks.

useHive()

Returns the full Hive context including the chain object, connection status, and endpoint information. This is the primary hook for accessing blockchain connectivity.

PropertyTypeDescription
chainIHiveChainInterface | nullHive chain instance for API calls
is_loadingbooleanTrue while connecting to blockchain
errorstring | nullError message if connection failed
is_clientbooleanTrue when running on client (SSR detection). Not available in Vue package.
api_endpointstring | nullCurrently active API endpoint URL
statusConnectionStatusConnection state: connecting | connected | reconnecting | disconnected | error
endpointsEndpointStatus[]Health status of all configured endpoints
refresh_endpoints() => Promise<void>Manually trigger endpoint health checks

Svelte Reactivity

All values are reactive — use them directly in the template. Use $: for derived values.

<script lang="ts">
  import { useHive } from "@hiveio/honeycomb-svelte";

  // Do NOT destructure - getters lose reactivity when copied
  const hive = useHive();
</script>

{#if hive.is_loading}
  <p>Connecting to Hive...</p>
{:else if hive.error}
  <p>Error: {hive.error}</p>
{:else}
  <div>
    <p>Status: {hive.status}</p>
    <p>Endpoint: {hive.api_endpoint}</p>
    <p>Healthy: {hive.endpoints.filter((ep) => ep.healthy).length}</p>
    <button onclick={hive.refresh_endpoints}>
      Refresh Endpoints
    </button>
  </div>
{/if}

useHiveChain()

Returns the chain object directly. Use this when you only need the chain and want to keep destructuring minimal. The chain object provides access to all Hive blockchain APIs.

Chain API

The chain object is an IHiveChainInterface from @hiveio/wax. Use it to call blockchain APIs like chain.api.database_api.find_accounts() or chain.api.database_api.get_dynamic_global_properties().

<script lang="ts">
  import { useHiveChain } from "@hiveio/honeycomb-svelte";

  let { username }: { username: string } = $props();

  // Do NOT destructure - getters lose reactivity when copied
  const hive_chain = useHiveChain();

  async function fetch_account() {
    if (!hive_chain.chain) return;

    const result = await hive_chain.chain.api.database_api.find_accounts({
      accounts: [username],
    });
    // result.accounts[0] contains full account data
  }

  async function fetch_global_props() {
    if (!hive_chain.chain) return;

    const global_props =
      await hive_chain.chain.api.database_api.get_dynamic_global_properties({});
    // global_props.head_block_number, global_props.current_supply, etc.
  }
</script>

<div>
  <button onclick={fetch_account}>Fetch Account</button>
  <button onclick={fetch_global_props}>Fetch Global Props</button>
</div>

useApiEndpoint()

Returns the currently active API endpoint URL. Returns null when not connected.

<script lang="ts">
  import { useApiEndpoint } from "@hiveio/honeycomb-svelte";

  const endpoint = useApiEndpoint();
</script>

<p>Connected to: {endpoint.url ?? "none"}</p>

useHiveStatus()

Returns connection status and endpoint health information.

FieldTypeDescription
urlstringEndpoint URL
healthybooleanWhether the endpoint is responding
lastChecknumber | nullTimestamp of last health check
lastErrorstring | nullLast error message if unhealthy
<script lang="ts">
  import { useHiveStatus } from "@hiveio/honeycomb-svelte";

  const hive_status = useHiveStatus();
  let healthy = $derived(
    hive_status.endpoints.filter((ep) => ep.healthy).length
  );
</script>

<div>
  <p>Status: {hive_status.status}</p>
  <p>Healthy endpoints: {healthy} / {hive_status.endpoints.length}</p>
  <ul>
    {#each hive_status.endpoints as ep (ep.url)}
      <li>{ep.url} - {ep.healthy ? "OK" : ep.lastError ?? "unhealthy"}</li>
    {/each}
  </ul>
</div>

useHiveAccount(username)

Fetches account data from the Hive blockchain. Handles loading and error states automatically.

ParamTypeDescription
usernamestringHive account username to fetch
PropertyTypeDescription
accountHiveAccount | nullAccount data (name, balance, hbd_balance, post_count, etc.)
is_loadingbooleanTrue while fetching account data
errorError | nullError if fetch failed
refetch() => voidManually re-fetch account data
<script lang="ts">
  import { useHiveAccount } from "@hiveio/honeycomb-svelte";

  let { username }: { username: string } = $props();

  // Do NOT destructure - getters lose reactivity when copied
  const result = useHiveAccount(() => username);
</script>

{#if result.is_loading}
  <p>Loading account...</p>
{:else if result.error}
  <p>Error: {result.error.message}</p>
{:else if !result.account}
  <p>Account not found</p>
{:else}
  <div>
    <h2>{result.account.name}</h2>
    <p>Balance: {result.account.balance}</p>
    <p>HBD: {result.account.hbd_balance}</p>
    <p>Posts: {result.account.post_count}</p>
    <p>Joined: {result.account.created}</p>
    <button onclick={result.refetch}>Refresh</button>
  </div>
{/if}
Hive ProviderTheming