Getting "Cannot read the properties of undefined" out of nowhere

Urgent help!

Our dapp was working well until all of the sudden we started to get a “Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘Contract’)” error

This is the exact line that throws it:
let contract = new web3.eth.Contract(abi, CONTRACT_ADDRESS);

This is what’s around that line:
window.web3 = await Moralis.Web3.enableWeb3();
let abi = await getAbi();
let contract = new web3.eth.Contract(abi, CONTRACT_ADDRESS);

Our code hasn’t changed and everything was working properly until about 4 hours ago. What could be the reason?

We’re obviously declaring CONTRACT_ADDRESS at the start of the code btw, so that’s not it =/

You are probably a victim of the migration from web3: Moralis JS SDK v1.0 (migration to Ethers.js)

If it works with the following script then that’s the problem:
<script src="https://unpkg.com/[email protected]/dist/moralis.min.js"></script>

1 Like

Hey!

We just switched to ethers, to update to the new version pleasse change cdn to such:

<script src="https://unpkg.com/moralis@latest/dist/moralis.js"></script>

If you don’t want to update

<script src="https://unpkg.com/[email protected]/dist/moralis.js"></script>

2 Likes

This one bit me too.

Thank you.