Socket
Socket
Sign inDemoInstall

@dapperlabs/react-web3

Package Overview
Dependencies
1
Maintainers
6
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dapperlabs/react-web3

Context provider for interacting with injected web3.


Version published
Weekly downloads
2
increased by100%
Maintainers
6
Install size
1.05 MB
Created
Weekly downloads
 

Readme

Source

react-web3?

Context provider for interacting with injected web3.

values provided on context:

  • web3: the injected web3 instance
  • checkingForWeb3: boolean indicating whether still actively waiting for injection.
  • account: current user wallet address
  • network: current network id
  • requestAccounts: utility method for requesting the users accounts
  • getAccounts: utility method for accessing the user accounts
  • personalSign: utility method for performing a personal sign

Setup

Import the provider and wrap your application in it.

import { Web3Provider } from '@dapperlabs/react-web3'

function Root() {
  return (
    <Web3Provider>
      <MyDApp />
    </Web3Provider>
  )
}

Context

Context is directly available via import { Web3Context } from '@dapperlabs/react-web3 and can be consumed however you'd like:

  • useContext(Web3Context)
  • static contextType = Web3Context
  • <Web3Context.Consumer />

HOC (withWeb3)

Decorates your component with the above context values spread onto it.


<Web3Toolbar />

Utility component to drop into your app that will render the current values of the context properties.

import { Web3Toolbar } ...

function MyDapp() {
  return (
    <div>
      {process.env.NODE_ENV !== 'production' && (  
        <Web3Toolbar />
      )}
      <OtherStuff />
    </div>
  )
}

Hooks

If you'd rather not use the provider + context interface, you can use hooks directly in your components.
  • useInjectedWeb3()
  • useWeb3Status( true/false ) where the parameter indicates whether to poll for the status.
function () {
  const [web3, checkingForWeb3] = useInjectedWeb3();
  const [account, network] = useWeb3Status();
  ...
}

FAQs

Last updated on 01 Feb 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc