[SOLVED] Linting Errors on Metamask setup

I am following this https://docs.moralis.io/docs/how-to-sign-in-with-metamask tutorial and have run into some issues. First I think that making an entire sign in page is unnecessary so I’m creating a button instead that will be nested in my navbar component. I’m using ESLint as my linter and it is throwing a couple of errors

import { useAuthRequestChallengeEvm } from "@moralisweb3/next";

import { useAccount, useConnect, useDisconnect, useSignMessage } from "wagmi";

import { MetaMaskConnector } from "wagmi/connectors/metaMask";

function MetamaskButton() {

  const { connectAsync } = useConnect();

  const { disconnectAsync } = useDisconnect();

  const { isConnected } = useAccount();

  const { signMessageAsync } = useSignMessage();

  const { requestChallengeAsync } = useAuthRequestChallengeEvm();

  const handleAuth = async () => {

    if (isConnected) {

      await disconnectAsync();

    }

    const { account, chain } = await connectAsync({

      connector: new MetaMaskConnector(),

    });

    const { message } = await requestChallengeAsync({

      address: account,

      chainId: chain.id,

    });

    const signature = await signMessageAsync({ message });

    const { url } = await MetamaskButton("moralis-auth", {

      message,

      signature,

      redirect: false,

      callbackUrl: "/user",

    });

    /**

     * instead of using signIn(..., redirect: "/user")

     * we get the url from callback and push it to the router to avoid page refreshing

     */

    push(url);

  };

  return (

    <div>

      <h3>Web3 Authentication</h3>

      <button onClick={handleAuth}>Authenticate via Metamask</button>

    </div>

  );

}

export default MetamaskButton;


It is telling me that push(url) is an undefined variable.

Second issue is that my Moralis.ts file is also throwing type errors. I changed it to a js file which helped but I’m still getting this error


uri: process.env.http://localhost:3000,
It is highlighting the http and giving this message Parsing error: Unexpected token, expected “,” (7:25)eslint

Also, this is what happens when I start my dev server.

Thank you for any help

Hey @Blockbuster, thanks for reaching out :grinning_face_with_smiling_eyes:

I’m not sure what are you trying to do there, but process.env is for environment variables which are stored in .env files, are you planning to have the uri value to http://localhost:3000? If so you should make http://localhost:3000 a string and remove process.env.

Hi @YosephKS, that is actually the authenticating config file which is specified in step six of the tutorial.
6. Add an authenticating config to the pages/api/moralis/[...moralis].ts:
I did try to make the change you suggested and now I am getting an internal server error that wasn’t there before.

Can you copy your code again here and let me take a look? @Blockbuster

import { MoralisNextApi } from "@moralisweb3/next";

export default MoralisNextApi({
  apiKey:
    process.env.pGzxOyQTEHw6czll24gOaQCM7hCq79TyE,
  authentication: {
    domain: "web.name",
    uri: "http://localhost:3000",
    timeout: 120,
  },
});

Hey there @Blockbuster,

That is the wrong way to put your API Key :raised_hands:

It should be

apiKey: "pGzxOyQTEHw6czll24gOaQCM7hCq79TyEfZYQ8N6m0bxB9YA4GtgzAsSqSX0wc3A"

Also I suggest after this you create a support ticket to renew your API key as this has been compromised, therefore people can use your API but you are paying their usage. You can request this through here https://moralis.io/support or message [email protected]

Thank you, @YosephKS. I will get that renewed as soon as possible. I just want to get this working. Do you have any ideas about the other issues I’m having?

Perfect!!

Ahh sorry I missed that, looks like from your code it’s very simple problem where we have not update the code to the latest wagmi version as they just deprecated defaultChain variable here in their changelog https://wagmi.sh/react/migration-guide#removed-defaultchains--defaultl2chains. Due to the deprecation, this results to defaultChain likely being null and therefore has no .length property as expected from an array type

So now you’ll need to change the wagmi configuration code to this instead:

mport { createClient, configureChains, mainnet } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public'
 
const { provider, webSocketProvider } = configureChains(
  [mainnet],
  [publicProvider()],
)
 
const client = createClient({
  provider,
  webSocketProvider,
})

That would definitely explain that issue! Now I’m running into this.

You just need to add a coosing parenthesis after publicProvider()], and should be all good

You’ve helped me tremendously thank you. I will be back if I have more questions.

1 Like

Perfect happy to help :grinning_face_with_smiling_eyes: feel free to come back and ask questions as needed