To start off, I'm fairly new to JavaScript and web3, so please excuse me if the question's very trivial.
if (typeof web3 !== 'undefined') {
web3Provider = web3.currentProvider;
web3 = new Web3(web3.currentProvider);
} else {
web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
web3 = new Web3(App.web3Provider);
}
This is the way I currently instantiate web3, not sure if it's deprecated (I feel like this could potentially be the problem)
When I attempt to log the getAccounts() function like this
console.log(web3.eth.getAccounts())
I'm faced with:
web3.min.js:2 Uncaught (in promise) TypeError: e is not a function
at web3.min.js:2
at web3.min.js:2
at r (inpage.js:1)
at s._handle (inpage.js:17)
and also when I attempt to call my solidity functions, namely one named "addFood()" that takes in 4 parameters like this,
var eth_pk = document.getElementById("pk").value
console.log(eth_pk) //console.log logs the output values in the javascript console.
var eth_fd = document.getElementById("fd").value
console.log(eth_fd)
var eth_pl = document.getElementById("pl").value
console.log(eth_pl)
var eth_prc = document.getElementById("prc").value
console.log(eth_prc)
contract.methods.addFood(eth_pk, eth_fd, eth_pl, eth_prc).send({ from: web3.eth.defaultAccount }, function(error, result)
{
console.log(result)
})
I'm faced with
Uncaught TypeError: Cannot read properties of undefined (reading 'addFood')
at HTMLFormElement.<anonymous> (sell.html:208)
I'll provide any additional code that's needed to solve this issue. I'd be very grateful if someone could solve this! Thank you!
You're probably using MetaMask, in which case your provider is window.ethereum