Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate WalletConnect in your Dapp using web3-react?

I've been trying to integrate WalletConnect by following this documentation of web3-react.

The configuration that I'm using for the connector is as follows:

import { WalletConnectConnector } from '@web3-react/walletconnect-connector';

export const walletconnect = new WalletConnectConnector({
  rpc: { 1: RPC_URLS[1], 4: RPC_URLS[4] },
  infuraId: INFURA_TOKEN,
  bridge: BRIDGE_URL,
  qrcode: true,
  pollingInterval: 15000,
});

Also, the versions of packages are as follows:

"@web3-react/core": "^6.0.9",
"@web3-react/walletconnect-connector": "^6.2.0",

When I use the activate function from useWeb3React() as explained in below code:

const { connector, activate, active, account } = useWeb3React();
activate(walletconnect, undefined, true)
    .catch((error) => {
        if (error instanceof UnsupportedChainIdError) {
            activate(walletconnect)
        } else {
            console.log('Pending Error Occured')
        }
    })

It was able to generate QR Code, also I was able to successfully scan through MetaMask app on my Mobile Phone and on the mobile app it shows successfully connected.

Though, on the console logs of the Web App it shows a warning saying

Warning: Suppressed stale connector activation [object Object]

Thus, It fails to receive address inside the account variable.

Important Note: I'm using the similar code with InjectedConnector and it is working perfectly fine for MetaMask.

Though the above problem also appears with other wallets. These are the wallets I am facing the problem with:

  1. WalletConnect
  2. WalletLink (Coinbase Wallet)
  3. Portis

Any advice will help me a lot.

like image 403
Utkarsh Gupta Avatar asked May 19 '21 06:05

Utkarsh Gupta


People also ask

How do I add DApp to WalletConnect?

Click on the scan icon in the top right corner and scan the QR code. A window will pop-up at the bottom of the screen and prompt you to connect to the DApp. Click Connect. If you were able to successfully connect, you will see a pop-up in MetaMask that says Connected to Moonbeam WalletConnect Demo App.

What is WalletConnect DApp?

WalletConnect is a bridge that connects Decentralized Applications (DApps) to your Bitcoin.com Wallet. Once you've approved a connection request from the DApp (via WalletConnect), the DApp can send transaction requests to your Bitcoin.com Wallet, which you must also manually approve in the Wallet.


Video Answer


1 Answers

I have also faced the same issue when I was developing tagprotocol.com , however I have solved it in two ways :

  1. Calling the activate function multiple times in subsequent lines ( Sounds weird I know )

  2. Setting a delay on calling the activate function, something like this

    setTimeout(() => activate(...), 500)

Im not sure about your code structure so I dont know to what extend this helps. But stale connector object issue is something that I have resolved using the above two methods. Let me know in the comments.

like image 193
Sak90 Avatar answered Sep 22 '22 17:09

Sak90