Migrating to webAuth v10, custom RPC needed

Hi, im using webAuth v9 and wanting to migrate to v10. I checked the documentation, but i can seem to find a way to do custom RPC. My original code is

                    const web3auth = new Web3Auth({
                    clientId: vars.clientId as string,
                    web3AuthNetwork: "mainnet"
                    chains: {
                        chainNamespace: CHAIN_NAMESPACES.SOLANA,
                        chainId: vars.clientId,
                        rpcTarget: vars.rpcTarget,
                    },
                });

                await web3auth.initModal(); // ✅ Now this will work
                const provider = await web3auth.connect();

But im getting error in the ff:

  1. chainNamespace issue
  2. initModal is not valid function in web3auth

Can someone help me?

Thanks for sharing the details, Daniel! You’re migrating from Web3Auth v9 to v10 using the Plug and Play (PnP) Web SDK and want to set a custom RPC, but are running into two main issues:

  1. chainNamespace issue
  2. initModal is not a valid function in Web3Auth v10

Here’s a breakdown of what’s happening and how you can address it:

1. chainNamespace Issue

  • In v10, the SDK has introduced some breaking changes in how you configure chains and RPCs.
  • The chains configuration is now passed as an array, and the structure has changed.
  • The chainNamespace key is still used, but the way you define the chain and custom RPC is different.

v10 Example for Solana with Custom RPC:

import { Web3Auth } from "@web3auth/modal";
import { CHAIN_NAMESPACES } from "@web3auth/base";

const web3auth = new Web3Auth({
  clientId: vars.clientId,
  web3AuthNetwork: "mainnet",
  chainConfig: {
    chainNamespace: CHAIN_NAMESPACES.SOLANA,
    chainId: "0x1", // Solana mainnet chainId in hex
    rpcTarget: vars.rpcTarget, // Your custom RPC endpoint
  },
});
  • Make sure to use the correct chainId for Solana. For Solana, you can use "0x1" as a placeholder, but it’s mostly the chainNamespace and rpcTarget that matter.

2. initModal is Not a Valid Function

  • In v10, initModal() has been replaced by init().
  • The new initialization flow is:
await web3auth.init();
const provider = await web3auth.connect();

Documentation Reference

Summary of Changes for v10

  • Use chainConfig instead of chains
  • Use init() instead of initModal()

Next Steps

  • Update your initialization code as shown above.
  • Double-check your chainConfig values, especially chainNamespace and rpcTarget.

If you run into any more errors, please share the specific error messages and your updated code snippet. If possible, a screenshot of your console error would also help!

Let me know if this helps or if you have any other questions!

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.

Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. Web3Auth Developer Office Hours

Hey @danieljao
Here’s the doc piece that you made ght be looking for: Add Custom Chains to the Dashboard | Documentation | Web3Auth

Hi, im trying to do the following

const web3auth = new Web3Auth({
  clientId: vars.clientId,
  web3AuthNetwork: "mainnet",
  chainConfig: {
    chainNamespace: CHAIN_NAMESPACES.SOLANA,
    chainId: "0x1", // Solana mainnet chainId in hex
    rpcTarget: vars.rpcTarget, // Your custom RPC endpoint
  },
});

But im getting this error: Property ‘privateKeyProvider’ is missing in type ‘{ clientId: string; web3AuthNetwork: “sapphire_devnet”; chainConfig: { chainNamespace: “solana”; chainId: string; rpcTarget: string; }; }’ but required in type 'Web3AuthOptions

Also, im trying to join the discord, but im getting invite invalid

Hey @danieljao
You don’t need to configure any RPC or chains in the code. All of it can be done via the dashboard.
Please join the office hours on Thursday, I can assist you well in setting this up.

Hi @maharshi thank you for answering my questions in the call yesterday.

updates:

  1. I did the npm clear cache and the web3auth/modal did install and no errors in IDE → good sign
  2. now when i start the app in dev mode via npm, this is where i got a new error, specifically:
ERROR
codecs_1.getBytesCodec is not a function
./node_modules/@solana/spl-token-metadata/lib/cjs/state.js@http://localhost:3000/static/js/bundle.js:192380:132
options.factory@http://localhost:3000/static/js/bundle.js:534527:30
__webpack_require__@http://localhost:3000/static/js/bundle.js:533877:32
fn@http://localhost:3000/static/js/bundle.js:534143:21
hotRequire@http://localhost:3000/static/js/bundle.js:534510:61
./node_modules/@solana/spl-token-metadata/lib/cjs/index.js@http://localhost:3000/static/js/bundle.js:192186:14
options.factory@http://localhost:3000/static/js/bundle.js:534527:30
__webpack_require__@http://localhost:3000/static/js/bundle.js:533877:32
fn@http://localhost:3000/static/js/bundle.js:534143:21