@use-web3wallet/ethereum
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

useEtherWallet

Usage

  1. Install @use-web3wallet/ethereum
yarn add @use-web3wallet/ethereum
// or
npm install --save @use-web3wallet/ethereum
  1. Add EtherWalletProvider to your DApp
import { EtherWalletProvider } from "@use-web3wallet/ethereum";

// If you don't use a WalletConnect, you don't need to import it.
import WalletConnectProvider from "@walletconnect/web3-provider"; 

const walletOptions = {
  // Similarly, if you don't use a WalletConnect, please ignore this option
  walletConnectProvider: new WalletConnectProvider({
    // https://docs.walletconnect.com/quick-start/dapps/web3-provider#required
  }),
};

const Index = () => {
  return(
    <EtherWalletProvider walletOptions={walletOptions}>
      ...
    </EtherWalletProvider>
  );
}
  1. Use a useEtherWallet hook
import { useEtherWallet } from "@use-web3wallet/ethereum";

const Page = () => {
  const {
    connectTo,
    disconnect,
    isLoading,
    provider,
    currentWallet,
    chainId,
    account,
    isWalletConnected,
  } = useEtherWallet();

  return (
    <>
      {!isLoading && (
        <>
          {!isWalletConnected ? (
            <>
              <button type="button" onClick={() => connectTo("MetaMask")}>
                MetaMask
              </button>

              <button type="button" onClick={() => connectTo("WalletConnect")}>
                Wallet Connect
              </button>
            </>
          ) : (
            <button type="button" onClick={disconnect}>
              Disconnect
            </button>
          )}
        </>
      )}
    </>
  );
};

Package Sidebar

Install

npm i @use-web3wallet/ethereum

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

158 kB

Total Files

23

Last publish

Collaborators

  • ryz0nd