I've been trying to run the following code:
$(document).ready(function(){
var myContract;
function startApp() {
myContract = new web3.eth.Contract(crowdsaleABI,
"0xfA6eeb8558c548B742E3745716aAEF04139a8d97");
}
function displayPrice() {
myContract.methods.tokenPrice().call((err, result) => {
console.log(web3.utils.fromWei(result, "ether"))});
}
window.addEventListener('load', function() {
// Checking if Web3 has been injected by the browser
(Mist/MetaMask)
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
web3 = new Web3(web3.currentProvider);
document.write("You are connected to MetaMask");
} else {
// Handle the case where the user doesn't have web3.
document.write("You are not connected to MetaMask");
web3 = new Web3(new
Web3.providers.HttpProvider("HTTP://127.0.0.1:7545"));
}
// Now you can start your app & access web3js freely:
startApp();
});
console.log("Hello World");
displayPrice();
});
However, I've been getting the following errors:
Uncaught TypeError: Cannot read property 'methods' of undefined
Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child
Particularly, first error is stopping me from doing any progress. I'm running web3 1.0.0-beta.34 (checked using npm ls web3).