npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web3-wallet-connection

v1.0.4

Published

This package is built upon [ThirdWeb](https://thirdweb.com/) & [Alchemy](https://www.alchemy.com/sdk) SDKs, it simplifies the process of Connecting your wallet and Sign In With Ethereum to verify the wallet ownership in your application.

Downloads

14

Readme

web3-wallet-connection

This package is built upon ThirdWeb & Alchemy SDKs, it simplifies the process of Connecting your wallet and Sign In With Ethereum to verify the wallet ownership in your application.

Installation

using NPM

npm install web3-wallet-connection

using YARN

yarn add web3-wallet-connection

Usage

Setting Up the Wallet Provider

First, wrap your application with the WalletProvider & ThirdwebProvider to provide wallet context throughout your app.

//_app.tsx

import { WalletProvider } from 'web3-wallet-connection';

function App() {
    return(
        <WalletProvider>
            <ThirdwebProvider>
                <App />
            </ThirdwebProvider>
        </WalletProvider>
    )
}

Connect Wallet

To connect the wallet in you DAPP, You can use the ConnectWallet component

import { ConnectWallet } from 'web3-wallet-connection';

<ConnectWallet
    theme="light"
    auth={{ loginOptional: false }}
    btnTitle="Connect Your Wallet"
    showThirdwebBranding={false}
    onConnect={async (wallet) => {
        //after successful connection of wallet this callback will be trigered
        //here you can use the react state to manage the stuff in your app

        setWalletConnected(true);
        setShowConnectedWallets(true);
    }}
/>

Using the Wallet Context

To access and manipulate the wallet context, use the useWallet hook.

// ExampleComponent.jsx

import React from 'react';
import { useWallet } from 'web3-wallet-connection';

const ExampleComponent = () => {
  const {
    walletConnected,
    setWalletConnected,
    currentlyConnectedWallet,
    setCurrentlyConnectedWallet,
    // ...other state variables and setters
  } = useWallet();

  return (
    <div>
      <p>Wallet Connected: {walletConnected.toString()}</p>
      <button onClick={() => setWalletConnected(!walletConnected)}>
        Toggle Wallet Connection
      </button>
      {/* Add more UI components and handlers as needed */}
    </div>
  );
};

export default ExampleComponent;

Wallet Actions & Hooks

There are some wallet actions that you can do

Sign In With Etherium

import { useWalletActions } from "web3-wallet-connection";

//inside your component after connecting the wallet, call this function to trigger the sign In with etherium process

const { createMessageAndSign } = useWalletActions();
createMessageAndSign();

useAddress hook

useAddress is a Hook provided by Thirdweb to get the connected wallet address

import { useAddress } from "web3-wallet-connection";

//If wallet is connected you can get the wallet address like this

const address = useAddress();

Wallet connection Status

useConnectionStatus is a Hook you can use to get the wallet connection status in realtime

It can be one of the following:

  • unknown: connection status is not known yet. This is the initial state.
  • connecting: wallet is being connected. Either because of a user action, or when the wallet is auto-connecting on page load.
  • connected: the wallet is connected and ready to be used.
  • disconnected: the wallet is not connected.
import { useConnectionStatus } from "web3-wallet-connection";

//inside your component

const connectionStatus = useConnectionStatus();


if (connectionStatus === "connected") {

    //wallet is connected

} else if(connectionStatus === "disconnected"){

    //wallet is disconnected

}

...

Disconnect Wallet

useDisconnect is the Hook you can use to disconnect the wallet manually

import { useDisconnect } from "web3-wallet-connection";

const disconnect = useDisconnect();

disconnect();

Get ENS of Wallet

We have some functions from Alchemy SDK, to get the ENS of the wallet Address and get the Wallet Address of an ENS

lookUpENS can be used to get the Ens of the Wallet address. resolveENS can be used to get the Address associated to the ENS.

import { resolveENS, lookUpENS } from "web3-wallet-connection";

const ensName = await lookUpENS(address, ALCHEMY_API_KEY);

const walletAddress = await resolveENS(ensName, ALCHEMY_API_KEY);

You can get the Alchemy API key from here