Docs Guides

Host features

Listen to host events and use device controls such as orientation and haptics.

Listen to host events

import { WalletBridgeClient } from '@hydraone-sdk/core';

export function listen(client: WalletBridgeClient) {
  const offTheme = client.onThemeChanged((theme) => console.log('theme', theme));
  const offLanguage = client.onLanguageChanged((language) => console.log('language', language));
  const offCustom = client.on<{ foo: string }>('CUSTOM_EVENT', (p) => console.log(p.foo));
  return () => {
    offTheme();
    offLanguage();
    offCustom();
  };
}

client.language holds the current UI language as a BCP-47 tag (for example 'en' or 'vi'), also reported in hostInfo.language. The host pushes changes with host.setLanguage(tag). In the same way, client.theme holds 'dark' or 'light' and the host pushes changes with host.notify('THEME_CHANGED', { theme }). client.on is a short alias of client.onHostEvent.

Every subscription returns an unsubscribe function. Call client.destroy() when the app shuts down; it removes all listeners.

Device and host controls

These calls ask the host shell to act:

import { WalletBridgeClient } from '@hydraone-sdk/core';

export async function device(client: WalletBridgeClient) {
  await client.setOrientation('landscape');
  await client.triggerHaptic('success');
}
CallOutside the App Center iframe
setOrientationUses the browser API and ignores failures.
triggerHapticUses the browser API and ignores failures.

Inside the iframe both calls need a connected client and reject with ERR_BRIDGE_NOT_CONNECTED otherwise. Outside it they still forward the request to the host when the client is connected.

setOrientation accepts any, natural, landscape, portrait and their -primary / -secondary variants. triggerHaptic accepts a preset (light, medium, heavy, selection, success, warning, error; default medium), a duration in milliseconds, or a vibration pattern array. Invalid values reject with ERR_INVALID_PARAMS.

Use unlockOrientation() (the same as setOrientation('any')) to release a lock you set earlier.

Run the host side

An app that embeds apps creates the host with createHost and gives it a HostWalletAdapter, which is how the SDK reads your wallet state:

MethodReturns
getChangeAddress()the connected wallet's change address, or null
getCip30Api()the active CIP-30 extension as a HostCip30Api, or null for an embedded wallet
fetchBalance() / fetchUtxos()decoded assets and UTxOs
getNetworkId()0 (testnet), 1 (mainnet) or null

Give the HostCip30Api a name (for example window.cardano.eternl.name) so embedded apps see the real wallet name in hostInfo.wallet.name and client.activeWalletName. Set hostName and networkName in createHost options; they reach apps as hostInfo.hostName / client.hostName and hostInfo.networkName.

Tell the host when the wallet changes: host.handleAddressChange(next, previous) when the account switches, and host.handleWalletConnectionChange(connected) when the user connects or disconnects the wallet. The second one sends WALLET_DISCONNECTED to apps. The bridge stays connected, so apps keep running and recover on the next ACCOUNT_CHANGED.

Next steps