Wallet Connect – Fixing ‘The Requested Account/Method has not been Authorized by the User’ Issue

metamaskreactwalletconnectweb3js

I am using the exactly same wallet on both Wallet Connect (Chrome) + MetaMask (mobile) and MetaMask (Chrome) in calling a mint function of my smart contract. With MetaMask (Chrome), the process goes smoothly; but with Wallet Connect (Chrome) + MetaMask (mobile), this error occurs:

inpage.js:1 MetaMask - RPC Error: The requested account and/or method has not been authorized by the user.

I am simply use

const contract = new web3.eth.Contract(
  abi,
  contractAddress
);

contract.methods.mintBatch(something).send({from: walletId, value: value}, (err, res) => callback(err, res));

with both Wallet Connect (Chrome) + MetaMask (mobile) and MetaMask (Chrome). Does it require additional set-up for Wallet Connect?

Best Answer

Turns out I need to use the following to replace the usual web3 to make it work:

const provider = new WalletConnectProvider({
  infuraId: process.env.INFURA_PROJECT_ID, // Required
});

walletConnectWeb3 = new Web3(provider as any);

contractSubstitute = new walletConnectWeb3.eth.Contract(abi, contractAddress);

contractSubstitute.methods.mintBatch(something).send({from: walletId, value: value}, (err, res) => callback(err, res));

The web3 has to be walletConnect web3.