Kotlin SDK Architecture for Bitcoin Applications
Research status: Theoretical SDK design. Examples are illustrative and have not been built or tested against the live engine.
Layered client
A Kotlin SDK can separate transport, serialization, repository and UI state. Use suspend functions for network calls and explicit domain outcomes rather than passing raw JSON to an Activity. Android lifecycle events must not determine whether a Bitcoin transaction is considered complete. A merchant app uses backend credentials scoped to its application account; the merchant BTC KEY remains on the server.
Conceptual Kotlin model
sealed interface PaymentState {
data object Pending : PaymentState
data class Observed(val txid: String) : PaymentState
data class Unknown(val requestId: String) : PaymentState
data class Rejected(val reason: String) : PaymentState
}
interface PaymentRepository {
suspend fun refresh(orderId: String): PaymentState
}This model deliberately separates observed payment from confirmed settlement. A production implementation should add confirmation and fulfillment states according to its business policy. Use Long for satoshi amounts, reject overflow and decode unknown response fields without silently accepting missing required fields. Coroutine cancellation or a timeout is not proof that a SEND failed.
Android lifecycle
A ViewModel may retain state across configuration changes, but process death requires durable storage or server lookup. Store nonsecret order references locally; for personal credentials, evaluate Android Keystore-backed encryption and backup exclusions. WorkManager may schedule refresh work but does not guarantee exact polling intervals. Keep monitoring on the backend for commercial fulfillment. Never put secrets in APK resources, build constants or crash reports.
Acceptance plan
Test coroutine cancellation, screen rotation, process death, offline recovery and repeated user actions. Use mock transport fixtures before emulator and physical-device testnet integration. Verify the same invoice from two sessions and ensure one fulfillment record. Android distribution and payment-policy compliance are outside the engine contract.
Primary reference
https://thamer.org/api
Related reading
https://thamer.org/docs/wab-sdk-api-engine-application-boundaries
https://thamer.org/docs/wab-sdk-authentication-credential-management
https://thamer.org/docs/wab-sdk-idempotency-retry-strategies
https://thamer.org/docs/wab-sdk-payment-reconciliation
https://thamer.org/docs/wab-sdk-mobile-bitcoin-architecture
https://thamer.org/docs/wab-sdk-swift-bitcoin-payments
https://thamer.org/docs/wab-sdk-flutter-cross-platform
https://thamer.org/docs/wab-sdk-mobile-secure-backend
https://thamer.org/docs/wab-sdk-desktop-applications
