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

@e_labs/web3provider

v1.5.3

Published

web3 Provider for React Websites

Downloads

70

Readme

Web3 Provider

npm version

This project is a web3 provider for React websites. It allows you to interact with the Ethereum blockchain and various wallets such as Coinbase Wallet, MetaMask, and WalletConnect. It also includes a modal for connecting to a web3 provider.

## Features

  • Interact with the Ethereum blockchain using `@alch/alchemy-web3` and `ethers`. -
  • Connect to various wallets including Coinbase Wallet, MetaMask, and WalletConnect.
  • Display a modal for connecting to a web3 provider using `web3modal`.
  • Build user interfaces with `react` and `react-dom`.

Installation

To install the project, you need to have Node.js version 18.0.0 or higher and npm.

npm i e-labs_web3provider@latest

Usage

To use the Web3 Provider wrap the outter most page/componet in the provider gain access though out

<UserWeb3Provider allowedChains={["ETH_MAINNET","MATIC_MAINNET"]} apiKeys={keys} primaryNetwork={"ETH_MAINNET"}>
  children
</UserWeb3Provider>

You can pass props to the provider to give it defaul and setup valuse.

interface UserWeb3ProviderProps {
  children?: ReactNode;
  allowedChains?: ActiveChainIndex;
  apiKeys: { alchemy: string };
  primaryNetwork?: NetworkKeys; // Defaults to Ethereum Mainnet
}

type NetworkKeys =
  | "ETH_MAINNET"
  | "ETH_GOERLI"
  | "OPT_MAINNET"
  | "OPT_GOERLI"
  | "ARB_MAINNET"
  | "ARB_GOERLI"
  | "MATIC_MAINNET"
  | "MATIC_MUMBAI";

type ActiveChainIndex = {
  [chain in NetworkKeys]?: boolean;
};

You can then access the provider with

const [] = useWeb3Provider();

interface UserWeb3ProviderContextType {
  alchemySDKAccess: {
    alchemy: {
      apiKey: string;
      network: string;
      maxRetries: 10;
    };
  };
  web3API: any;
  walletAddress: string;
  addressBook: AddressBook;
  shortWalletAddress: string;
  userProvider: ethers.providers.Provider;
  userSigner: ethers.Signer;
  auxStorage: { [key: string]: any };
  localProvider: ethers.providers.Provider;
  selectedChains: ActiveChainIndex;
  onSelectedChainChange: (action: "add" | "remove", chain: NetworkKeys) => void;
  updateAuxStorage: updateAuxStorage;
  connectToUsersProvider: connectToUsersProvider;
  userSignMessage: userSignMessage;
  disconnectProvider: disconnectProvider;
  connectToGivenProvider: connectToGivenProvider;
  useEnsResolver: useEnsResolver;
}

type useEnsResolver = (network: NetworkKeys) => Promise<ensResolverReturns>;
type connectToGivenProvider = (
  provider: GivenProviderAllowance,
  network: NetworkKeys
) => Promise<ethers.providers.Provider | false>;
type disconnectProvider = () => void;
type userSignMessage = (
  signer: ethers.Signer,
  message: string,
  checkAddress?: string
) => Promise<boolean>;
type connectToUsersProvider = (
  userAction: boolean,
  givenNetwork?: NetworkKeys
) => Promise<boolean>;
type updateAuxStorage = (param: string, value: any) => void;

Project Structure

The project is structured as follows:

  • src/: This is the main folder where all the source code is located.
    • api/: This folder contains the setup for the Alchemy SDK and the API calls.
    • assets/: This folder contains the icons and placeholder images used in the project.
    • components/: This folder contains all the React components used in the project.
    • constants/: This folder contains the constants used across the project.
    • data/: This folder contains the data types used in the project.
    • helpers/: This folder contains helper functions for address formatting, web3 connection, event listening, and media formatting.
    • hooks/: This folder contains custom React hooks.
    • lib/: This folder contains the Address and AddressBook classes.
    • types/: This folder contains the TypeScript type definitions.
    • utils/: This folder contains utility functions and interfaces for interacting with Ethereum and the web3 providers.

Available Components

The following components are available in the project:

  • ChainSelector
  • ConnectButton
  • Gateway
  • NFTCard
  • NFTMedia
  • NFTModal
  • NFTModalExtention
  • NFTPaginate
  • NetworkNotification
  • TokenGateway
  • WalletEtherlink
  • web3Modal

Example

<ChainSelector availableChains==={["ETH_MAINNET", "MATIC_MAINNET"]} notForProvider onSelectedChain={handleChainSelect}  />

Technologies and Libraries

The project uses the following technologies and libraries:

  • @alch/alchemy-web3: For interacting with the Ethereum blockchain.
  • @coinbase/wallet-sdk: For interacting with the Coinbase Wallet.
  • @metamask/providers: For interacting with the MetaMask wallet.
  • @walletconnect/web3-provider: For interacting with WalletConnect compatible wallets.
  • ethers: For interacting with the Ethereum blockchain.
  • react and react-dom: For building the user interface.
  • web3modal: For creating a modal for connecting to a web3 provider.