1.5.3 • Published 3 months ago

@e_labs/web3provider v1.5.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

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.
2.0.0-beta.22

3 months ago

2.0.0-beta.21

3 months ago

2.0.0-beta.20

3 months ago

2.0.0-beta.23

3 months ago

2.0.0-beta.11

3 months ago

2.0.0-beta.10

3 months ago

2.0.0-beta.15

3 months ago

2.0.0-beta.14

3 months ago

2.0.0-beta.13

3 months ago

2.0.0-beta.12

3 months ago

2.0.0-beta.19

3 months ago

2.0.0-beta.18

3 months ago

2.0.0-beta.17

3 months ago

2.0.0-beta.16

3 months ago

2.0.0-beta.9

3 months ago

2.0.0-beta.8

3 months ago

2.0.0-beta.7

3 months ago

1.5.3

3 months ago

2.0.0-beta.2

3 months ago

2.0.0-beta.1

3 months ago

2.0.0-beta.0

3 months ago

2.0.0-beta.6

3 months ago

2.0.0-beta.5

3 months ago

2.0.0-beta.4

3 months ago

2.0.0-beta.3

3 months ago

1.5.2

3 months ago

1.5.1

3 months ago

1.5.0

3 months ago

1.4.17

6 months ago

1.4.16

6 months ago

1.4.15

6 months ago

1.4.14

6 months ago

1.4.13

6 months ago

1.4.12

6 months ago

1.4.11

6 months ago

1.4.10

6 months ago

1.4.9

6 months ago

1.4.8

6 months ago

1.4.7

6 months ago

1.4.6

6 months ago

1.4.3

6 months ago

1.4.2

6 months ago

1.4.1

6 months ago

1.3.13

6 months ago

1.3.12

6 months ago

1.3.11

6 months ago

1.3.10

6 months ago

1.3.9

6 months ago

1.3.8

6 months ago

1.3.7

6 months ago

1.3.6

6 months ago

1.3.5

6 months ago

1.3.4

6 months ago

1.3.3

6 months ago

1.3.2

6 months ago

1.3.1

6 months ago

1.3.0

6 months ago