Error sending transaction with web3auth-wagmi-connector

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

  • SDK Version(package.json):
    @web3auth/base”: “^8.12.4”,
    @web3auth/ethereum-provider”: “^8.12.4”,
    @web3auth/modal”: “^8.12.7”,
    @web3auth/wallet-services-plugin”: “^8.12.5”,
    @web3auth/web3auth-wagmi-connector”:“^6.0.0”,
    @wagmi/core”: “^2.6.5”,
    “viem”: “^2.21.5”,
    “wagmi”: “^2.12.10”,

  • Platform: web modal sdk nextjs app router

  • Browser Console Screenshots:

On Login

On send Transaction

Also, kindly provide the Web3Auth initialization and login code snippet

import { Web3AuthConnector } from '@web3auth/web3auth-wagmi-connector'
import { Web3Auth } from '@web3auth/modal'
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider'
import {
  CHAIN_NAMESPACES,
  WEB3AUTH_NETWORK,
  WALLET_ADAPTERS,
} from '@web3auth/base'
import type { Chain } from 'wagmi/chains'
import { WalletServicesPlugin } from '@web3auth/wallet-services-plugin'
import { env } from '@/env.mjs'

export default function Web3AuthConnectorInstance(chains: Chain[]) {
  if (!env.NEXT_PUBLIC_WEB3AUTH_CLIENT_ID) {
    throw new Error('NEXT_PUBLIC_WEB3AUTH_CLIENT_ID is not defined')
  }

  // Create Web3Auth Instance
  const name = 'IQ Wallet'
  const chainConfig = {
    chainNamespace: CHAIN_NAMESPACES.EIP155,
    chainId: `0x${chains[0].id.toString(16)}`,
    rpcTarget: chains[0].rpcUrls.default.http[0],
    displayName: chains[0].name,
    tickerName: chains[0].nativeCurrency?.name,
    ticker: chains[0].nativeCurrency?.symbol,
    blockExplorerUrl: chains[0].blockExplorers?.default.url[0] as string,
  }

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

  const web3AuthInstance = new Web3Auth({
    clientId: env.NEXT_PUBLIC_WEB3AUTH_CLIENT_ID,
    chainConfig,
    privateKeyProvider,
    uiConfig: {
      appName: name,
      loginMethodsOrder: ['google'],
      defaultLanguage: 'en',
      modalZIndex: '2147483647',
      logoLight: 'https://web3auth.io/images/web3authlog.png',
      logoDark: 'https://web3auth.io/images/web3authlogodark.png',
      uxMode: 'redirect',
      mode: 'light',
    },
    web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
    enableLogging: true,
  })

  const walletServicesPlugin = new WalletServicesPlugin({
    walletInitOptions: {
      whiteLabel: {
        showWidgetButton: true,
      },
    },
  })
  web3AuthInstance.addPlugin(walletServicesPlugin)

  const modalConfig = {
    [WALLET_ADAPTERS.OPENLOGIN]: {
      label: 'openlogin',
      loginMethods: {
        google: {
          // it will hide the facebook option from the Web3Auth modal.
          name: 'Login with Google',
          showOnModal: true,
        },
      },
      // setting it to false will hide all social login methods from modal.
      showOnModal: true,
    },
  }

  return Web3AuthConnector({
    web3AuthInstance,
    modalConfig,
  })
}

wagmi.ts

'use client'
import { createConfig, http } from 'wagmi'
import { polygon } from 'wagmi/chains'
import { iqTestnet } from './data/iqTestnet'
import { env } from '@/env.mjs'
import { magicConnector } from './magicConnector'
import Web3AuthConnectorInstance from '@/integrations/web3-auth-connector'

const isProduction = env.NEXT_PUBLIC_IS_PRODUCTION

export const config = createConfig({
  chains: [isProduction ? polygon : iqTestnet],
  transports: {
    [polygon.id]: http(
      `https://polygon-mainnet.g.alchemy.com/v2/${env.NEXT_PUBLIC_ALCHEMY_API_KEY}`,
    ),
    [iqTestnet.id]: http(iqTestnet.rpcUrls.default.http[0]),
  },
  connectors: [
    magicConnector,
    Web3AuthConnectorInstance([isProduction ? polygon : iqTestnet]),
  ],
})

//log connectors with details
config.connectors.map(async (connector) => {
  console.log({
    name: connector.name,
    id: connector.id,
    type: connector.type,
    accounts: await connector.getAccounts(),
    chainid: await connector.getChainId(),
    isConnected: await connector.isAuthorized(),
  })
})

Hi Sid Kapoor,

Thank you for providing the detailed information. It looks like you’re encountering an error while sending transactions using the Web3Auth-Wagmi connector in your Next.js app. Let’s summarize the key details for the support team:

SDK Details:

  • PnP Web SDK
  • SDK Versions (as in package.json):
    • @web3auth/base": "^8.12.4"
    • @web3auth/ethereum-provider: "^8.12.4"
    • @web3auth/modal: "^8.12.7"
    • @web3auth/wallet-services-plugin: "^8.12.5"
    • @web3auth/web3auth-wagmi-connector: "^6.0.0"
    • @wagmi/core: "^2.6.5"
    • viem: "^2.21.5"
    • wagmi: "^2.12.10"

