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.
| Property | Type | Description |
|---|---|---|
chain | IHiveChainInterface | null | Hive chain instance for API calls |
is_loading | boolean | True while connecting to blockchain |
error | string | null | Error message if connection failed |
is_client | boolean | True when running on client (SSR detection). Not available in Vue package. |
api_endpoint | string | null | Currently active API endpoint URL |
status | ConnectionStatus | Connection state: connecting | connected | reconnecting | disconnected | error |
endpoints | EndpointStatus[] | 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.
| Field | Type | Description |
|---|---|---|
url | string | Endpoint URL |
healthy | boolean | Whether the endpoint is responding |
lastCheck | number | null | Timestamp of last health check |
lastError | string | null | Last 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.
| Param | Type | Description |
|---|---|---|
username | string | Hive account username to fetch |
| Property | Type | Description |
|---|---|---|
account | HiveAccount | null | Account data (name, balance, hbd_balance, post_count, etc.) |
is_loading | boolean | True while fetching account data |
error | Error | null | Error if fetch failed |
refetch | () => void | Manually 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}