Wallet Services initialization

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

I’m trying to use Wallet Services with web3auth’s no-modal, but I’m encountering this error. I’m not sure what’s causing the issue or how to fix it.

<script setup lang="ts">
import { onMounted } from 'vue';
import { Web3AuthNoModal as Web3Auth } from '@web3auth/no-modal';
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider';
import {
  ADAPTER_EVENTS,
  UX_MODE,
  WALLET_ADAPTERS,
  WEB3AUTH_NETWORK,
  CHAIN_NAMESPACES,
} from '@web3auth/base';
import { AuthAdapter } from '@web3auth/auth-adapter';
import { WalletServicesPlugin } from '@web3auth/wallet-services-plugin';

import { logger } from '@/utils';

const { VITE_AUTH_WEB3AUTH_CLIENT_ID } = import.meta.env;

const chainConfig = {
  chainNamespace: CHAIN_NAMESPACES.EIP155,
  chainId: '0xaa36a7',
  rpcTarget: 'https://sepolia.drpc.org',
  // Avoid using public rpcTarget in production.
  // Use services like Infura, Quicknode etc
  displayName: 'Ethereum Sepolia Testnet',
  blockExplorerUrl: 'https://sepolia.etherscan.io',
  ticker: 'ETH',
  tickerName: 'Ethereum',
  logo: 'https://cryptologos.cc/logos/ethereum-eth-logo.png',
};
/**
 * @description Web3Auth
 */
const privateKeyProvider = new EthereumPrivateKeyProvider({
  config: { chainConfig },
});
/**
 * @description Web3Auth
 */
const web3auth = new Web3Auth({
  clientId: VITE_AUTH_WEB3AUTH_CLIENT_ID,
  web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
  privateKeyProvider,
});
/**
 * @description Wallet Services
 */
const walletServicesPlugin = new WalletServicesPlugin();
/**
 * @description Web3Auth AuthAdapter
 */
function authAdapter(verifier: string) {
  return new AuthAdapter({
    adapterSettings: {
      // POPUP은 버튼 클릭으로만 동작함.
      // REDIRECT는 페이지 리다이렉션 후 동작함.
      uxMode: UX_MODE.REDIRECT,
      loginConfig: {
        jwt: {
          verifier,
          typeOfLogin: 'jwt',
          clientId: VITE_AUTH_WEB3AUTH_CLIENT_ID,
        },
      },
    },
  });
}

/**
 * @description idToken 가져오기
 */
const getLocalIdToken = () => localStorage.getItem('idToken');
/**
 * @description provider 가져오기
 */
const getLocalProvider = () => localStorage.getItem('provider');

/**
 * @description Web3Auth 초기화
 * @param {string} verifier
 * - web3auth > Project > Custom Authentication > Verifier
 * - omc-google, omc-facebook, omc-kakao
 */
async function init(verifier: string) {
  logger.log('web3auth init');
  if (web3auth.connected) {
    logger.log('web3auth already initialized');
    return web3auth.connected;
  }

  web3auth.configureAdapter(authAdapter(verifier));
  web3auth.addPlugin(walletServicesPlugin);
  web3auth.on(ADAPTER_EVENTS.CONNECTED, () => {
    logger.log('web3auth connected');
  });

  await web3auth.init();

  logger.log('web3auth init done', web3auth.connected);

  return web3auth.connected;
}

/**
 * @description Web3Auth 로그인
 */
async function login() {
  logger.log('web3auth login');
  if (web3auth === null) {
    logger.log('web3auth not initialized yet');
    return;
  }
  if (web3auth.connected) {
    logger.log('web3auth already connected');
    return web3auth.provider;
  }

  const idToken = getLocalIdToken();

  const web3authProvider = await web3auth.connectTo(WALLET_ADAPTERS.AUTH, {
    loginProvider: 'jwt',
    extraLoginOptions: {
      id_token: idToken,
      verifierIdField: 'email',
      domain: 'https://dev-auth.openmeta.city',
    },
  });

  return web3authProvider;
}

onMounted(async () => {
  const provider = getLocalProvider();
  const loggedIn = await init(provider as string);
  console.log('loggedIn:', loggedIn);
  const loggedInProvider = await login();
  console.log('loggedInProvider:', loggedInProvider);
});
</script>

<template>
  <div>
    <h1>Test</h1>

    <button
      type="button"
      @click="() => walletServicesPlugin.showWalletUi({ show: true })"
    >
      Show Wallet UI
    </button>
  </div>
</template>

<style lang="scss" scoped></style>

Hi Aaron Yun! Thank you for reaching out to the Web3Auth community. I see you’re having some trouble with Wallet Services initialization while using the PnP Web SDK. Let’s gather the details for the support team:

Issue Reported:

  • SDK Details: PnP Web SDK
  • SDK Version: ^9.4.5
  • Platform: Vue3
  • Error Description: Error during Wallet Services initialization when using Web3Auth’s no-modal.

Additional Information:

Code Snippet:

You’ve provided a comprehensive code snippet, which is great! It includes the initialization of Web3Auth, configuration of wallet services, and the login function.

Next Steps:

It would be helpful if you could provide any specific error messages from the console that might clarify the issue further. If possible, please check if the issue might relate to custom authentication with any provider you’re using (e.g., specifics around the verifier name or method of login).

This information will assist our support team in addressing your issue more effectively. Thank you again for your detailed submission, and we’re here to help you resolve this!

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.