Next Js 15.1.14 with web3auth modal not working

When asking for help in this category, please make sure to provide the following details:

  • SDK Version(package.json):9.5.3
  • Platform: Web Next Js
  • Browser Console Screenshots: Brave

Hello here is my config files

projectConfig.ts

import {
  CHAIN_NAMESPACES,
  CustomChainConfig,
  WEB3AUTH_NETWORK
} from '@web3auth/base'
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider'
import { Web3Auth, Web3AuthOptions } from '@web3auth/modal'

const clientId = process.env.NEXT_PUBLIC_WEB3AUTH_CLIENT_ID || ''

const chainConfig: CustomChainConfig = {
  chainNamespace: CHAIN_NAMESPACES.EIP155,
  chainId: '0x1',
  rpcTarget: 'https://rpc.ankr.com/eth',
  displayName: 'Ethereum Mainnet',
  blockExplorerUrl: 'https://etherscan.io',
  ticker: 'ETH',
  tickerName: 'Ethereum',
  logo: 'https://cryptologos.cc/logos/ethereum-eth-logo.png'
}

const privateKeyProvider = new EthereumPrivateKeyProvider({
  config: { chainConfig }
})

export const web3AuthOptions: Web3AuthOptions = {
  clientId,
  web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
  privateKeyProvider
}
export const web3auth = new Web3Auth(web3AuthOptions)

My file WalletConnect.tsx

'use client'

import { Button } from '@/components/ui/button'
import { IAdapter, IProvider } from '@web3auth/base'
import { useEffect, useState } from 'react'
import { getDefaultExternalAdapters } from '@web3auth/default-evm-adapter'
import { web3auth, web3AuthOptions } from '@/lib/projectConfig'

export default function Walletconnect() {
  const [provider, setProvider] = useState<IProvider | null>(null)
  const [loggedIn, setLoggedIn] = useState(false)

  useEffect(() => {
    const init = async () => {
      try {
        const adapters = await getDefaultExternalAdapters({
          options: web3AuthOptions
        })
        adapters.forEach((adapter: IAdapter<unknown>) => {
          web3auth.configureAdapter(adapter)
        })

        await web3auth.initModal()
        setProvider(web3auth.provider)

        if (web3auth.connected) {
          setLoggedIn(true)
        }
      } catch (error) {
        console.error(error)
      }
    }

    init()
  }, [])

  const login = async () => {
    const web3authProvider = await web3auth.connect()
    setProvider(web3authProvider)
    if (web3auth.connected) {
      setLoggedIn(true)
    }
  }
  console.log(provider)
  console.log(loggedIn)

  return (
    <div className="flex items-center gap-2">
      <Button
        variant="outline"
        size="lg"
        className="rounded-full"
        onClick={login}
      >
        Login
      </Button>
    </div>
  )
}

Inside my Dashboard I have setup:

  • Products: Plug and Play
  • Select Chains: EVM Based Chain

Errors:




Hi Nicolas!

Thanks for sharing all the details about your issue with Next.js and Web3Auth.

From the errors you’re encountering, and given that you’re using the PnP Web SDK with the 9.5.3 version and the Brave browser, it looks like there might be a configuration issue with initialization or the integration flow.

Here’s a checklist to help troubleshoot the issue:

  1. Environment Variables: Ensure that process.env.NEXT_PUBLIC_WEB3AUTH_CLIENT_ID is correctly set and accessible in your Next.js environment. Sometimes, a missing or undefined client ID can cause initialization problems.

  2. Network Configuration: Make sure the web3AuthNetwork you specified (WEB3AUTH_NETWORK.SAPPHIRE_MAINNET) is supported by your project and corresponds to your selected chain in the dashboard.

  3. Modal Initialization: Double-check if there’s any asynchronous initialization issue. You can add additional logs inside your init function to pinpoint where it might be failing.

  4. Error Details: Review the console errors closely in the provided screenshots for any hints about missing dependencies or incorrect function usage.

  5. Adapter Configuration: Ensure proper adapter configurations are returned by getDefaultExternalAdapters and verify that they are correctly linked with web3auth.

  6. Dependencies: Confirm that all necessary dependencies are compatible with your Next.js version, and there’s no version conflict.

If these suggestions don’t resolve the problem, I’d recommend examining the detailed stack trace from your console logs and seeing if there are more specific error messages that could indicate a specific piece of misconfiguration or missing dependencies.

Please let me know if any further assistance is required or if there are any specific console errors you’d need help interpreting!

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

I followed the docs. I found that the issue was related with the clientId. It not work the clientId from my project, I use the client from the docs and works. I need to have the emailandpassword modal. What do I need to config on my project to use it?

Hi @limonico,

Are you currently using the Brave browser? If so, please try accessing it through a different browser.

Additionally, since the examples in the documentation are using a clientId that is correctly configured, you might want to check your plan, as some features are available only under specific pricing tiers.

You can find a similar issue related to clientId and its solution here: Cannot connect with Metamask on Sapphire Devnet (sapphire_devnet) - #3 by shahbaz.

Thanks. Yes I saw many features that I need. require upgrade plan. Thanks

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.