Platform:

  • Web Modal SDK
  • Next.js App Router

Error Details:

Web3Auth Initialization and Login Code Snippets:

web3-auth-connector.js

import { Web3AuthConnector } from '@web3auth/web3auth-wagmi-connector'
import { Web3Auth } from '@web3auth/modal'
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider'
import {
  CHAIN_NAMESPACES,
  WEB3AUTH_NETWORK,
  WALLET_ADAPTERS,
} from '@web3auth/base'
import type { Chain } from 'wagmi/chains'
import { WalletServicesPlugin } from '@web3auth/wallet-services-plugin'
import { env } from '@/env.mjs'

export default function Web3AuthConnectorInstance(chains: Chain[]) {
  if (!env.NEXT_PUBLIC_WEB3AUTH_CLIENT_ID) {
    throw new Error('NEXT_PUBLIC_WEB3AUTH_CLIENT_ID is not defined')
  }

  // Create Web3Auth Instance
  const name = 'IQ Wallet'
  const chainConfig = {
    chainNamespace: CHAIN_NAMESPACES.EIP155,
    chainId: `0x${chains[0].id.toString(16)}`,
    rpcTarget: chains[0].rpcUrls.default.http[0],
    displayName: chains[0].name,
    tickerName: chains[0].nativeCurrency?.name,
    ticker: chains[0].nativeCurrency?.symbol,
    blockExplorerUrl: chains[0].blockExplorers?.default.url[0] as string,
  }

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

  const web3AuthInstance = new Web3Auth({
    clientId: env.NEXT_PUBLIC_WEB3AUTH_CLIENT_ID,
    chainConfig,
    privateKeyProvider,
    uiConfig: {
      appName: name,
      loginMethodsOrder: ['google'],
      defaultLanguage: 'en',
      modalZIndex: '2147483647',
      logoLight: 'https://web3auth.io/images/web3authlog.png',
      logoDark: 'https://web3auth.io/images/web3authlogodark.png',
      uxMode: 'redirect',
      mode: 'light',
    },
    web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
    enableLogging: true,
  })

  const walletServicesPlugin = new WalletServicesPlugin({
    walletInitOptions: {
      whiteLabel: {
        showWidgetButton: true,
      },
    },
  })
  web3AuthInstance.addPlugin(walletServicesPlugin)

  const modalConfig = {
    [WALLET_ADAPTERS.OPENLOGIN]: {
      label: 'openlogin',
      loginMethods: {
        google: {
          // it will hide the facebook option from the Web3Auth modal.
          name: 'Login with Google',
          showOnModal: true,
        },
      },
      // setting it to false will hide all social login methods from modal.
      showOnModal: true,
    },
  }

  return Web3AuthConnector({
    web3AuthInstance,
    modalConfig,
  })
}

wagmi.ts

'use client'
import { createConfig, http } from 'wagmi'
import { polygon } from 'wagmi/chains'
import { iqTestnet } from './data/iqTestnet'
import { env } from '@/env.mjs'
import { magicConnector } from './magicConnector'
import Web3AuthConnectorInstance from '@/integrations/web3-auth-connector'

const isProduction = env.NEXT_PUBLIC_IS_PRODUCTION

export const config = createConfig({
  chains: [isProduction ? polygon : iqTestnet],
  transports: {
    [polygon.id]: http(
      `https://polygon-mainnet.g.alchemy.com/v2/${env.NEXT_PUBLIC_ALCHEMY_API_KEY}`,
    ),
    [iqTestnet.id]: http(iqTestnet.rpcUrls.default.http[0]),
  },
  connectors: [
    magicConnector,
    Web3AuthConnectorInstance([isProduction ? polygon : iqTestnet]),
  ],
})

//log connectors with details
config.connectors.map(async (connector) => {
  console.log({
    name: connector.name,
    id: connector.id,
    type: connector.type,
    accounts: await connector.getAccounts(),
    chainid: await connector.getChainId(),
    isConnected: await connector.isAuthorized(),
  })
})

For further investigation, could you provide some insights on the errors/screenshot descriptions or copy the error texts if possible? This would help in diagnosing the issue more accurately.

This response was generated by the Web3Auth Bot and a member of our support team will be with you shortly to assist further.

The error log originated from

  const { data: hash, error, isPending, sendTransactionAsync } = useSendTransaction()

Also, the same error occurs in your example, when sending tokens (tried on sepolia testnet)
https://wagmi-modal-example.vercel.app/
@yashovardhan

Can you update to the latest version if the SDKs? It was recently released with a lot of bug fixes. Although as you mentioned, I can see the error on the hosted example as well. I’ll try to investigate what is going wrong there.

As I checked further this issue seems unrelated to web3auth. You account must be containing insufficient funds for sending the transaction or the transaction failed for some other reason. The particular code from wagmi always throws this error, be it any issue. You can check in the stack trace that all of these errors are thrown by the viem library.

When I am sending a transaction of enough value, it moves forward as expected.

Screenshot 2024-10-02 at 4.08.29 PM