Skip to main content

Coroutines Alternatives

Beacon Android SDK by default uses Coroutines to handle asynchronous code. If you don't want to use Coroutines in your application, see the alternatives below.

:client-wallet-compat

Beacon Adndroid SDK ships with :client-wallet-compat module that provides a supplementary callback-based interface for :client-wallet. See the snippets below to learn how to use it.

tip

See the Installation page for more information about the :client-wallet-compat module and how to install it.

Create a wallet client

import it.airgap.beaconsdk.client.wallet.BeaconWalletClient
import it.airgap.beaconsdk.client.wallet.compat.BuildCallback
import it.airgap.beaconsdk.client.wallet.compat.build

lateinit var beaconWallet: BeaconWalletClient

BeaconWalletClient.Builder("My App").apply {
support(/* blockchains */)
use(/* connections */)
}.build(object : BuildCallback {
override fun onSuccess(beaconClient: BeaconWalletClient) {
beaconWallet = beaconClient
}

override fun onError(error: Throwable) {
error.printStackTrace()
}

override fun onCancel() {
super.onCancel()
}
})

Subscribe to incoming requests

import it.airgap.beaconsdk.client.wallet.compat.OnNewMessageListener
import it.airgap.beaconsdk.client.wallet.compat.connect

beaconWallet.connect(object : OnNewMessageListener {
override fun onNewMessage(message: BeaconMessage) {
...
}

override fun onError(error: Throwable) {
...
}
})

Connect to a dApp

import it.airgap.beaconsdk.client.wallet.compat.SetCallback
import it.airgap.beaconsdk.client.wallet.compat.addPeers
import it.airgap.beaconsdk.core.data.P2pPeer

val dApp = P2pPeer(
id = "id",
name = "name",
publicKey = "publicKey",
relayServer = "relayServer",
version = "version",
)

beaconWallet.addPeers(dApp, callback = object : SetCallback {
override fun onSuccess() {
TODO("Not yet implemented")
}

override fun onError(error: Throwable) {
TODO("Not yet implemented")
}
})

Handle requests from the dApp

import it.airgap.beaconsdk.client.wallet.compat.ResponseCallback
import it.airgap.beaconsdk.client.wallet.compat.respond

beaconWallet.respond(response, object : ResponseCallback {
override fun onSuccess() {
...
}

override fun onError(error: Throwable) {
...
}
})

Integration with other asynchronous libraries

See the guides below to learn how to integrate Beacon Android SDK with other asynchronous libraries.