@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
Import
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 exportsBrowserSDK, the constructor config, event types, and convenience re-exports from the wallet stack.
| Export | Description |
|---|---|
BrowserSDK | Main class for initializing the iframe, connecting to the wallet, and accessing the embedded Thru client. |
BrowserSDKConfig | Constructor config with iframeUrl, addressTypes, and rpcUrl. |
ConnectOptions | Optional metadata for the connect flow. |
SDKEvent | Event names: connect, disconnect, lock, error, and accountChanged. |
EventCallback | Callback shape used by on, off, and once. |
WalletAccount, ConnectResult, IThruChain, SignMessageParams, SignMessageResult | Re-exported convenience types from @thru/chain-interfaces. |
ErrorCode | Re-exported error codes from @thru/embedded-provider. |
Main entry points
| Method | What 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, once | Registers lifecycle listeners for wallet events. |
destroy() | Tears down the provider and clears internal state. |
Example
Events
The SDK forwards these wallet lifecycle events:connectdisconnectlockerroraccountChanged
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.