Get started
Drive native iOS and Android features from your web app with @thebdk/native.
Create the client
Create the client once with createBdkNative() and reuse it everywhere.
Always create the client with createBdkNative(), never new BdkNativeClient(). It's ready the moment it returns.
Start readiness from your browser startup code rather than awaiting it in the shared module. Reuse the exported client throughout the page.
Detect the native app
Use bdk.ready(timeoutMs) to wait for device info and bdk.isNative() to branch your code. In a plain browser there's no app, so render a web-only fallback.
bdk.ready(0)(the default) resolves immediately — cachedBdkDeviceInfoif it arrived, elsenull.bdk.ready(3000)waits up to the timeout (ms) for thedeviceInfoevent.
Browser method options are typed — pass the option names each method documents, and your editor will catch mismatches.
Get a command's result
Legacy commands return NativeCommandResult; use !result.triggered and subscribe before calls whose data arrives on events. A browser tab returns pending, while a runtime without window returns skipped. Envelope helpers return { ok: true, ... } or { ok: false, code, message }; use isBdkError(result) or !result.ok, not triggered. New iap.* and health.* helpers can also return a bare command result: check "ok" in result first. Read each helper’s result type; do not apply one check to all methods.
Match the event to the command: bdk.media.capturePhoto() emits photoCaptured, bdk.media.pickPhoto() emits photoSelected. Both deliver a MediaResult ({ fileUrl, dataUri, data, contentType }).
Browser and server SDKs
Use @thebdk/native/browser (or the package root; CDN at dist/cdn/bdk-native.global.js) in your web app. Use @thebdk/native/server or a focused /server/* entry on your backend — await returns the typed result.
Never import @thebdk/native/server/* into a browser bundle — those modules are server-only and may carry secrets. Only the root and /browser entry points are browser-safe.
Start an in-app purchase
Subscribe once when the UI mounts, then start a purchase from a user action. Keep the listener for deferred approvals and unsubscribe when the UI unmounts. verifyAndUnlock is your application’s authenticated backend flow: verify the store proof before granting access.
Create the store products first and test your product IDs in your own build. See Purchases and Verify purchases.