Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

web3-react-hooks

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-react-hooks

React hooks that interact with web3 systems like Metamask.

latest
Source
npmnpm
Version
0.0.13
Version published
Maintainers
1
Created
Source

Web3 React Hooks

A set of convenience hooks for web3 actions in react.

Usage

Install using npm or yarn:

npm i -S web3-react-hooks

This module has react as a peer dependency, since it provices react hooks 🤷‍♂️

Example usage:

import React from 'react'
import { useAddress, useENS } from 'web3-react-hooks'

export default function UserProfile() {

    const address = useAddress()
    const ens = useENS()

    return <p>Welcome back { address.slice( 0, 10 ) }! { ens ? `Your ENS name ${ ens } looks good!` : `You should get a fancy ENS ;)` }</p>


}

Available hooks

All hooks have jsdoc declarations you can use to get more details on what they do.

Useful frontend hooks

  • useAddress: last known selected address
  • useENS: ENS address of currently connected account on currently connected network
  • useAvatar: returns uri of the current ENS avatar

Chain/wallet

  • useIsConnected: whether or not the Ethereum provider is connected to its RPC
  • useChainID: chain ID as hex value, e.g. 0x01 is Ethereum Mainnet

Generic interfaces

  • useProvider: get an ethers.js provider instance, see the ethers provider documentation for what you can do with it
  • useResolver: returns the resolver of the current ENS, see the ethers resolver documentation for what you can do with it

For a more elaborate demo, run npm start inside the demo directory.

Feature requests

Do you need a hook not in this list? Suggest a feature here.

Contributing

Pull requests are welcome! If you want to implement backwards-incompatible changes please check in first.

Keywords

web3

FAQs

Package last updated on 19 Aug 2022

Did you know?

Socket

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