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-connect-react

v0.6.6

Published

Web3-connect-react is a React library for seamless blockchain wallet integration across multiple networks. It provides ready-made hooks and components for connecting popular wallets like MetaMask, OKX, Phantom, and WalletConnect, with support for custom

Downloads

896

Readme

web3-connect-react

Web3-connect-react is a React library for seamless blockchain wallet integration across multiple networks. It provides ready-made hooks and components for connecting popular wallets like MetaMask, OKX, Phantom, and WalletConnect, with support for custom wallet providers. The library simplifies Web3 interactions by managing wallet connections, network switching, and smart contract calls through a unified API. Just wrap your app with WalletContextProvider to access its complete functionality across your React components.

Online Demo: https://web3-connect.pagepreview.dev

Features

  • Multiple chains support
  • Multiple wallet support
    • MetaMask
    • OKX
    • Phantom
    • WalletConnect
    • Custom providers
  • Smart contract interaction
  • Network switching
  • Send transactions
  • Event listeners (on network change, on account change)

Installation

  
pnpm install web3-connect-react

Usage

Wrap your application with the WalletContextProvider and EnvironmentProvider.

<EnvironmentProvider>
    <WalletContextProvider
        session={session}
        walletConnectConfig={WalletConnectConfig}
    >
        {children}
    </WalletContextProvider>
</EnvironmentProvider>

Use the sdk

Sign In

import { useWallet } from "web3-connect-react";

const { signIn, isSignedIn } = useWallet();

await signIn(providerName, {
    onSignedIn: async (walletAddress, provider, session) => {
        sessionStorage.setItem("session", JSON.stringify(session));
        router.refresh();
    },
    getSignInData: async () => {},
});

Sign Out

import { useWallet } from "web3-connect-react";

const { signOut } = useWallet();

await signOut();

Call a Contract

import { useWallet } from "web3-connect-react";

const { sdk } = useWallet();

// deploy
const address = await sdk
    .deployContract({
        abi,
        bytecode,
    });

// call
const result = await sdk.callContractMethod({
    contractAddress,
    abi,
    method: "balanceOf",
    params: [walletAddress],
})

Implementing a Custom Provider

Implementing a custom provider is straightforward; you simply need to extend the BaseProvider class. Below is an illustrative example of a MetaMaskProvider.

export class MetaMaskProvider extends BaseProvider {
    // MetaData is used to display information about the provider in the modal
    metadata: MetaData = {
        name: "MetaMask",
        image: <MetaMaskIcon/>,
        description:
            "Connect using a browser plugin or mobile app. Best supported on Chrome or Firefox.",
        displayName: "MetaMask",
        notInstalledText:
            "Dear friend, If you don't have a wallet yet, you can go to install MetaMask and create one now.",
        downloadLink: "https://metamask.io/",
    };

    // The rdns is used to identify the provider using the EIP-6963 event
    rdns: string = "io.metamask";

    constructor(globalWindow: any) {
        super(globalWindow);
    }

    init() {
        if (this.globalWindow === undefined) {
            return;
        }
        // get the provider from the EIP-6963 event
        this.globalWindow.addEventListener(
            "eip6963:announceProvider",
            (event: any) => {
                const eipEvent = event as EIP6963AnnounceProviderEvent;
                if (eipEvent.detail.info.rdns === this.rdns) {
                    this.provider = eipEvent.detail.provider;
                }
            }
        );
        this.globalWindow.dispatchEvent(new Event("eip6963:requestProvider"));
    }
}

Testing

pnpm test