Hi team, I have created my javascript code for Moralis at end of last year, and it was working perfectly fine with my Front-end, however it is now throwing me this error!
Has something changed in Moralis? I’m not sure why it is all of a sudden no longer able to read the contract!?!
What am I doing wrong? What’s changed?!
My Javascript:
<script>
///// loads consts
//MORALIS INITIALISE SERVER 1
Moralis.start({ serverUrl, appId }).then(() => {
console.log("Moralis initialized");
});
//CONSTANTS 2
var abi; //GET ABI JSON
var nftCost;
var nftSupply;
var web3;
var accounts;
var contractAbi;
// window.onload =
fetch("https://raw.githubusercontent.com/ **************************** /abi.json")
.then((response) => response.json())
.then((data) => {
contractAbi = data;
console.log("ABI:", contractAbi); //print full ABI
console.log("ABI Loaded");
console.log(contractAddress);
});
/////
other functions
/////
//MORALIS UPDATE COST
updateNftCost = async () => {
//Web3 User Account
let web3 = await Moralis.enableWeb3();
const contract = new web3.eth.Contract(contractAbi, contractAddress); //ERROR IS HERE
//Total Supply get from Contract
const optionsA = {
contractAddress: contractAddress,
functionName: "cost",
abi: contractAbi,
};
nftCost = await Moralis.executeFunction(optionsA);
console.log("NFT Price GWEI:", nftCost);
nftCostConverted = nftCost / 1000000000000000000;
document.getElementById("NftPrice").innerHTML = nftCostConverted;
console.log("NFT Price:", nftCostConverted);
};
//BUTTON BINDINGS
// window.onload = networkCheck();
document.querySelector("#btn-mint").onclick = mint;
document.querySelector("#w3-login").onclick = login;
document.querySelector("#w3-logout").onclick = logout;
document.querySelector("#w3-newChain").onclick = networkConfig;
document.addEventListener("DOMContentLoaded", theDomHasLoaded, false);
window.addEventListener("load", pageFullyLoaded, false);
function theDomHasLoaded(e) {
console.log("theDomHasLoaded");
};
function pageFullyLoaded(e) {
console.log("pageFullyLoaded");
updateNftCost();
updateTotalSupply();
};
</script>