web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Error: ENS is not supported on network private

Open shenhaoguangDayDayUp opened this issue 4 years ago • 11 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

image

Expected Behavior

no error

Steps to Reproduce

export const web3Connect = () => async (dispatch, getState) => {
  //@ts-ignore
  if (typeof window.ethereum === "undefined") {
    //没安装MetaMask钱包进行弹框提示
    return;
  }
  const { web3Reducer, netWorkId } = getState();

  let addresses = await web3.eth.getAccounts();
  if (!addresses.length) {
    addresses = await (window as any).ethereum.enable();
  }
  let chainId = (await web3.eth.getChainId()) || 56; // 币安链

  console.log(web3Reducer.contractAddresses);

  try {
    await dispatch(swichNetWork(chainId));
    await dispatch({
      type: WEB3_CONNECTED,
      payload: {
        web3,
        chainId: chainId,
        account: addresses,
        loading: false,
        walletConnect: true,
        contractAddresses,
      },
    });
    dispatch(web3ConnectChange(true));
  } catch (error) {
    dispatch(web3ConnectChange(false));
  }
export const swichNetWork = (chainId) => async (dispatch, getState) => {
  //@ts-ignore
  const tx = await ethereum.request({
    method: "wallet_switchEthereumChain",
    params: [{ chainId: netWorkId }],
  });
};


Web3.js Version

1.61

Environment

  • Operating System: Mac
  • Browser: chome
  • Node.js Version: v14.17.6
  • NPM Version: 6.14.15

Anything Else?

No response

shenhaoguangDayDayUp avatar Dec 14 '21 03:12 shenhaoguangDayDayUp

Hi @shenhaoguangDayDayUp Thanks for reaching out to us. I looked into the code you shared, seems like React or Redux code. Unfortunately I can't execute that code right away to debug it further. It would be so nice if you can share a reproducible script that we can run on our end without dependencies to reproduce the issue.

nazarhussain avatar Dec 17 '21 14:12 nazarhussain

Hello folks, thanks for checking this issue.

I'm also experiencing this issue in a Node/NestJS service where I'm using web3 (v1.6.1 - also tried w/ 1.5.2 and 1.2.11 but got the same error). The project doesn't make any calls ENS at all (no calls to ens functions), only web3 (pretty much create a web3 instance, and instantiate a few contracts, without ENS integration). However, a few moments after web3 is instantiated (using a RPC for Polygon or Celo), the service throws this error.

Error happens on node_modules/web3-eth-ens/lib/ENS.js:482:19. Error message: UnhandledPromiseRejectionWarning: Error: ENS is not supported on network private

I'm not really sure what's happening, but looks like that by simply creating a web3 instance, the ens package is required, which in result calls checkNetwork function and then throws the exception asynchronously.

fodisi avatar Jan 02 '22 20:01 fodisi

@fodisi @shenhaoguangDayDayUp

This is very strange behavior. The error ENS is not supported on network is only been thrown from checkNetwork and that function is not invoked by the library itself.

Certainly some upper layer is invoking that function. Are you sure there is no other library or code which you are injecting with web3, that may be invoking that function.

@fodisi Can you try to create an empty npm package with only dependency of web3 and see the problem persists.

nazarhussain avatar Jan 06 '22 16:01 nazarhussain

@fodisi Were you able to reproduce this error with only web3 dependency in the package?

nazarhussain avatar Jan 21 '22 10:01 nazarhussain

this happens when you use state management like Redux and I don't know the reason why lol in vue you can use something like markRaw when using state management

Marks an object so that it will never be converted to a proxy. Returns the object itself.

mrguamos avatar Feb 06 '22 16:02 mrguamos

@mrguamos I am not sure, but it looks the state management is creating new objects for the web3.

I am closing this issue, as this error does not directly relates to web3 library. If we get more context we can reopen the issue.

nazarhussain avatar Feb 09 '22 12:02 nazarhussain

@nazarhussain having the same issue here. I'm using useReducer and ContextAPI for global state management, and whenever I connect using web3modal, i'm given this error: Error: ENS is not supported on network private at ENS.checkNetwork Can anyone please look into this? I'm not making any sort of ens.checkNetwork or networkType call in my code, its just merely a contract call after I connect my wallet

Hamza141999 avatar Jul 26 '22 10:07 Hamza141999

@nazarhussain having the same issue here. I'm using useReducer and ContextAPI for global state management, and whenever I connect using web3modal, i'm given this error: Error: ENS is not supported on network private at ENS.checkNetwork Can anyone please look into this? I'm not making any sort of ens.checkNetwork or networkType call in my code, its just merely a contract call after I connect my wallet

I also had this problem, but it's weird that it only triggers when I have the redux toolkit open

Yinboan avatar Oct 02 '22 10:10 Yinboan

@nazarhussain having the same issue here. I'm using useReducer and ContextAPI for global state management, and whenever I connect using web3modal, i'm given this error: Error: ENS is not supported on network private at ENS.checkNetwork Can anyone please look into this? I'm not making any sort of ens.checkNetwork or networkType call in my code, its just merely a contract call after I connect my wallet

I also had this problem, but it's weird that it only triggers when I have the redux toolkit open

I'm not familiar with redux but can you try using this? https://redux-toolkit.js.org/api/other-exports#original

mrguamos avatar Oct 02 '22 11:10 mrguamos

No Ens calls, react context api same issue here.

Jsherborne92 avatar Mar 17 '23 15:03 Jsherborne92

i get this on svelte but only when dynamically importing the web3 library 1.xx

cryptolit0 avatar Aug 04 '24 00:08 cryptolit0