Search code examples
ethereumblockchainweb3jstruffle

How to solve [web3.eth.Contract is not a constructor]


I`m getting this error.

truffle(development)> const mycontract = new web3.eth.Contract(abi, contractAddress)

Thrown: TypeError: web3.eth.Contract is not a constructor

This happens when I set mycontract on console. Web3 version is `1.0.0

Could you give me any advise, please?


Solution

  • Assuming you are on Truffle 5 and you already run truffle deploy command, you can simply run the following in your truffle console terminal:

    const mycontract = await YourContract.deployed()
    
    // or
    
    const mycontract = await YourContract.at("0x_your_contract_address")