1

I'm getting this error when I'm trying to convert Wei to Ether using the code window.web3.utils.fromWei("200000",'ether'). This error shows only on the single page and when I console.log in the same window it shows the same error. But when I'm console.log in other windows it is working fine. Please find below screenshots for both.error Image

success image

  • How do you load web3.js in your page? – Ismael Apr 1 at 6:29
  • if (window.ethereum){ window.web3 = new Web3(window.ethereum); window.ethereum.enable(); } else if (window.web3) { window.web3 = new Web3(window.web3.currentProvider); } else { window.alert('Non-Ethereum browser detected. You should consider trying MetaMask!'); } I have used the above code to load Web3 – dinesh dsv Apr 1 at 22:25
0

I don't know what code you have for your "other windows", but the error:

Cannot read property 'x' of undefined

Tells you that in the expression obj1.obj2.x, the value of obj1.obj2 is undefined.

This is general to Javascript, and it has nothing to do specifically with Ethereum.

In your case, it means that window.web3.utils === undefined.

So your first debug-step should be console.log(JSON.stringify(window.web3, null, 4))...

| improve this answer | |
  • Thanks, @goodvibration. it helped to solve the error. Actually, In my code, I have loaded elements before loading Web3. I have loaded web3 before loading the page and it resolves my error. – dinesh dsv Apr 1 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.