# dAPI Integration

Integrating the `dAPI` is practically equivalent to integrating the `Provider SDK`. The `Provider SDK` encapsulates methods for `iOS/Android webview`, and supports communication between web based `dApps` and `iOS/Android webview`.

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvPYTBbYX4L3mHx0vBh%2F-LvPYVGeMfZeV9Z6pqe1%2Fwalletintegration-providersdk.jpg?generation=1575624772405096\&alt=media)

{% hint style="info" %}
For the `dAPI` method handbook for both **Android** and **iOS** operating systems, please follow this [link](https://docs.ont.io/developer-tools/cyano-wallet/mobile-version-provider).
{% endhint %}

## dAPI usage scenarios

Mobile version of `dAPI` can allow the wallet to perform the following features based on `dApp` scenarios-

* `dApps` are launched **in the wallet**
* Wallet scans **QR codes**
* Applications **wake the wallet**

### dApps open in the wallet

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvPYTBbYX4L3mHx0vBh%2F-LvPYVGg7rrDr22ZP-kF%2Fdapp-wallet-interaction-flow-2.svg?generation=1575624772221381\&alt=media)

The execution process is as follows:

1. The `dApp` is opened in the wallet
2. Account or identity information is fetched
3. `dApp` logs in
4. `dApp` invokes smart contract

### Wallet scans a QR code

#### Login Process

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvskKw8s9Pwh0-imBPd%2F-LvskNjGjutt26ec-DER%2Fdappintegration-qrcode-login-1.jpg?generation=1576131467839683\&alt=media)

The execution process is as follows:

1. Wallet scans the QR code provided by the `dApp`
2. Provider receives the `callback URL` and verification message, user authenticates and signs the message, the message is sent to the `callback URL` provided.
3. `dApp` back end carries out the verification process for the message.

#### Invoking a smart contract

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvskKw8s9Pwh0-imBPd%2F-LvskNjIdhgQ-1Uzskbs%2Fdappintegration-qrcode-sc-2.jpg?generation=1576131467844165\&alt=media)

The execution process is as follows:

1. Wallet scans the QR code provided by the `dApp`
2. Wallet initiates the transaction, the user authenticates and signs, the contract is pre-executed, user confirms, transaction is transmitted to the blockchain, transaction `hash` is returned to the callback address
3. `dApp` back end queries transaction event

### dApp wakes the wallet

#### dApp sends a login request

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvPYTBbYX4L3mHx0vBh%2F-LvPYVF-9hNyFlZbhBQg%2Fdappintegration-wake-login-1.jpg?generation=1575624772977214\&alt=media)

1. `dApp` sends the wake call to the wallet
2. Wallet fetches the `callback URL` and the verification message, user enter authenticates and signs the message, wallet returns the signature to the callback address
3. `dApp` back end verifies the message

#### dApp sends an invocation request

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvPYTBbYX4L3mHx0vBh%2F-LvPYVF145l4fEBoJNQ1%2Fdappintegration-wake-transaction-1.jpg?generation=1575624772979788\&alt=media)

1. `dApp` sends the wake call to the wallet
2. Wallet initiates the transaction, the user authenticates and signs, wallet pre-executes the transaction, the transaction is transmitted to the blockchain, the transaction `hash` is returned to the `callback` address
3. `dApp` back end queries the transaction event on the blockchain using the transaction `hash`

## Demonstration

Here is a basic demonstration of some of the basic functions that the wallet can perform. A demo wallet which can be downloaded using the link below has been used to mimic a second party.

{% hint style="info" %}
**H5 demo dApp source code:** <https://github.com/ontio-cyano/mobile-dapp-demo>

**H5 demo dApp link:** <http://101.132.193.149:5000/#/>

**Cyano wallet mobile version (Android):** <http://101.132.193.149/files/app-debug.apk>

**Cyano wallet source code(Android):** <https://github.com/ontio-cyano/cyano-android>

**Cyano wallet source code(iOS):** <https://github.com/ontio-cyano/cyano-ios>
{% endhint %}

After completing the installation of `Cyano` wallet and the demo app, features of both the wallets can be tested along with the source code as reference.

Transactions can be performed to test smart contract logic and confirming whether or not the platform has been integrated successfully.

### 1. Open a dApp in the wallet

Launch Cyano wallet and access the "DApp" section. Open the "PRIVATE APPS" tab and input this address to access the demo `dApp`: <http://101.132.193.149:5000/#/>

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvPYTBbYX4L3mHx0vBh%2F-LvPYVHWXWguUuqprpJV%2Fdapp_integration_comb1.jpg?generation=1575624772718223\&alt=media)

### 2. Fetch Account or Identity Information

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvPYTBbYX4L3mHx0vBh%2F-LvPYVGsMXp1SybViifo%2Fdapp_integration_demo1.jpg?generation=1575624772307409\&alt=media)

Clicking on the Get Identity button will directly fetch the `ONT ID` of the account. Enter the password when prompted and the ID will appear in the blank field below. You can carry out the authorization/KYC by uploading your document information, for e.g, passport number, picture of the first page, etc.

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvskKw8s9Pwh0-imBPd%2F-LvskNjQ4LxRdWpCwV6P%2Fdapp_integration_demo5-1.jpg?generation=1576131467746801\&alt=media)

### 3. Login into the dApp

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvPYTBbYX4L3mHx0vBh%2F-LvPYVHbk6XX6Qu8W0Bt%2Fdapp_integration_comb4.jpg?generation=1575624772824922\&alt=media)

In case there is a need to verify the user's identity, `dApp` sends a message to the wallet to carry out the signature process, and then verifies the signature.

As illustrated above, the wallet prompts the user to enter the password. Once confirmed, the contract related details can be accessed.

### 4. dApp Contract Deployment

![](https://1077617372-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvPXC4l2V4Z8gRDNIoZ%2F-LvPYTBbYX4L3mHx0vBh%2F-LvPYVGySVtuJFquTfzo%2Fdapp_integration_comb5.jpg?generation=1575624772350180\&alt=media)

The contract deployment process involves the following steps:

1. After the signature verification is completed successfully, the contract is pre-processed.
2. The user confirms and transmits the transaction via the wallet.
3. The `hash` value of the transaction is returned to the `dApp`.
