@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
Import
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:EmbeddedProviderEmbeddedThruChainEmbeddedProviderConfigConnectOptionsErrorCodePOST_MESSAGE_REQUEST_TYPES,EMBEDDED_PROVIDER_EVENTS,POST_MESSAGE_EVENT_TYPE,IFRAME_READY_EVENT, andDEFAULT_IFRAME_URL- Message and result types such as
ConnectResult,PostMessageRequest,PostMessageResponse,SignMessagePayload, andSignTransactionResult - Convenience types re-exported from
@thru/chain-interfaces, includingIThruChainandWalletAccount
Configuration
| Option | Description |
|---|---|
iframeUrl | Hosted wallet URL to load, defaulting to DEFAULT_IFRAME_URL. |
addressTypes | Which chain interfaces to enable. |
ConnectOptions currently supports optional connection metadata.
Example
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 readymountInline(container)to mount the wallet inline in an elementconnect(options?)to open the wallet and request a connectiondisconnect()to end the sessionselectAccount(publicKey)to switch the active accountdestroy()to clean up the iframe and listeners
thru property gives you the chain-specific interface:
connect()returns the Thru public keydisconnect()disconnects the walletsignTransaction(serializedTransaction)signs a base64-encoded transaction string
Events
You can subscribe withprovider.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.