Connect to a dApp
#
RequirementsMake sure you have added the following modules as your dependencies:
You should have also decided which blockchains will be supported in your application and what transport layers to use to establish the communication. Make sure you have added the appropriate Blockchain and Transport modules as your dependencies as well.
tip
See the Installation page for more information about the modules and how to install them.
caution
Beacon Android SDK by default uses Coroutines to handle asynchronous code. If you don't want to use Coroutines in your application, see the Coroutines Alternatives to learn other approaches.
#
How to listen for messages and respondFollow the steps below to learn how to interact with a dApp. The guide assumes all blockchains and transport layers are supported.
#
Create a wallet clientCreate a BeaconWalletClient
instance by providing your app's name, registering supported blockchains and transport layers that will be used for communication.
The example below creates a new BeaconWalletClient
instance with default settings. See the Configuration guide to learn about more advanced setups.
caution
Currently only one instance of BeaconWalletClient
should be created per application.
#
Subscribe to incoming requestsListen to requests from the dApp by collecting the Flow
returned from the BeaconWalletClient#connect
method. The Flow
emits BeaconRequest
packed in a Result
.
#
Connect to a dAppTo connect to a new dApp take the pairing request (obtained from, for example, a paring QR code) and transform it to P2pPeer
. Next, register the new instance of P2pPeer
in your wallet client.
#
Handle requests from the dAppHaving received a request, you can create a response and send it back to the dApp. The response should always be created from an incoming request. Attempting to send a response that was not created from a request awaiting answer will result in an error.
The first request your app receives from a dApp is a permission request. The example below shows how to respond to it in the most basic way. To get more information about other kinds of requests or learn more advanced use cases see the Blockchain guides.
#
Example CodeThe following example shows how to create a simple Activity
which connects to a dApp using Matrix and handles Substrate and Tezos messages based on the steps described earlier.
- Groovy
- Kotlin
- Groovy
- Kotlin