Web3 error for NFT Marketplace

Hello
I am getting this error: “Could not find name ‘Web3’. Did you mean ‘web3’?”
This is the code:


var web3 = new Web3(Web3.givenProvider);

var instance;
var user;
var contractAddress = "0x4B25339CF0DdbDE4f56B9ac6E302fb6e6660bd52";

$(document).ready(async function(){

    window.ethereum.enable()
    .then(async function(accounts){
     const instance = new web3.eth.Contract(abi, contractAddress, {from: accounts[0]})
     user = accounts[0];
     console.log(instance);
    });
  
  });

How do I go about fixing it?
Thanks, Michael

Hi @MichaelW

if(typeof web3 != 'undefined'){
			web3 = new Web(web3.currentProvider);
		} else {
			web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
		}

Keep an eye on capital and small “w” in “web3”

Hope this helps

I am still getting the same error with this code:

if(typeof web3 != 'undefined'){
  web3 = new Web3(web3.currentProvider);
} else {
  web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
}
var web3 = new Web3(Web3.givenProvider);

Hi @MichaelW

Hopefully, you have imported web3 library?

Can you share your full code?

1 Like

Hello
This is my Git Hub : https://github.com/MichaelWaterfall/Penguin/tree/main/Penguin%20NFT%20Marketplace
The code is all in there.