Clearshine
Clearshine

Reputation: 11

I cannot create connector using "@walletconnect/client" and getting error

I used "@walletconnect/client" module to create wallet connector. Here is my code:

const WalletConnect = require("@walletconnect/client");
const connector = new WalletConnect({ uri });

This makes an error in my project.

Error: WalletConnect is not a constructor

Upvotes: 1

Views: 774

Answers (2)

elcharitas
elcharitas

Reputation: 151

You get the error because WalletConnect is default exported and default exports do not work as expected in commonjs. read more here

You should try this instead:

const WalletConnect = require("@walletconnect/client").default;
const connector = new WalletConnect({ uri });

Upvotes: 1

Tarandeep singh
Tarandeep singh

Reputation: 9

use this npm package and install it, then use the below command to use it

npm i @metamask/detect-provider

import detectEthereumProvider from '@metamask/detect-provider'

const provider = await detectEthereumProvider()

if (provider) {

  console.log('Ethereum successfully detected!')
  })
} else {
  console.error('Please install MetaMask!', error)
}

Upvotes: 0

Related Questions