SDK APIs
Modern SDK tools to help you access imToken's public APIs.
Last updated
Modern SDK tools to help you access imToken's public APIs.
Last updated
With the @consenlabs-fe/webview
, you can easily access and use the various interfaces built into the imToken WebView environment. Whether you're migrating a DApp to imToken or adapting a Web application, you can quickly solve it with minimal code and minimal invasiveness.
The SDK includes functions to obtain the language environment, common native UI, route navigation, scan QR codes, etc. The SDK itself does not contain dependencies and is only used as a tool to bond the host environment and will not cause any invasive damage to your project.
All interfaces and methods have full type support.
In modern front-end projects, the esm
mode is used by default, but we also provide cjs
umd
and ways.
Based on v1, all our asynchronous interfaces support promise by default.
We've added support for the community, where you can create a discussion for any questions about the API or tools.
If you are looking for a complete project example, please check out the sample applications we have prepared:
React project sample: examples/react-app
Vue project sample: examples/vue-app
UMD project sample: examples/umd
You can use the package management tool to install @consenlabs-fe/webview
, this is the recommended way. For this, your project may need the NodeJS environment with the NPM management tool. (or Yarn)
NPM: (recommended installation)
Yarn:
CDN:
@consenlabs-fe/webview
is available on unpkg and jsdelivr. (the CDN may require some time synchronization, please note the version you are using)
Before you can use it, you need to import
the module:
As a suggestion to maintain compatibility, we recommend that you always check the current environment first:
All API interfaces, types, and examples are listed here. In fact, if you are using TypeScript, you can already get good type hints in your project.
This is the API that comes with the root module and is usually used to check the environment and the processing of generic scenarios.
Check if the current context is imToken WebView and return a boolean value.
Types
Usage Example
Get the current version of the imToken App.
Types
Usage Example
The current App version is greater than or equal to the specified value.
Types
Usage Example
Compare the two versions of the value and return the number.
Requires that the comparison value must be a semantic version of the string. The return value rules are the same as for the JavaScript sort function.
Types
Usage Example
Check if the current error was caused by a user cancellation.
Types
Usage Example
Error constants. The source of the error message, most of the time you do not need to compare this constant.
Types
API for communicating with the host environment, please see below for details.
Get the current language environment, which usually comes from the user's settings within the imToken application.
Types
Usage Example
Get the current currency, returns the currency string.
Types
Usage Example
Provide native platform UI and interaction capabilities.
Display the string as an alert box.
Types
Usage Example
Display the string as a confirm box.
A user clicks on the confirm or cancel button action will be returned as a Boolean value.
Types
Usage Example
Set the entire WebView to the loading state.
If you do not actively cancel this status, users will not be able to operate. The loaded state will block all interactive events.
Types
Usage Example
Share a link or picture.
If the shared content is an image, it needs to be pre-converted to base64
format.
The success of the sharing depends on the user's confirmation and whether the user allows permissions.
Types
Usage Example
Evoke the camera to scan the QR code, if the scan is successful, the parsed string will be returned.
Types
Usage Example
Filling the user's clipboard with strings.
Types
Usage Example
Routing navigation and settings page.
Close the current DApp.
Types
Usage Example
Returns the previous level of routing, or closes the app if there is no routing stack.
Types
Usage Example
Navigate to a specific screen.
Types
Usage Example
Get the direction of the current device.
Types
Usage Example
Set the orientation of the current device, which can be very helpful when playing multimedia messages.
Types
Usage Example
Dynamically set DApp title. No effect to document.title
.
Types
Usage Example
Show switchable user wallets. If the switch is successful, the new address will be returned.
Types
Usage Example
Set the frame layout style of the WebView.
This updates the layout of the current WebView synchronously and can only be applied after the page has been loaded and parsed. If you want to make changes to the layout while the page is loading, please refer to our preload configuration documentation.
Types
Usage Example
Unstable API, mainly for advanced user custom development and debugging.