0.1.3 • Published 2 years ago

@marcotommoro/react-ethereum-auth-hook v0.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago
*** DEVELOPMENT IN PROGRESS ***
*** Please contact me for bugs ***

Next / React Ethereum Auth Hook

Implements metamask functions:

  1. connect wallet
  2. get address
  3. change network

Implements web3-auth function from library

  1. get signed token

Install

npm i @marcotommoro/react-ethereum-auth-hook

Add to project

  1. add EthereumContextProvider to _app.tsx: | param | type | default | :---: | :---: | :---: | | autoCheckCorrectNetwork auto check that the network is always the same as the one specified in the .env (or 0x1 by default) | boolean | true| | | |
 import { EthereumContextProvider } from "@marcotommoro/react-ethereum-auth-hook";


 function MyApp({ Component, pageProps }: AppProps) {
     return (
         <EthereumContextProvider autoCheckCorrectNetwork={true}>
           ...
           <Component {...pageProps} />
           ...
         </EthereumContextProvider>
     );
 }
  1. useEthereum in a react/next component:

     const {
         address,
         currentNetwork,
         isMetamaskInstalled,
         isNetworkCorrect,
         connect,
         correctNetwork,
         getToken,
     } = useEthereum();
  2. (optional) set env NEXT_PUBLIC_NETWORK_ID with your testnet id. Default Ethereum mainnet 0x1. Check networks id on Metamask documentation

Instructions

keyvalue
addressCurrent metamask address selected.
currentNetworkCurrent network selected.
isMetamaskInstalledCheck if window.ehtereum is present.
isNetworkCorrectCheck if is the correct network. If process.env.NEXT_PUBLIC_NETWORK_ID is not present, the default network is Ethereum mainnet ('0x1')
connectAsk user to connect your beautiful react app with metamask extension.
correctNetworkAsk user permission to switch to the right network.
getTokenAsk user to sign a transaction and get a signed token to use in a backend server to validate the user is really him/her/it.
0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.3

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago