Link Search Menu Expand Document

Dapp browser API usage

Table of Contents

  1. Abstract
  2. Definitions
  3. Overview
  4. Usage
  5. Implementation
  6. Compatibility
  7. Changelog
  8. Copyright

Abstract

This document describes requirements that an application must fulfill in order to provide a proper environment for Dapps running inside a browser. A description of the Status Dapp API is provided, along with an overview of bidirectional communication underlying the API implementation. The document also includes a list of EIPs that this API implements.

Definitions

Term Description
Webview Platform-specific browser core implementation.
Ethereum Provider A JS object (window.ethereum) injected into each web page opened in the browser providing web3 compatible provider.
Bridge A set of facilities allow bidirectional communication between JS code and the application.

Overview

The application should expose an Ethereum Provider object (window.ethereum) to JS code running inside the browser. It is important to have the window.ethereum object available before the page loads, otherwise Dapps might not work correctly.

Additionally, the browser component should also provide bidirectional communication between JS code and the application.

Usage in Dapps

Dapps can use the below properties and methods of window.ethereum object.

Properties

isStatus

Returns true. Can be used by the Dapp to find out whether it’s running inside Status.

status

Returns a StatusAPI object. For now it supports one method: getContactCode that sends a contact-code request to Status.

Methods

isConnected

Similarly to Ethereum JS API docs, it should be called to check if connection to a node exists. On Status, this fn always returns true, as once Status is up and running, node is automatically started.

scanQRCode

Sends a qr-code Status API request.

request

request method as defined by EIP-1193.

Unused

Below are some legacy methods that some Dapps might still use.

enable (DEPRECATED)

Sends a web3 Status API request. It returns a first entry in the list of available accounts.

Legacy enable method as defined by EIP1102.

send (DEPRECATED)

Legacy send method as defined by EIP1193.

sendAsync (DEPRECATED)

Legacy sendAsync method as defined by EIP1193.

sendSync (DEPRECATED)

Legacy send method.

Implementation

Status uses a forked version of react-native-webview to display web or dapps content. The fork provides an Android implementation of JS injection before page load. It is required in order to properly inject Ethereum Provider object.

Status injects two JS scripts:

Dapps running inside a browser communicate with Status Ethereum node by means of a bridge provided by react-native-webview library. The bridge allows for bidirectional communication between browser and Status. In order to do so, it injects a special ReactNativeWebview object into each page it loads.

On Status (React Native) end, react-native-webview library provides WebView.injectJavascript function on a webview component that allows to execute arbitrary code inside the webview. Thus it is possible to inject a function call passing Status node response back to the Dapp.

Below is the table briefly describing what functions/properties are used. More details available in package docs.

Direction Side Method
Browser->Status JS ReactNativeWebView.postMessage()
Browser->Status RN WebView.onMessage()
Status->Browser JS ReactNativeWebView.onMessage()
Status->Browser RN WebView.injectJavascript()

Compatibility

Status browser supports the following EIPs:

  • EIP1102: eth_requestAccounts support
  • EIP1193: connect, disconnect, chainChanged, and accountsChanged event support is not implemented

Changelog

Version Comment
0.1.0 Initial Release

Copyright and related rights waived via CC0.