Skip to main content
@thru/embedded-provider is the lowest-level browser wallet package. It gives you the iframe lifecycle, the postMessage protocol, and the chain interface without adding React or a typed RPC client.

Install

npm install @thru/embedded-provider

Import

import { EmbeddedProvider } from '@thru/embedded-provider';

When to use it

Use this package when you need direct control over the wallet iframe or want to build your own abstraction on top of the embedded wallet protocol. Choose a different layer if:
  • You want the embedded wallet plus a typed Thru client: use @thru/browser-sdk
  • You want React state and hooks: use @thru/react-sdk
  • You want a prebuilt React wallet control: use @thru/react-ui

Public surface

The package has a single root entry point. It exports the provider class, the embedded chain adapter, the config types, and the message/result types used by the wallet protocol. It exports:
  • EmbeddedProvider
  • EmbeddedThruChain
  • EmbeddedProviderConfig
  • ConnectOptions
  • ErrorCode
  • POST_MESSAGE_REQUEST_TYPES, EMBEDDED_PROVIDER_EVENTS, POST_MESSAGE_EVENT_TYPE, IFRAME_READY_EVENT, and DEFAULT_IFRAME_URL
  • Message and result types such as ConnectResult, PostMessageRequest, PostMessageResponse, SignMessagePayload, and SignTransactionResult
  • Convenience types re-exported from @thru/chain-interfaces, including IThruChain and WalletAccount

Configuration

OptionDescription
iframeUrlHosted wallet URL to load, defaulting to DEFAULT_IFRAME_URL.
addressTypesWhich chain interfaces to enable.
ConnectOptions currently supports optional connection metadata.

Example

import { EmbeddedProvider } from '@thru/embedded-provider';

const provider = new EmbeddedProvider({
  iframeUrl: 'https://wallet.thru.org',
});

await provider.initialize();
const { accounts } = await provider.connect();
const signed = await provider.thru.signTransaction(base64Transaction);
await provider.disconnect();
provider.destroy();

What it does

EmbeddedProvider manages the wallet iframe lifecycle, connection state, and event forwarding. The provider also exposes a thru chain interface for signing Thru transactions through the embedded wallet. The main methods are:
  • initialize() to create the iframe and wait for it to be ready
  • mountInline(container) to mount the wallet inline in an element
  • connect(options?) to open the wallet and request a connection
  • disconnect() to end the session
  • selectAccount(publicKey) to switch the active account
  • destroy() to clean up the iframe and listeners
The thru property gives you the chain-specific interface:
  • connect() returns the Thru public key
  • disconnect() disconnects the wallet
  • signTransaction(serializedTransaction) signs a base64-encoded transaction string

Events

You can subscribe with provider.on(event, callback) and unsubscribe with provider.off(event, callback). Common provider events include connect start, connect success, connect error, disconnect, lock, account change, and UI show events.