@walletconnect/client vs @walletconnect/web3-provider vs @web3-react/core vs ethers
Web3 and Wallet Integration
@walletconnect/client@walletconnect/web3-provider@web3-react/coreethersSimilar Packages:

Web3 and Wallet Integration

Web3 and Wallet Integration libraries provide tools for connecting decentralized applications (dApps) to blockchain networks and user wallets. These libraries facilitate interactions with smart contracts, manage user accounts, and handle transactions on behalf of users. They are essential for building applications that leverage blockchain technology, allowing for secure and seamless interactions between users and decentralized platforms. @walletconnect/client is a library for connecting dApps to wallets using the WalletConnect protocol, enabling secure and decentralized wallet connections. @walletconnect/web3-provider is a Web3 provider implementation for WalletConnect, allowing dApps to interact with Ethereum and other blockchain networks through WalletConnect-compatible wallets. @web3-react/core is a framework-agnostic library for managing wallet connections in React applications, providing a set of hooks and components for integrating various wallet providers. ethers is a comprehensive Ethereum library that provides tools for interacting with the Ethereum blockchain, including smart contract interaction, wallet management, and utilities for working with Ethereum addresses and transactions.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
@walletconnect/client01,649188 kB64-Apache-2.0
@walletconnect/web3-provider01,649876 kB64-Apache-2.0
@web3-react/core05,69667.6 kB1762 years agoGPL-3.0-or-later
ethers08,64413 MB6313 months agoMIT

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

Wallet Connection

  • @walletconnect/client:

    @walletconnect/client provides the core functionality for establishing a connection between your dApp and WalletConnect-compatible wallets. It handles the QR code generation, session management, and secure communication between the dApp and the wallet.

  • @walletconnect/web3-provider:

    @walletconnect/web3-provider acts as a Web3 provider that wraps around the WalletConnect client, allowing dApps to interact with the Ethereum blockchain through the connected wallet. It integrates seamlessly with existing Web3.js or Ethers.js code, making it easy to use.

  • @web3-react/core:

    @web3-react/core provides a set of hooks and components for managing wallet connections in React applications. It supports multiple wallet providers and allows for easy integration and management of wallet connections within your app.

  • ethers:

    ethers provides wallet connection functionality through its Wallet class and integration with various wallet providers. It supports EIP-1559 transactions, gas estimation, and more, making it a comprehensive solution for Ethereum dApp development.

Smart Contract Interaction

  • @walletconnect/client:

    @walletconnect/client does not provide direct support for smart contract interaction. It focuses on establishing secure connections between dApps and wallets, leaving contract interaction to be handled by the dApp using Web3 or Ethers.js.

  • @walletconnect/web3-provider:

    @walletconnect/web3-provider allows dApps to interact with smart contracts by forwarding calls through the connected wallet. It supports all standard Web3 methods, making it compatible with existing smart contract interaction code.

  • @web3-react/core:

    @web3-react/core does not handle smart contract interaction directly. It provides the tools to manage wallet connections, while the actual interaction with smart contracts is done using a separate library like Web3.js or Ethers.js.

  • ethers:

    ethers provides a rich set of features for interacting with smart contracts, including contract deployment, function calls, event listening, and more. It is a full-featured library that supports both simple and complex contract interactions.

Ease of Integration

  • @walletconnect/client:

    @walletconnect/client is easy to integrate into any dApp that needs WalletConnect functionality. However, it requires some manual setup to handle the wallet connection flow and integrate with your existing code.

  • @walletconnect/web3-provider:

    @walletconnect/web3-provider is designed for easy integration with dApps, especially those that already use Web3.js or Ethers.js. It requires minimal setup and provides a familiar interface for developers.

  • @web3-react/core:

    @web3-react/core offers a flexible and customizable integration for React applications. It allows developers to easily integrate multiple wallet providers and manage connections, but may require some configuration to set up.

  • ethers:

    ethers is straightforward to integrate for Ethereum-related functionality. Its well-documented API and modular design make it easy to use for both simple and complex tasks.

