0.2.8 • Published 3 years ago

use-onboard v0.2.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

useOnboard()

NPM NPM Bundle size

A React Web3 wallet hook for Onboard.js library.

Features

  • Fully configurable as much as Onboard itself
  • selectWallet and disconnectWallet functions to manage wallet state
  • Optional initialData to pass for initial address and balance values while wallet is loading

Install

pnpm i use-onboard

Example

CodeSandbox

import React from 'react'
import { useOnboard } from 'use-onboard'

const App = ({ initialData }) => {
  // in case you are authorized before this won't ask to login from the wallet
  const { selectWallet, address, isWalletSelected, disconnectWallet, balance } = useOnboard({
    options: {
      dappId: process.env.DAPP_ID, // optional API key
      networkId: 1 // Ethereum network ID
    },
    initialData // optional initial to data to pass while wallet is loading
  })

  return (
    <div>
      {
        <button
          onClick={async () => {
            if (isWalletSelected) disconnectWallet()
            else await selectWallet()
          }}>
          {isWalletSelected ? 'Disconnect' : 'Connect'}
        </button>
      }
      <p>Address: {address}</p>
      <p>Balance: {balance} ETH</p>
    </div>
  )
}
0.2.7

3 years ago

0.2.8

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.3

3 years ago

0.2.4

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.3

3 years ago

0.1.0

3 years ago

0.1.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago