Connect Wallets with dApps on Tezos
Beacon is an implementation of the wallet interaction standard tzip-10 which describes the connection of a dApp with a wallet.
The Beacon iOS SDK
provides iOS developers with tools useful for setting up communication between native wallets supporting Tezos and dApps that implement beacon-sdk
.
See the below guides to learn how to add Beacon into your project.
To add Beacon iOS SDK
with the Swift Package Manager, add the Beacon iOS SDK
package dependency:
Open the Add Package Dependency
window (as described in the official guide) and enter the Beacon iOS SDK
GitHub repository URL:
https://github.com/airgap-it/beacon-ios-sdk
Add the following dependency in your Package.swift
file:
.package(url: "https://github.com/airgap-it/beacon-ios-sdk", from: "3.2.1")
To add Beacon iOS SDK
using CocoaPods, add the Beacon iOS SDK
pod to your Podfile
:
target 'MyTarget' do
use_frameworks!
pod 'BeaconCore', :git => 'https://github.com/airgap-it/beacon-ios-sdk', :tag => '3.2.1'
// optional
pod 'BeaconClientDApp', :git => 'https://github.com/airgap-it/beacon-ios-sdk', :tag => '3.2.1'
// optional
pod 'BeaconClientWallet', :git => 'https://github.com/airgap-it/beacon-ios-sdk', :tag => '3.2.1'
// optional
pod 'BeaconBlockchainSubstrate', :git => 'https://github.com/airgap-it/beacon-ios-sdk', :tag => '3.2.1'
// optional
pod 'BeaconBlockchainTezos', :git => 'https://github.com/airgap-it/beacon-ios-sdk', :tag => '3.2.1'
// optional
pod 'BeaconTransportP2PMatrix', :git => 'https://github.com/airgap-it/beacon-ios-sdk', :tag => '3.2.1'
end
The documentation can be found here.
The project is divided into the following packages:
Core packages are the basis for other packages. They are required for the SDK to work as expected.
Module | Description | Dependencies | Required by |
---|---|---|---|
BeaconCore |
Base for other modules | ✖️ | BeaconClientWallet BeaconBlockchainSubstrate BeaconBlockchainTezos BeaconTransportP2PMatrix |
Client packages ship with Beacon implementations for different parts of the network.
Module | Description | Dependencies | Required by |
---|---|---|---|
BeaconClientDApp |
Beacon implementation for dApps | BeaconCore |
✖️ |
BeaconClientWallet |
Beacon implementation for wallets | BeaconCore |
✖️ |
Blockchain packages provide support for different blockchains.
Module | Description | Dependencies | Required by |
---|---|---|---|
BeaconBlockchainSubstrate |
Substrate specific components | BeaconCore |
✖️ |
BeaconBlockchainTezos |
Tezos specific components | BeaconCore |
✖️ |
Transport packages provide various interfaces used to establish connection between Beacon clients.
Module | Description | Dependencies | Required by |
---|---|---|---|
BeaconTransportP2PMatrix |
Beacon P2P implementation which uses Matrix for the communication | BeaconCore |
✖️ |
Demos provide examples of how to use the library.
Module | Description |
---|---|
BeaconSDKDemo |
Example application |
The snippets below show how to quickly setup listening for incoming Beacon messages.
For more examples please see our demo
app (WIP).
import BeaconCore
import BeaconBlockchainSubstrate
import BeaconBlockchainTezos
import BeaconClientWallet
import BeaconTransportP2PMatrix
class BeaconController {
private var client: Beacon.WalletClient?
...
func startBeacon() {
Beacon.WalletClient.create(
with: Beacon.Client.Configuration(
name: "My App",
blockchains: [Tezos.factory, Substrate.factory],
connections: [try Transport.P2P.Matrix.connection()]
)
) { result in
switch result {
case let .success(client):
self.client = client
self.listenForBeaconMessages()
case let .failure(error):
/* handle error */
}
}
}
func listenForBeaconMessages() {
client?.connect { result in
switch result {
case .success(_):
self.client?.listen { request in
/* process messages */
}
case let .failure(error):
/* handle error */
}
}
}
}
See the below guides to learn how to migrate your existing code to new Beacon iOS SDK
versions.
As of v3.0.0
, Beacon iOS SDK
has been further split into new packages and has become more generic in terms of supported blockchains and transports. This means that in some parts the values that had been previously set by default now must be configured manually or that various structures have changed their location or definition. To make sure your existing Beacon integration will be set up the same way as it used to be before v3.0.0
do the following:
- Replace the old
Beacon.Client
with the newBeacon.WalletClient
(BeaocnClientWallet
) and configure it withTezos
blockchain (BeaconBlockchainTezos
) andTransport.P2P.Matrix
transport (BeaconTransportP2PMatrix
).
import BeaconCore
import BeaconBlockchainTezos
import BeaconClientWallet
import BeaconTransportP2PMatrix
/* <v3.0.0: Beacon.Client.create(with: Beacon.Client.Configuration(name: "My App")) { ... } */
Beacon.WalletClient.create(
with: Beacon.Client.Configuration(
name: "My App",
blockchains: [Tezos.factory],
connections: [try Transport.P2P.Matrix.connection()]
)
) { /* ... */ }
- Adjust the message handling code.
/* <v3.0.0:
* beaconClient.listen { result in
* switch result {
* case let .success(beaconRequest):
* switch beaconRequest {
* case let .permission(permission):
* ...
* case let .operation(operation):
* ...
* case let .signPayload(signPayload):
* ...
* case let .broadcast(broadcast):
* ...
* }
* ...
* }
* }
*/
beaconClient.listen { (result: Result<BeaconRequest<Tezos>, Beacon.Error>) in
switch result {
case let .success(beaconRequest):
switch beaconRequest {
case let .permission(content):
/* ... */
case let .blockchain(blockchain):
switch blockchain {
case let .operation(operation):
/* ... */
case let .signPayload(signPayload):
/* ... */
case let .broadcast(broadcast):
/* ... */
}
}
}
/* ... */
}
/* <v3.0.0
* let response = Beacon.Response.Operation(from: operationRequest, transactionHash: transactionHash)
* beaconClient.respond(with: .operation(response)) { ... }
*/
let response = OperationTezosResponse(
from: operationRequest, //: OperationTezosRequest
transactionHash: transactionHash
)
beaconClient.respond(
with: BeaconResponse<Tezos>.blockchain(
.operation(response)
)
) { /* ... */ }
/* let errorResponse = Beacon.Response.Error(from: broadcastRequest, errorType: .broadcastError)
* beaconClient.respond(with: BeaconResponse<Tezos>.error(errorResponse)) { ... }
*/
let errorResponse = ErrorBeaconResponse<Tezos>(from: broadcastRequest, errorType: .blockchain(.broadcastError))
beaconClient.respond(with: BeaconResponse<Tezos>.error(errorResponse)) { /* ... */ }
Beacon SDK - an SDK for web developers
Beacon Android SDK - an SDK for Android developers
Beacon Flutter SDK - an SDK for Flutter developers