Skip to content

UIKeyringProvider

The UIKeyringProvider is the provider implementation that works with browser wallet extensions.

This provider has been tested with following wallet extensions:

Usage

import { UIKeyringProvider } from '@phala/sdk'
 
const availableWallets = await UIKeyringProvider.getSupportedWallets()
const accounts = await UIKeyringProvider.getAllAccountsFromProvider('My dApp', availableWallets[0].name)
const provider = await UIKeyringProvider.create(client.api, 'My dApp', availableWallets[0].name, accounts[0])

create

Get a provider instance and connected to the browser wallet extension.

Parameters

api

ApiPromise

appName

string

The name of your dApp, it will use for the permission request from the wallet extension.

providerName

string

The name of the wallet extension that you want to connect to. It should be one of the supported wallets (alphabet order):

  • polkadot-js
  • subwallet-js
  • talisman

account

InjectedAccount

Learn more about the InjectedAccount from the polkadot-js documentation.

Returns

Promise<UIKeyringPairProvider>

getSupportedWallets

Fetch the supported wallet extensions and check if they're installed.

Usage

import { UIKeyringProvider } from '@phala/sdk'
 
const wallets = await UIKeyringProvider.getSupportedWallets()

Returns

Promise<SupportedWallet[]>

The SupportedWallet is a plain object with following properties:

  • key: string. A readable name for the wallet extension.
  • name: string. The registered namespace to lookup in window.injectedWeb3 object.
  • icon: string. The SVG format icon in based64 string.
  • downloadUrl: string. The download URL for the wallet extension.
  • installed: boolean. The installation state of the wallet extension.
  • version: string. The version of the wallet extension.

getAllAccountsFromProvider

Get all accounts from specified wallet extension.

Usage

import { UIKeyringProvider } from '@phala/sdk'
 
const accounts = await UIKeyringProvider.getAllAccountsFromProvider('My dApp', 'polkadot-js')

Parameters

appName

string

The name of your dApp, it will use for the permission request from the wallet extension.

providerName

string

The registered namespace of the wallet extension. You can get it with SupportedWallet.name.

Returns

Promise<InjectedAccount[]>

A list of InjectedAccount instances from the wallet extension, they should be the wallets that the user allows to connect to your dApp.