Search code examples
reactjsmetamask

How to detect which Wallet is connected?


I have a web3 application where I use three types of wallets: MetaMask, WalletConnect, BianceChain, users can connect to these wallets,Problem is I can not detect which wallet user comes from, is there any way to distinguish them from each other?


Solution

  • Detecting the type of wallet a user is connecting with can be complex because Ethereum wallet services typically adhere to standards like EIP-1193: Ethereum Provider JavaScript API. This standardizes how transactions are signed and broadcasted, but does not inherently provide metadata about the wallet itself.

    Consider the following approaches:

    1. User Selection: Ask users to select their wallet type before the connection process. This is straightforward and scalable, but it relies on user honesty and may not be fully accurate.
    2. Programmatic Detection: You might infer the wallet type from certain characteristics. For instance, MetaMask and Binance Chain Wallet, respectively, inject window.ethereum and window.BinanceChain objects. WalletConnect, though, does not inject a window object, so its detection would rely more on user selection.

    Both methods have limitations and potential inaccuracies. Your choice depends on the specific wallets you support, the user experience you seek, and the importance of accurate wallet detection for your dapp.