0

i have issue on web3 = new web3 (web3.currentProvider);

below is the code. it said web3 is not a constructor. is it like the capital letter issues?

the version of my web3 is "^1.3".

var contract = "";

if (typeof web3 !== 'undefined') {
console.log('inside web3')
Web3 = new Web3 (Web3.currentProvider);
} else {
console.log('else web3');
var web3 = new Web3(new 
Web3.providers.HttpProvider('http://127.0.0.1:4444/'));

}

window.ethereum.enable()
.then(function (accounts) {
    console.log(accounts[0]);

    web3.eth.defaultAccount = web3.eth.getAccounts();
 
  var contractabi = new web3.eth.contract([
{ABI}])

1 Answer 1

0

change your Constructor name to Uppercase

var web3 = new Web3(new Web3.providers.HttpProvider(provider);
4
  • Thank you so much for the reply. Current errors (updated code above) : MetaMask no longer injects web3. & Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getAccounts')
    – Hafizah
    Commented Apr 11, 2022 at 7:05
  • If metamask is installed in your browser, it injects an ethereum object into your browser’s global window object. that will be accessing window.ethereum dev.to/rounakbanik/building-a-web3-frontend-with-react-340c
    – Mohammad
    Commented Apr 11, 2022 at 7:18
  • okay. i only use metamask browser extension. i have to install to make it work? sorry, im still new about blockchain
    – Hafizah
    Commented Apr 11, 2022 at 7:50
  • why there is an error here: web3.eth.getAccounts(); ?
    – Hafizah
    Commented Apr 11, 2022 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.