Mobile wallet dApp
Launching the dApp inside the mobile wallet
Considering the current scenario, mobile wallets are an important channel of access to dApps
. After integrating Ontology's cyano-bridge
package, the developer can implement and invoke dAPI
that adheres to OEP-1 standards, and can communicate with any wallet dApp
that integrates the Provider SDK
to carry out chain-related operations.
Details regarding the OEP-1 protocol can be found here.
Fundamental concepts
Let us take a look at the processes that distributed technologies such as dApps
and mobile wallets carry out.
Role of dApps
The dApp
back end primarily carries out the following tasks:
dApp
operations, i.e., generating the relevant login parameters, or the parameters for invoking smart contracts.Synchronizing with the on-chain data, and fetching the results of login, or smart contract invocation.
Role of mobile wallets
A mobile wallet acts as a provider
. It carries out the roles that involve interacting with the chain, such as providing the signature data, pre-executing and executing transactions, etc.
The above description is with respect to the wallets that can serve as providers. Currently, the following are supported:
Interaction Process
Generally speaking, application users' primary concerns are the login and transaction procedure.
The process flow is illustrated in the following figure:
Login scenario
A
dApp
is opened in the wallet'sdApp
store.Next, there are two possible circumstances - either the
dApp
sends an account query request to the wallet, and the wallet returns the asset account's address, or thedApp
sends a login request to the wallet and the wallet returns signature data.If the
dApp
verification is completed, access is granted.
Smart Contract invocation scenario
The
dApp
sends an invocation request to the wallet.The wallet digitally signs the transaction, pre-executes it, sends it to the chain, and returns the transaction
hash
to thedApp
.
dAPI protocol usage
1. Installation
Based on subjective requirements, one of the following two methods can be chosen to install cyanobridge
.
npm installation-
CDN installation-
Currently, the latest version can be acquired using jsDelivr
. Paste the following script on the page's code to instantly start using the dAPI
.
CDN users are advised to fix the version in the above link so as to avoid compatibility issues during updates.
2. Import
CommonJS
ES6 module
Web Page Embed
To import the browser.js file inside the ./lib
directory:
3. Initialization
The dAPI
needs to be initialized and registered before being used.
4. Method Usage
Fetch account or user identity information
dApp
information is optional. The developer may choose not to fill it when making the function call.
Login
Login is signed on the wallet's end. The dApp
carries out the verification signature.
Invoke contract or initiate payment
Error codes
This is the list of error codes that the system returns.
An example of the code returned (JSON):
Code base for Reference
Last updated