0.0.25 • Published 3 years ago

@gimmixfactory/use-wallet v0.0.25

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

✵useWallet✵

An easy-to-integrate, React hook for connecting and interacting with a Web 3 wallet.

Uses Web3Modal and Zustand.

Example Connect / Disconnect button

const ConnectWalletButton = () => {
  const { account, connect, disconnect } = useWallet();
  return <>
      {!account ? (
        <button onClick={() => connect()}>Connect Wallet</button>
      ) : (
        <button onClick={() => disconnect()}>Disconnect Wallet</button>
      )}
    </>;
}

The connect function passes along an optional config to a Web3Modal instance for additional customization.

You can use the account information from useWallet anywhere inside your React app, without any extra set up.

const UserAddress = () => {
  const { account } = useWallet();
  if (!account) return null;
  return <>{account}</>;
}

To run a transaction or sign a message, use the provider object returned by the hook for connected wallets. This is a standard Ether.js Provider.

const SignMessageButton = () => {
  const { account, provider } = useWallet();
  if (!account) return null;
  const signMessage = async () => {
    const signature = await provider.getSigner().signMessage("Hello!");
    console.log(signature);
  }
  return <button onClick={signMessage}>Sign Message</>;
}
0.0.25

3 years ago

0.0.24

3 years ago

0.0.22

3 years ago

0.0.23

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.15

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.19

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago