[SOLVED] Moralis Auth with WalletConnect

For John

async function handleAuth(provider) {
    await Moralis.enableWeb3({
      throwOnError: true,
      provider,
    });
  
    const { account, chainId } = Moralis;
  
    if (!account) {
      throw new Error(
        "Connecting to chain failed, as no connected account was found"
      );
    }
    if (!chainId) {
      throw new Error(
        "Connecting to chain failed, as no connected chain was found"
      );
    }
  
    const { message } = await Moralis.Cloud.run("requestMessage", {
      address: account,
      chain: parseInt(chainId, 16),
      network: "evm",
    });
  
    return Moralis.authenticate({
      signingMessage: message,
      throwOnError: true,
    });
}

Hi @tarunprakash343

You mentioned you have updated the provider to walletconnect somewhere in your code. May I know on which file you have updated it?

Did you try passing the provider to this authentication function

All I am doing is calling this function as

handleAuth("walletconnect")

I did not explicitly set a provider anywhere in the code

Try passing provider: "walletConnect" params value to the Moralis.authenticate function. I think that should fix it.

Just tried that and it worked, thanks!

1 Like