Set up the client
Create the one client object you use for everything in the SDK.
Create the client
Create one client per browser page and import it everywhere. Creating another client can stop the earlier client receiving results. In an SSR app, load the shared module only on the client; do not evaluate it on the server.
Configure the client
Every option is optional with a safe default, so most apps pass nothing. Set removeLoading: "manual" to dismiss the native splash screen yourself, and pass onError to centralize error reporting (it receives a BdkError).
Wait for the app to be ready
Wait for device info at startup before using native features. Pass a timeout to wait that many milliseconds; inside the app it resolves as soon as device info arrives, and in a plain browser it resolves to null when the timeout elapses. It never rejects, and it doesn't block rendering — only the code after the await.
Detect native vs. browser
Branch between native-only features and web fallbacks. bdk.isNative() returns true once device info has arrived; bdk.getDeviceInfo() returns the cached BdkDeviceInfo or null. For an instant answer, bdk.environment() reports "native" synchronously on current app builds — treat "unknown" as "wait" and use ready().
isNative() reads false until device info arrives — at page load that's the wrong answer inside the app. Always await bdk.ready(...) before branching.
Use it in your framework
Vite apps can import the shared browser module at startup. In React/Next, load it in a client component’s effect or event handler, not during server rendering. In Nuxt, import it from a .client.ts plugin without awaiting readiness in the plugin. Run readiness in client startup code and keep rendering independent of it. Public IDs may use the framework’s public environment variables; secrets never may.
Clean up in tests
Dispose a client only when that page or test no longer needs it. Do not dispose the shared client when one component unmounts; remove that component’s listeners instead. Hot reload should reuse the shared browser instance.