Documentation and Community

  • @walletconnect/client:

    @walletconnect/client has good documentation and an active community, but it is primarily focused on the WalletConnect protocol. Developers may need to refer to additional resources for integrating with specific wallets or dApps.

  • @walletconnect/web3-provider:

    @walletconnect/web3-provider is well-documented and has a growing community of developers. It is widely used in the dApp ecosystem, making it easy to find examples and support.

  • @web3-react/core:

    @web3-react/core has comprehensive documentation and a supportive community. Its framework-agnostic approach and flexibility have made it popular among React developers.

  • ethers:

    ethers boasts excellent documentation, a large community, and numerous tutorials and resources. It is one of the most widely used Ethereum libraries, ensuring plenty of support for developers.

Code Example

  • @walletconnect/client:

    WalletConnect Integration Example

    import { Client } from '@walletconnect/client';
    
    const connector = new Client({
      bridge: 'https://bridge.walletconnect.org', // Required
      qrcode: true, // Optional
    });
    
    // Create a new session
    connector.createSession().then(() => {
      const uri = connector.uri;
      console.log(`QR Code URI: ${uri}`);
    });
    
    // Subscribe to connection events
    connector.on('connect', (payload) => {
      const { chainId, accounts } = payload.params[0];
      console.log(`Connected to chain ${chainId} with accounts: ${accounts}`);
    });
    
    // Subscribe to disconnection events
    connector.on('disconnect', (error) => {
      if (error) {
        console.error('Connection error:', error);
      }
      console.log('Disconnected from wallet');
    });
    
  • @walletconnect/web3-provider:

    WalletConnect Web3 Provider Example

    import WalletConnectProvider from '@walletconnect/web3-provider';
    import { ethers } from 'ethers';
    
    // Create a WalletConnect Provider
    const provider = new WalletConnectProvider({
      infuraId: 'YOUR_INFURA_ID', // Required
    });
    
    // Enable session (triggers QR Code modal)
    await provider.enable();
    
    // Create an ethers provider
    const web3Provider = new ethers.providers.Web3Provider(provider);
    
    // Get signer
    const signer = web3Provider.getSigner();
    const address = await signer.getAddress();
    console.log(`Connected address: ${address}`);
    
  • @web3-react/core:

    Web3 React Example

    import { Web3ReactProvider } from '@web3-react/core';
    import { ethers } from 'ethers';
    
    function getLibrary(provider) {
      return new ethers.providers.Web3Provider(provider);
    }
    
    function App() {
      return (
        <Web3ReactProvider getLibrary={getLibrary}>
          {/* Your app components */}
        </Web3ReactProvider>
      );
    }
    
  • ethers:

    Ethers.js Example

    import { ethers } from 'ethers';
    
    // Connect to the Ethereum network
    const provider = new ethers.providers.InfuraProvider('mainnet', 'YOUR_INFURA_ID');
    
    // Create a wallet instance
    const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
    
    // Interact with a smart contract
    const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, wallet);
    const result = await contract.someFunction();
    console.log(result);
    

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

  • @walletconnect/client:

    Choose @walletconnect/client if you need a lightweight library for implementing WalletConnect in your dApp. It provides the core functionality for connecting to WalletConnect-compatible wallets and is ideal for projects that require direct integration with the WalletConnect protocol.

  • @walletconnect/web3-provider:

    Choose @walletconnect/web3-provider if you want a simple way to integrate WalletConnect as a Web3 provider in your dApp. This package is particularly useful if you are building on Ethereum and want to enable users to connect their WalletConnect-compatible wallets easily.

  • @web3-react/core:

    Choose @web3-react/core if you are building a React application and need a flexible and framework-agnostic solution for managing wallet connections. This library allows you to integrate multiple wallet providers and offers a customizable approach to wallet management.

  • ethers:

    Choose ethers if you need a comprehensive and feature-rich library for interacting with the Ethereum blockchain. It provides tools for smart contract interaction, wallet management, and more, making it suitable for both simple and complex dApp development.

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);
  });