Connect to a dApp
#
RequirementsMake sure you have added the following packages 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 packages as your dependencies as well.
tip
See the Installation page for more information about the packages and how to install them.
#
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 Beacon.WalletClient
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 Beacon.WalletClient
instance with default settings. See the Configuration guide to learn about more advanced setups.
caution
Currently only one instance of Beacon.WalletClient
should be created per application.
#
Subscribe to incoming requestsSubscribe to requests from the dApp by connecting to the Beacon network and listening to incoming requests.
#
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 Beacon.P2PPeer
. Next, register the new instance of Beacon.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 class which connects to a dApp using Matrix and handles Substrate and Tezos messages based on the steps described earlier.
- SPM
- CocoaPods
Or in Xcode open the Add Package Dependency
window (as described in the official guide) and enter the Beacon iOS SDK
GitHub repository URL