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]);
startApp();
} else {
console.log("No web3!");
getWeb3();
}
});
But this gives me
Cannot read property 'currentProvider' of undefined
Ok, I then tried:
if (typeof Web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
returns:
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?