When I try to declare a web3 object It's always undefined
.
I'm writting in JavaScript and using Infura as my provider for the ETH mainnet. I also tried with a local blockchain instead of Infura, but it also didn't work. I'm new to blockchain development and I'm kinda stuck on this. I know it must be something very small I'm missing, maybe I forgot to install something. I've also spent quite some time researching my problem, but I just can't seem to get it to work.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://raw.githubusercontent.com/ethereum/web3.js/master/dist/web3.min.js"></script>
</head>
<script>
const rpcURL = "https://rinkeby.infura.io/INFURA_PROJECT_ID";
const address = 'MY_WALLET_ADDRESS';
const web3 = new Web3(new Web3.providers.HttpProvider(rpcURL));
web3.eth.getBalance(address, (err, wei) => {
myBalance = web3.utils.fromWei(wei, 'ether')
console.log(myBalance)
})
</script>
</html>
web3 is undefined
– RazerBoy Jun 29 '19 at 21:28