1.0.12 • Published 4 years ago

@chainx/signer-connector v1.0.12

Weekly downloads
15
License
MIT
Repository
-
Last release
4 years ago

@chainx/signer-connector is used for connecting and interacting with ChainX signer.

Installation

npm install @chainx/signer-connector

Or

yarn add @chainx/signer-connector

How to use

import Connector from '@chainx/signer-connector'

// Create the signer connector instance
const connector = new Connector('dapp')

;(async () => {
  try {
    await connector.link()
  } catch (e) {
    // handle the linking failure case
  }

  // Get current account from signer. If the returned value is not empty, then it have `name` and `address` fields.
  const account = await connector.getCurrentAccount()

  // Get current node from signer. The returned value have `name` and `url` fields.
  const node = await connector.getCurrentNode()

  function accountChangeListener({ from, to }) {
    // `to` is the changed account, you may set this account to your dapp
  }

  function nodeChangeListener({ from, to }) {
    // `to` is the changed node, you may re-init the ChainX instance with this node
  }

  function networkChangeListener({ from, to }) {
    // `to` is the changed network, you may restart your dapp with this network
  }

  connector.listenAccountChange(accountChangeListener)
  connector.listenNodeChange(nodeChangeListener)
  connector.listenNetworkChange(networkChangeListener)

  // Make sure to remove the listener when you don't need them
  connector.removeAccountChangeListener(accountChangeListener)
  connector.removeNodeChangeListener(nodeChangeListener)
  connector.removeNetworkChangeListener(networkChangeListener)
})()
1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago