It is too confusing for me. I tried everything.

If I run the code in node.js with browserfy.. everything works fine.

No I want to run it on my webserver. As MetaMask states it will not inject the global web3 object any more. So I download the web3.js here and add it in the html file with: Ok. Now I do:

   window.addEventListener('load', function () {

     if (typeof Web3 !== 'undefined') {
        window.web3 = new Web3(window.web3.currentProvider);
        console.log('Found web3!');
        console.log('Your Account: '+ web3.eth.accounts[0]);
     } else {
        console.log("No web3!");

But this gives me

Cannot read property 'currentProvider' of undefined

Ok, I then tried:

    if (typeof Web3 !== 'undefined') {
        web3 = new Web3(web3.currentProvider);


web3 is not defined

I also tried different thins like:

    if (typeof Web3 !== 'undefined') {
        var web3 = new Web3(window.web3.currentProvider);

Well, whatever I try I fail. Did I get the concept wrong?

How can I host a website and connect to the MetaMask provider?

1 Answer 1


Ok, I think I figured it out myself.


states in the first paragraph

Http(s) - Web Server Required Due to browser security restrictions, we can't communicate with dapps running on file://. Please use a local server for development.

Nevermind. But maybe it helps someone else.

  • the object is still sometimes undefined and sometimes not. but this is for sure an other issue :/
    – kn1g
    Dec 21, 2017 at 16:57

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.