Main.js:129 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'Contract')

I am following the casino dapp from however im am running into the following error when placing a bet.

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'Contract')
    at renderApp (main.js:48:36)
async function renderApp(){
    document.getElementById("register").style.display = "none";
    document.getElementById("app").style.display = "block";
    window.web3 = await Moralis.enableWeb3();
    window.contract = new web3.eth.Contract(contractAbi, CONTRACT_ADDRESS);

Did you declare the contract address as a variable?

Check this below thread for a similar issue.

I think it is something to do with the below code. I tried both <script src=""></script> and <script src="[email protected]/dist/moralis.js"></script> @johnversus

<script src="[email protected]/dist/web3.min.js"></script>
    <script src="" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
    <script src=""></script>
    <script src="[email protected]/dist/moralis.js"></script>
    <script type="text/javascript" src="./abi.js"></script>
    <script src="" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <link rel="stylesheet" href="./style.css">```

I managed to figure it out, I just had to replace <script src=""></script> with <script src="[email protected]/dist/moralis.js"></script>

1 Like

Can you replace this with the below script and see if this also solves it. I think the below script will always be the latest one so it does not require you to change this version code [email protected] after every release.

<script src="[email protected]/dist/moralis.js"></script>

That tutorial is an old one and that is why it works with that old version, because in the past Moralis sdk used web3 and now it uses ethers by default and the syntax is different for web3 versus ethers.