Web3auth Provider with avalanche chainId?

Has anyone had success setting Avalanche (or any chain) as the default for the web3auth provider?

When I try this:

const user = await Moralis.authenticate({
          provider: "web3Auth",
          theme: "light",
          chainId: "avalanche",
          clientId:
            "BNAltJRis6TNpXXXXXXXXXXXXXXXXXXX7ay3TLGKow",
        });

I get

walletInitializationError: Invalid params passed in, rpcTarget is required in chainConfig at Function.fromCode

Same result with: chainId: 0xa86a

Did you later get this to work ?

I never did get it working, but i moved away form this approach a few months ago so I am not sure if it is working now.

They said it works for avalanche C chain

How did you try to set that chain id parameter?

https://docs.moralis.io/moralis-dapp/users/crypto-login/web3auth

here is an example how to set chainId:

Can you try with Moralis.Chains.AVAX_MAINNET ?

Hey, I am using react typescript and setting
chainId: Moralis.Chains.AVAX_TESTNET
in the authenticate method with “web3Auth” as provider returns a type error where type “EChains” can’t be assigned to type “number”.
Any work around ?

You can change it to a number:

chainId: Number(Moralis.Chains.AVAX_TESTNET)

Thanks for your answer.
Sadly it’s not fixing the issue.
Here is my snippet:

		await authenticate({
			provider: "web3Auth",
			clientId:
				"***",
			chainId: Number(Moralis.Chains.AVAX_TESTNET),
		})

On the auth trigger, it’s creating inside the DOM an empty <section id="w3a-container"> whereas if I remove the chainId then web3Auth is triggered as it should but with Ethereum.

Do you get any console errors? Try using another chain e.g. POLYGON_MUMBAI to see if the modal shows up.

No console errors, and its working as it should with POLYGON_MUMBAI but not with AVAX_MAINNET/TESTNET

You may need to change the RPC. For now until it’s available in a future SDK version where you can pass in the RPC directly into authenticate, you can test it locally by making a change similar to the one here and change the chainId and RPC e.g. if (chainId === 0xa869) {.

1 Like

Is it okay to ship in prod with this method?
thanks for your help!

You could either fork the SDK or patch it to make this change (as mentioned in that post I linked), or you could use a custom connector similar to this and change it there. The second option would be easier.

1 Like