PnP errors when switching chains and even the Playground example does the same thing

I’m having issues with our integration switching between chains.

We have authentication working. Sending & receiving transactions, and several other things all work great.

But we can’t switch between chains for some reason.

I’ve been through the documentation for days back and forth and just can’t get it to work.

I notice even the Web3Auth example in the playground has the same problem:
https://pnp-modal-playground.vercel.app/

it won’t switch chains properly and gives and error except when switching to ETH chain. Switching to Polygon gives error:

[
"Failed to switch chain",
{
"cause": null,
"code": -32603,
"data": {
"error": "message: API key is not allowed to access blockchain, json-rpc code: -32052, rest code: 403",
"cause": null
}
}
]

Here’s a quick Loom video showing what ours is doing.
https://www.loom.com/share/6085d0ebee8d48cebb9a87305e10716a?sid=0f94ca69-25cb-49c7-bd51-bfb440ccd0f8

Thanks for providing detailed information and the Loom video—this is really helpful!

Here’s a summary of your issue for the support team:


Issue Summary:

  • SDK/Platform: Web3Auth Plug n Play (PnP)

  • Problem: Chain switching fails (except for Ethereum) both in your integration and in the official PnP Playground example.

  • Error Message:

    [
      "Failed to switch chain",
      {
        "cause": null,
        "code": -32603,
        "data": {
          "error": "message: API key is not allowed to access blockchain, json-rpc code: -32052, rest code: 403",
          "cause": null
        }
      }
    ]
    
  • What works:

    • Authentication
    • Sending/receiving transactions
    • Chain switching to Ethereum
  • What fails:

    • Switching to other chains (e.g., Polygon) results in the above error.
  • Reproducible in:

  • Reference Video: Loom video


Possible Cause & Next Steps

The error message indicates an API key permission issue:

API key is not allowed to access blockchain, json-rpc code: -32052, rest code: 403

This usually means:

  • The default RPC provider (or the API key being used) does not have access to the requested chain (e.g., Polygon).
  • In the PnP Playground, only certain chains may be enabled by default.

Proposed Solution:

  • You may need to provide your own RPC endpoints for non-Ethereum chains (like Polygon) in your Web3Auth configuration.
  • See the Custom Chain Configuration documentation for how to add your own RPC URLs.

Example:

chains: [
  {
    chainNamespace: CHAIN_NAMESPACES.EIP155,
    chainId: "0x89", // Polygon Mainnet
    rpcTarget: "https://polygon-rpc.com", // Or your own RPC endpoint
    displayName: "Polygon Mainnet",
    blockExplorer: "https://polygonscan.com",
    ticker: "MATIC",
    tickerName: "Polygon",
  },
  // ...other chains
]

Next Steps for You:

  • Try specifying custom RPC endpoints for the chains you want to support in your Web3Auth config.
  • If you’re using the Playground, note that it may be limited to certain chains for demo purposes.

If you’ve already tried custom RPC endpoints and still see this issue, please share your Web3Auth initialization code snippet (with sensitive info redacted) so the support team can take a closer look.

Let us know if this helps or if you need further guidance!

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