When i made web3 instance and run index.html i lose ethereum and window.ethereum when i call it from console i got ethereum is not defined,i have installed metamask and use ropsten network.Why its happend,but when i go on site like cryptokitties it works perfect.

if (typeof web3 !== 'undefined') {
 web3 = new Web3(web3.currentProvider);
} else {
 // set the provider you want from Web3.providers
 web3 = new Web3(new 

async function asyncCall() {
  ethereum.enable()  // =========== RETURN UNDEFINED
  const result = await web3.eth.getAccounts();
  // expected output: 'resolved'

2 Answers 2


I was running into this same issue.
Apparently nobody wants to make the solution obvious, but I finally found this issue, which brought me to this link:

Due to browser security restrictions, we can't communicate with dapps running on file://. Please use a local server for development.

So setting up an actual server locally fixes the issue. I just verified that this works after installing http-server.

I installed it using npm install http-server -g (assuming node is installed).
Then ran it using http-server "C:\directory_of_my_html_file" -a and was then able to successfully access window.ethereum (browsing to http://localhost:8080/index.html).

  • 1
    Thanks.Thats true,i solve it befor 2 weeks,but thanks Commented Apr 18, 2020 at 20:36

An easier way that worked for me is to install Live server extension for VSCode (VsCode users only)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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