@walletconnect/client vs @web3-react/core vs @web3modal/core vs ethers vs wagmi
Web3 and Blockchain Integration
@walletconnect/client@web3-react/core@web3modal/coreetherswagmiSimilar Packages:

Web3 and Blockchain Integration

Web3 and Blockchain Integration libraries provide tools and frameworks for building decentralized applications (dApps) that interact with blockchain networks. These libraries facilitate tasks such as connecting to wallets, sending transactions, reading and writing data on the blockchain, and managing user accounts. They are essential for developers looking to leverage blockchain technology in their applications, providing the necessary APIs and abstractions to work with smart contracts, cryptocurrencies, and decentralized protocols. These libraries help streamline the development process, enhance user experience, and ensure secure and efficient interactions with blockchain networks.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
@walletconnect/client01,649188 kB68-Apache-2.0
@web3-react/core05,69267.6 kB1762 years agoGPL-3.0-or-later
@web3modal/core0-725 kB-a year agoApache-2.0
ethers08,65213 MB6333 months agoMIT
wagmi06,6761.84 MB2219 days agoMIT

Feature Comparison: @walletconnect/client vs @web3-react/core vs @web3modal/core vs ethers vs wagmi

Wallet Connection

  • @walletconnect/client:

    @walletconnect/client provides a decentralized wallet connection protocol that allows users to connect their wallets using QR codes or deep links. It supports multiple wallets and is platform-agnostic, making it versatile for various applications.

  • @web3-react/core:

    @web3-react/core offers a flexible wallet connection framework that allows developers to integrate multiple wallet providers easily. It provides hooks and context for managing wallet connections, making it highly customizable for React applications.

  • @web3modal/core:

    @web3modal/core focuses on simplifying the wallet connection process by providing a modal interface for users to select their wallets. It supports multiple wallet providers and offers a seamless onboarding experience for users.

  • ethers:

    ethers does not provide a built-in wallet connection solution but can be integrated with any wallet provider. It is compatible with wallets that support the Ethereum JSON-RPC API, allowing for flexible wallet interactions.

  • wagmi:

    wagmi provides hooks for connecting to wallets and managing wallet state. It supports multiple wallet providers and is designed to work seamlessly with React applications, making wallet connection easy and intuitive.

Smart Contract Interaction

  • @walletconnect/client:

    @walletconnect/client does not handle smart contract interactions directly but facilitates transactions by connecting wallets that can sign and send transactions to the blockchain.

  • @web3-react/core:

    @web3-react/core does not provide built-in smart contract interaction features but allows developers to integrate any smart contract library (like ethers.js or web3.js) to interact with contracts once the wallet is connected.

  • @web3modal/core:

    @web3modal/core focuses on wallet connection and does not provide direct support for smart contract interactions. However, it can be used alongside other libraries like ethers.js for contract interactions after the wallet is connected.

  • ethers:

    ethers is a comprehensive library for interacting with smart contracts on the Ethereum blockchain. It provides a simple and intuitive API for reading and writing data to contracts, handling events, and managing transactions.

  • wagmi:

    wagmi simplifies smart contract interactions by providing hooks and utilities for reading and writing data to contracts. It integrates well with ethers.js, allowing for seamless contract interactions within React applications.

User Experience

  • @walletconnect/client:

    @walletconnect/client offers a user-friendly experience by allowing wallet connections via QR codes and deep links. However, the user interface is dependent on the wallet applications, which may vary.

  • @web3-react/core:

    @web3-react/core provides a good user experience but relies on developers to create their own UI components for wallet connection. It is highly customizable, allowing for tailored experiences.

  • @web3modal/core:

    @web3modal/core excels in user experience by providing a ready-to-use modal for wallet selection. It streamlines the connection process and supports multiple wallets, making it easy for users to connect.

  • ethers:

    ethers focuses on providing a robust API for developers and does not directly address user experience. However, its simplicity and documentation make it easy for developers to create user-friendly interfaces for wallet and contract interactions.

  • wagmi:

    wagmi enhances user experience in React applications by providing hooks that simplify wallet connection and contract interactions. Its design encourages best practices and reduces boilerplate code, making it easier for developers to create intuitive interfaces.

