Custom RPC node with web3Auth x Moralis

pe_chaut, are you using typescript? When I try to pass rpcTarget I get:

“Argument of type ‘{ provider: “web3Auth”; clientId: string; chainId: number; rpcTarget: string; theme: string; loginMethodsOrder: string[]; }’ is not assignable to parameter of type ‘AuthenticateOptions | undefined’.
Object literal may only specify known properties, and ‘rpcTarget’ does not exist in type ‘AuthenticateOptions’.”

Not working even with ts ignore.

You have latest version of the sdk?

Yes I did 1.8.0 . I even just reinstalled all my packages again and restarted VS Code to be sure.

    await authenticate({
        provider: "web3Auth",
        clientId: process.env.NEXT_PUBLIC_WEB3AUTH_ID!,
        chainId,
        //@ts-ignore
        rpcTarget: "https://rpc.ankr.com/eth",
        theme: "light", //or "dark"
        loginMethodsOrder: ["google", "facebook", "twitter", "discord", "reddit", "apple", "line", "github", "kakao", "linkedin", "weibo", "wechat", "email_passwordless"]
    })

Still requires to ts ignore the type error and still doesn’t work (console shows the default quicknode RPC is failing)

What if you add that ts-ignore on the authenticate function?

There is still an error

Cryptokid, do you know that rpcTarget is supposed to be accepted a parameter on the latest 1.8.0 or are you basing it off of pe_chaunt? It is not present in the documentation https://docs.moralis.io/moralis-dapp/users/web3-login/web3auth

Also the chainId types indicate it is suppose to be a number, which differs from the documentation.

Note: I already solved this issue by forking Moralis, but if it is indeed a feature already, then that is a far better solution.

OH NEVERMIND, they are appearing in my console. The chainId should be 1 (number), not the string (your code has a bug)

That string in hex form works for Mumbai (it was example code for someone else). Were you using "1"?

Also the chainId types indicate it is suppose to be a number, which differs from the documentation.

Which one, the chainId parameter for authenticate or for the web3auth config? You can submit an issue on the relevant GitHub repo.

I am not sure how @pe_chaut is using rpcTarget directly where it changes the URL (he isn’t using TypeScript), rpcTarget is not set at all in the Web3Auth connector.

@pe_chaut Can you verify that it is actually being used?

I’m using chainId: 1

VS Code tells me “(property) chainId: number” and also gives me a type error when entering “0x1”

This also works on Ropsten when I use the number 4.

It does sound like the types are wrong, not your code.

And I tend to also believe that rpcTarget is not a feature in 1.8.0

@alex @cryptokid @Erno ave you looked at the new 1.9.0? Does this solve the problem?

If it does, the documentation does not reflect it yet.
https://docs.moralis.io/moralis-dapp/users/web3-login/web3auth

What do you mean with the question if we have looked?

That update should fix the problem. Did you test it?

I have not tested it yet, it would take some time (which I wanted to ask before I spend the time to do so).

But it sounds like it’s worth trying.

1 Like

Yes rpcTarget does work in the options with the latest 1.9.0.

await authenticate({
  provider: 'web3Auth',
  rpcTarget: 'https://matic-mumbai.chainstacklabs.com', // use https://test.com to break/test it
  chainId: '0x13881',
  clientId: '',
});
1 Like