Max
Max

Reputation: 708

Connect Polygon dApp to Wallect Connect using Alchemy RPC Provider

We are currently using the "ethers" library to connect our dApp to Metamask and to send transactions on the Polygon blockchain.

We would like to allow users to connect to the dApp via Wallet Connect as well.

So far we tried this :

import WalletConnectProvider from "@walletconnect/web3-provider";

const provider = await new WalletConnectProvider({
  rpc: {
    137: 'https://polygon-mainnet.g.alchemy.com/v2/<OUR_ALCHEMY_RPC_PRIVATE_KEY>'
  },
  chainId: 137
});

await provider.enable();
const eProvider = await new ethers.providers.Web3Provider(provider)

... but provider.enable() never resolves without any error after scanning the QR Code and the connection never gets established...

We also tried the Polygon dedicated library for WallectConnect but still were not able to make it work :

const WalletConnectProviderPolygon = require('@maticnetwork/walletconnect-provider')

const wcProvider = new WalletConnectProviderPolygon({
  host: 'https://polygon-mainnet.g.alchemy.com/v2/<OUR_ALCHEMY_RPC_PRIVATE_KEY>',
  callbacks: {
    onConnect: (res: any) => {
      console.log('onConnect', res)
    },
    onDisconnect: (res: any) => {
      console.log('onDisconnect', res)
    }
  }
})
// await alchemyProvider.createWebconnector()
const eProvider = new ethers.providers.Web3Provider(wcProvider, 137)

... but not connection modal is displayed. If we uncomment await alchemyProvider.createWebconnector() an ugly distorted modal appears, without desktop options, and again it never resolves after scanning the QR Code...

Any idea how to make Wallect Connect work with our Alchemy provider ?

Thank you

Upvotes: 0

Views: 690

Answers (1)

gringonivoli
gringonivoli

Reputation: 151

I use an alchemy rpc and others rpc but, with web3 instead ethers.

    const providerOptions = {
        walletconnect: {
          package: WalletConnectProvider,
          options: {
            rpc: {
              137: "https://polygon-rpc.com"
            }
          }
        },
      };
    
      web3Modal = new Web3Modal({
        cacheProvider: false,
        providerOptions,
      });

Here the example: codepen Web3modal

I'll try use ethers in a new example.

Upvotes: 0

Related Questions