Code Example

  • @walletconnect/client:

    Wallet Connection Example with @walletconnect/client

    import { WalletConnectClient } from '@walletconnect/client';
    
    const connector = new WalletConnectClient({
      bridge: 'https://bridge.walletconnect.org', // Required
      qrcode: true,
    });
    
    // Create a new session
    connector.createSession().then(() => {
      // Get URI for QR Code
      const uri = connector.uri;
      console.log(`Connect with URI: ${uri}`);
    });
    
    // Subscribe to connection events
    connector.on('connect', (error, payload) => {
      if (error) throw error;
      const { account, chainId } = payload.params[0];
      console.log(`Connected: ${account}, Chain ID: ${chainId}`);
    });
    
    // Send a transaction
    const tx = {
      from: account,
      to: '0xRecipientAddress',
      value: '1000000000000000000', // 1 ETH
    };
    connector.sendTransaction(tx);
    
  • @web3-react/core:

    Wallet Connection Example with @web3-react/core

    import { Web3ReactProvider } from '@web3-react/core';
    import { ethers } from 'ethers';
    
    function getLibrary(provider) {
      const library = new ethers.providers.Web3Provider(provider);
      library.pollingInterval = 12000; // Refresh every 12 seconds
      return library;
    }
    
    function App() {
      return (
        <Web3ReactProvider getLibrary={getLibrary}>
          <YourComponent />
        </Web3ReactProvider>
      );
    }
    
  • @web3modal/core:

    Wallet Connection Example with @web3modal/core

    import { Web3Modal } from '@web3modal/core';
    import { ethers } from 'ethers';
    
    const web3Modal = new Web3Modal({
      cacheProvider: true,
      providerOptions: {}, // Add your provider options here
    });
    
    async function connectWallet() {
      const provider = await web3Modal.connect();
      const web3Provider = new ethers.providers.Web3Provider(provider);
      const signer = web3Provider.getSigner();
      const address = await signer.getAddress();
      console.log(`Connected: ${address}`);
    }
    
  • ethers:

    Smart Contract Interaction Example with ethers

    import { ethers } from 'ethers';
    
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    const signer = provider.getSigner();
    const contract = new ethers.Contract(contractAddress, contractABI, signer);
    
    // Read from contract
    const value = await contract.getValue();
    console.log(`Value from contract: ${value}`);
    
    // Write to contract
    const tx = await contract.setValue(42);
    await tx.wait();
    console.log('Value updated in contract');
    
  • wagmi:

    Smart Contract Interaction Example with wagmi

    import { useContractRead, useContractWrite } from 'wagmi';
    import { ethers } from 'ethers';
    
    const contractAddress = '0xYourContractAddress';
    const contractABI = [/* Your Contract ABI */];
    
    function YourComponent() {
      const { data, isLoading } = useContractRead({
        address: contractAddress,
        abi: contractABI,
        functionName: 'getValue',
      });
    
      const { write } = useContractWrite({
        address: contractAddress,
        abi: contractABI,
        functionName: 'setValue',
      });
    
      return (
        <div>
          <h1>Value: {isLoading ? 'Loading...' : data}</h1>
          <button onClick={() => write()}>Update Value</button>
        </div>
      );
    }
    

How to Choose: @walletconnect/client vs @web3-react/core vs @web3modal/core vs ethers vs wagmi

  • @walletconnect/client:

    Choose @walletconnect/client if you need a wallet connection solution that supports multiple wallets and platforms, including mobile and desktop. It is ideal for projects that require a decentralized and open-source protocol for connecting to wallets.

  • @web3-react/core:

    Select @web3-react/core if you want a flexible and customizable React library for managing wallet connections. It provides a set of hooks and components that allow you to integrate wallet connectivity into your React applications easily.

  • @web3modal/core:

    Opt for @web3modal/core if you need a complete solution for wallet onboarding and connection. It offers a customizable modal interface for users to select their wallets, making it easy to integrate multiple wallet providers in your dApp.

  • ethers:

    Use ethers if you require a comprehensive and lightweight library for interacting with the Ethereum blockchain. It provides tools for working with smart contracts, managing wallets, and handling transactions, making it suitable for both frontend and backend applications.

  • wagmi:

    Choose wagmi if you are building a React application and want a modern, hooks-based library for Ethereum. It simplifies the process of connecting to wallets, managing state, and interacting with smart contracts, while also providing excellent TypeScript support.

README for @walletconnect/client

WalletConnect Client

Client for WalletConnect

For more details, read the documentation

Install

yarn add @walletconnect/client
# OR

npm install --save @walletconnect/client

Initiate Connection

import WalletConnect from "@walletconnect/client";

// Create a connector
const connector = new WalletConnect({
  bridge: "https://bridge.walletconnect.org", // Required
});

connector.on("session_update", (error, payload) => {
  if (error) {
    throw error;
  }

  // Get updated accounts and chainId
  const { accounts, chainId } = payload.params[0];
});

connector.on("disconnect", (error, payload) => {
  if (error) {
    throw error;
  }

  // Delete connector
});

const { accounts, chainId } = await connector.connect();

Send Transaction (eth_sendTransaction)

