Skip to main content
@thru/browser-sdk is the browser integration layer for apps that want the Thru wallet iframe plus a typed Thru client in one place.

Install

npm install @thru/browser-sdk

Import

import {
  BrowserSDK,
  type BrowserSDKConfig,
  type ConnectOptions,
} from '@thru/browser-sdk';

When to use it

Use this package when you want to manage the embedded Thru wallet yourself and keep the Thru RPC client close to the wallet lifecycle. Choose a different layer if:
  • You only need the iframe/provider protocol: use @thru/embedded-provider
  • You are in React and want hooks/state management: use @thru/react-sdk
  • You want a prebuilt React control: use @thru/react-ui

Public surface

The package has a single root entry point. It exports BrowserSDK, the constructor config, event types, and convenience re-exports from the wallet stack.
ExportDescription
BrowserSDKMain class for initializing the iframe, connecting to the wallet, and accessing the embedded Thru client.
BrowserSDKConfigConstructor config with iframeUrl, addressTypes, and rpcUrl.
ConnectOptionsOptional metadata for the connect flow.
SDKEventEvent names: connect, disconnect, lock, error, and accountChanged.
EventCallbackCallback shape used by on, off, and once.
WalletAccount, ConnectResult, IThruChain, SignMessageParams, SignMessageResultRe-exported convenience types from @thru/chain-interfaces.
ErrorCodeRe-exported error codes from @thru/embedded-provider.

Main entry points

MethodWhat it does
initialize()Creates the iframe once before you connect or mount inline.
connect(options?)Opens the wallet connection flow and returns the connected accounts.
mountInline(container)Mounts the wallet iframe inside a container element.
disconnect()Disconnects the wallet and clears the cached connection state.
isConnected()Returns whether the embedded provider is currently connected.
getAccounts()Returns the current wallet accounts.
getSelectedAccount()Returns the active account, if one is selected.
selectAccount(publicKey)Selects a specific wallet account by public key.
getThru()Returns the embedded Thru RPC client.
on, off, onceRegisters lifecycle listeners for wallet events.
destroy()Tears down the provider and clears internal state.

Example

import { BrowserSDK } from '@thru/browser-sdk';

const sdk = new BrowserSDK({
  iframeUrl: 'https://wallet.thru.org/embedded',
  rpcUrl: 'https://grpc-web.alphanet.thruput.org',
});

await sdk.initialize();
const { accounts } = await sdk.connect();
const thru = sdk.getThru();

Events

The SDK forwards these wallet lifecycle events:
  • connect
  • disconnect
  • lock
  • error
  • accountChanged
connect emits when the wallet connection succeeds, disconnect when the wallet disconnects, lock when the provider locks, error when the provider or connect flow fails, and accountChanged when the selected account changes. The SDK derives default connect metadata from the current browser origin when you do not provide appId, appUrl, or appName.