@dioxide-js/detect-provider
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

@dioxide-js/detect-provider

A tiny utility for detecting the Dioxide-wallet provider which injected at window.dioxide after install the diox-wallet chrome extension.

Usage

ES Module

Install

$ yarn add @dioxide-js/detect-provider
import detectDioxideProvider from '@dioxide-js/detect-provider'

const provider = await detectDioxideProvider()

if (provider) {

  console.log('dioxide successfully detected!')

  // From now on, this should always be true:
  // provider === window.dioxide

  // Access the decentralized web!

  const chainId = await provider.request({
    method: 'diox_chainId'
  })
} else {

  // if the provider is not detected, detectDioxideProvider resolves to null
  console.error('Please install Dioxide-Wallet!', error)
}

HTML

<script src="https://unpkg.com/@dioxide-js/detect-provider/dist/detect-provider.umd.js"></script>
<script type="text/javascript">
  const provider = await dioxideDetectProvider({timeout: 3000})
  if (provider) {
    // handle provider
  } else {
    // handle no provider
  }
</script>

Options

options.timeout

Type: number
Default: 3000
Milliseconds to wait for asynchronously injected providers.

Dependencies (0)

    Dev Dependencies (31)

    Package Sidebar

    Install

    npm i @dioxide-js/detect-provider

    Weekly Downloads

    12

    Version

    0.0.8

    License

    MIT

    Unpacked Size

    31.9 kB

    Total Files

    18

    Last publish

    Collaborators

    • czr
    • hyzheng
    • 189