// Draft transaction
const tx = {
  from: "0xbc28Ea04101F03aA7a94C1379bc3AB32E65e62d3", // Required
  to: "0x89D24A7b4cCB1b6fAA2625Fe562bDd9A23260359", // Required (for non contract deployments)
  data: "0x", // Required
  gasPrice: "0x02540be400", // Optional
  gasLimit: "0x9c40", // Optional
  value: "0x00", // Optional
  nonce: "0x0114", // Optional
};

// Send transaction
connector
  .sendTransaction(tx)
  .then(result => {
    // Returns transaction id (hash)
    console.log(result);
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  });

Sign Transaction (eth_signTransaction)

// Draft transaction
const tx = {
  from: "0xbc28Ea04101F03aA7a94C1379bc3AB32E65e62d3", // Required
  to: "0x89D24A7b4cCB1b6fAA2625Fe562bDd9A23260359", // Required (for non contract deployments)
  data: "0x", // Required
  gasPrice: "0x02540be400", // Optional
  gasLimit: "0x9c40", // Optional
  value: "0x00", // Optional
  nonce: "0x0114", // Optional
};

// Sign transaction
connector
  .signTransaction(tx)
  .then(result => {
    // Returns signed transaction
    console.log(result);
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  });

Sign Personal Message (personal_sign)


// Draft Message Parameters
const message = "My email is john@doe.com - 1537836206101"

const msgParams = [
  convertUtf8ToHex(message)                                                 // Required
  "0xbc28ea04101f03ea7a94c1379bc3ab32e65e62d3",                             // Required
];


// Sign personal message
connector
  .signPersonalMessage(msgParams)
  .then((result) => {
    // Returns signature.
    console.log(result)
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  })

Sign Message (eth_sign)


// Draft Message Parameters
const message = "My email is john@doe.com - 1537836206101";

const msgParams = [
  "0xbc28ea04101f03ea7a94c1379bc3ab32e65e62d3",                            // Required
  keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))    // Required
];


// Sign message
connector
  .signMessage(msgParams)
  .then((result) => {
    // Returns signature.
    console.log(result)
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  })

Sign Typed Data (eth_signTypedData)

// Draft Message Parameters
const typedData = {
  types: {
    EIP712Domain: [
      { name: "name", type: "string" },
      { name: "version", type: "string" },
      { name: "chainId", type: "uint256" },
      { name: "verifyingContract", type: "address" },
    ],
    Person: [
      { name: "name", type: "string" },
      { name: "account", type: "address" },
    ],
    Mail: [
      { name: "from", type: "Person" },
      { name: "to", type: "Person" },
      { name: "contents", type: "string" },
    ],
  },
  primaryType: "Mail",
  domain: {
    name: "Example Dapp",
    version: "1.0.0-beta",
    chainId: 1,
    verifyingContract: "0x0000000000000000000000000000000000000000",
  },
  message: {
    from: {
      name: "Alice",
      account: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    },
    to: {
      name: "Bob",
      account: "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
    },
    contents: "Hey, Bob!",
  },
};

const msgParams = [
  "0xbc28ea04101f03ea7a94c1379bc3ab32e65e62d3", // Required
  typedData, // Required
];

// Sign Typed Data
connector
  .signTypedData(msgParams)
  .then(result => {
    // Returns signature.
    console.log(result);
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  });

Send Custom Request

// Draft Custom Request
const customRequest = {
  id: 1337,
  jsonrpc: "2.0",
  method: "eth_signTransaction",
  params: [
    {
      from: "0xbc28Ea04101F03aA7a94C1379bc3AB32E65e62d3",
      to: "0x89D24A7b4cCB1b6fAA2625Fe562bDd9A23260359",
      data: "0x",
      gasPrice: "0x02540be400",
      gasLimit: "0x9c40",
      value: "0x00",
      nonce: "0x0114",
    },
  ],
};

// Send Custom Request
connector
  .sendCustomRequest(customRequest)
  .then(result => {
    // Returns request result
    console.log(result);
  })
  .catch(error => {
    // Error returned when rejected
    console.error(error);
  });

Create Instant Request

import WalletConnect from "@walletconnect/browser";
import WalletConnectQRCodeModal from "@walletconnect/qrcode-modal";

// Create a connector
const connector = new WalletConnect();

// Draft Instant Request
const instantRequest = {
  id: 1,
  jsonrpc: "2.0",
  method: "eth_signTransaction",
  params: [
    {
      from: "0xbc28ea04101f03ea7a94c1379bc3ab32e65e62d3",
      to: "0x0000000000000000000000000000000000000000",
      nonce: 1,
      gas: 100000,
      value: 0,
      data: "0x0",
    },
  ],
};

// Create Instant Request
connector
  .createInstantRequest(instantRequest)
  .then(result => {
    // Get Instant Request Result
    console.log(result);
  })
  .catch(error => {
    // Handle Error or Rejection
    console.error(error);
  });