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

2.0.3 • Public • Published

@deficonnect/provider

Installation

use npm package manager

here's an full example of how to use this package: dapp-connect-provider-example

npm install "@deficonnect/provider"

use script tag

<script type="module" src="https://unpkg.com/@deficonnect/provider/dist/index.umd.js"></script>

the global variable is: DeFiConnectProvider

constructor

import { DeFiConnectProvider } from '@deficonnect/provider'

const provider = new DeFiConnectProvider({
  appName: 'your app name',
  chainType: 'eth', // currently support 'eth' | 'cosmos'
  chainId: '25', // for eth is 1
  rpcUrls: {
    1: 'https://mainnet.infura.io/v3/INFURA_API_KEY',
    25: 'https://evm-cronos.crypto.org/',
  },
})

if you want to support cosmos like chain, please read: @deficonnect/cosmos-signer cosmos support: docs

Provider(EIP-1193)

interface RequestArguments {
 method: string;
 params?: unknown[] | object;
}

// Send JSON RPC requests
const result = await provider.request(payload: RequestArguments);

// Close provider session
await provider.close()

events for Provider (EIP-1193)

// Subscribe to accounts change
provider.on('accountsChanged', (accounts: string[]) => {
  console.log(accounts)
})

// Subscribe to chainId change
provider.on('chainChanged', (chainId: number) => {
  console.log(chainId)
})

// Subscribe to session connection
provider.on('connect', () => {
  console.log('connect')
})

// Subscribe to session disconnection
provider.on('disconnect', (code: number, reason: string) => {
  console.log(code, reason)
})

Functions

Parameters Description Type Exmaple Default
disconnect () => Promise<void> await provider.disconnect() -

Event

Parameters Description Type Exmaple Default
accountsChanged (account: string[]) => void -
chainChanged (chainId: number) => void -
connect () => void
disconnect (code: number, reason: string) => void

Readme

Keywords

none

Package Sidebar

Install

npm i @deficonnect/provider

Weekly Downloads

607

Version

2.0.3

License

Apache-2.0

Unpacked Size

533 kB

Total Files

10

Last publish

Collaborators

  • cryptocom