I am including web3.js
0.19.0
and getting the following error from the browser console: Uncaught ReferenceError: web3 is not defined at file.html:270
when using it with the following code:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.js"></script>
<script>
window.addEventListener('load', function () {
if (typeof web3 !== 'undefined') {
console.log('Web3 Detected! ' + web3.currentProvider.constructor.name)
web3 = new Web3(web3.currentProvider);
} else {
console.log('No Web3 Detected... using HTTP Provider')
web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/key"));
if(!web3.isConnected())
console.log("not connected");
else
console.log("connected");
}
});
web3.eth.defaultAccount = "0x..."; // <-- here starts the error "web3 undefined!!"
var myContract = web3.eth.contract(...abi...);
var myInstance = myContract.at('0x...');
</script>
On the other hand the browser gives me a positive message and tells me:
No Web3 Detected... using HTTP Provider (because I don't use Metamask)
connected
So how can web3 not being defined, if I get a connection with it?