Custom RPC node with web3Auth x Moralis

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

Okay, so going back to the issues with the package not being updated when editing code, it has something to do with package-lock.json and the versions stored there. I even had to update the version of my fork for my production enviroment to realize it should look for changes…I’m now the first running the newest version of Moralis 1.8.1.

BUT BACK TO THE ORIGINAL ISSUE:
It appears to be using my custom rpc but now I’m getting error 403, not authorized https://f*******w.usemoralis.com:2053/server/users 403

What’s the deal?

Okay, I switched servers, and now it works.

Wow, that’s a lot of work to jump through to put in a custom RPC which is REQUIRED for web3auth. I hope someone at Moralis is taking notes and implements this feature. There is really no point to offer intergration with web3auth if you have to use their crappy rpcs (they say in their documentation that you need to switch it)

Hi Mikiekwoods,

Actually I passed the rpcTarget directly at the top level of the config and it works:

await authenticate({
provider: “web3Auth”,
clientId: “…”,
chainId: “0x5”,
rpcTarget: “https://rpc.ankr.com/eth”
})

my only question is that I thought Moralis would provide an rpc Target… what am I supposed to put there as a valid target ?

you should put there a public RPC url, if you put your speedy node url then anyone can see it and use it

1 Like

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