Web3Auth Custom External Wallets + Login Functionality

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

  • SDK Version(package.json): 8.0.1
  • Platform: NextJS
  • Browser Console Screenshots:

Also, kindly provide the Web3Auth initialization and login code snippet below. This will help us better understand your issue and provide you with the necessary assistance.

I want to know three things:

  1. Why do we have to verify the appPubKey server-side? Or the external wallet address that a user connects to? If it’s already embedded in the JWT that anyone can decode, what’s the purpose in this case?

  2. Can we add custom adapters? I’m looking to see if it would be possible to support Station Wallet.

  3. Is there a procedure to swap chains after the modal has been inited? I’m currently trying to use a constructor like this:

export type ChainConfig = {
  ethereum: CustomChainConfig;
  solana: CustomChainConfig;
};

type ChainProvider = {
  ethereum: typeof EthereumPrivateKeyProvider;
  solana: typeof SolanaPrivateKeyProvider;
};

type Adapters = {
  openlogin: typeof OpenloginAdapter;
  metamask: typeof MetamaskAdapter;
  phantom: typeof PhantomAdapter;
};

...

  constructor(clientId: string, chain: keyof ChainConfig) {
    this.clientId = clientId;
    const ChainProviderClass = this.chainProvider[chain];
    try {
      this.web3auth = new Web3Auth({
        clientId: this.clientId,
        web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
        privateKeyProvider: new ChainProviderClass({
          config: { chainConfig: this.chainConfig[chain] },
        }),
      });
    } catch (e) {
      throw new SDKInitializationError(
        "Error initializing Web3Auth object" + e
      );
    }

    this.configureAdapter(chain);
  }

If I initialize the Web3Auth to Solana, and then later try to initialize another Web3Auth object with Ethereum, I get an error that the adapter Phantom is not configured. More specifically from this line: throw WalletInitializationError.invalidParams(Adapter ${adapterName} is not configured);. I’m not passing any arguments to initModal(), could this be the cause?

Or this is a dead end and I should just hard lock the user flow after he’s chosen a chain?

Hey @claudio.guerra

It is essential to verify the JWT on the server-side for authorization purposes. Let’s take an example where you need to authorize some API calls. In this case, you can use the JWT token obtained from Web3Auth and decode it using the JWKS we offer for social and external wallets. This process ensures that no one has tampered with the payload data of your token.

Currently, we have the following adapters available on https://web3auth.io/docs/sdk/pnp/web/adapters. If you have any suggestions or want to contribute a custom adapter, please make a PR to our GitHub repository at GitHub - Web3Auth/web3auth-web: Simple infrastructure that enables Web3 wallets and applications to provide seamless user logins for both mainstream and Web3.0 users..

Certainly, you can utilize the functions addChain() and switchChain(). For further reference, please visit https://web3auth.io/docs/sdk/pnp/web/modal/usage#add-chain.

Have you tried using the default-solana-adapter? If not, check out this link for sample code: web3auth-pnp-examples/web-modal-sdk/blockchain-connection-examples/solana-modal-example/src/App.tsx at main · Web3Auth/web3auth-pnp-examples · GitHub