This is my code foe call a contract.And it was working perfectly fine not sure why stopped working all of sudden. Please help
const web3 = await enableWeb3();
const tokenContractTmp = await new web3.eth.Contract(nftAbi, nftaddress);
This is my code foe call a contract.And it was working perfectly fine not sure why stopped working all of sudden. Please help
const web3 = await enableWeb3();
const tokenContractTmp = await new web3.eth.Contract(nftAbi, nftaddress);
can you try adding a if condition using isWeb3Enabled
and only then run the second line.
if enableWeb3
function throws an error web3 will be undefined, which maybe the cause of this error.
Moralis now use ethers js and your syntax above is web3js syntax whereas the web3 constant there refers to ethers web3 provider. To use that syntax, you can check here about using web3js with moralis
In JavaScript, nearly everything is an object except for null and undefined. The error βCannot read property of undefinedβ occurs when a property is read or a function is called on an undefined variable. Undefined indicates that a variable has been declared but not assigned a value. In JavaScript, properties and functions can only belong to objects. Since undefined is not an object type, calling a function or property on such a variable causes the TypeError: Cannot read property of undefined.
To prevent errors caused by variables that may not have a guaranteed value, it is recommended to verify their value for null or undefined before utilizing them. To ensure that the variables being accessed contain the expected value, there are several approaches that can be employed. One such approach is to perform if checks prior to working with objects that may undergo changes:
if (myVar !== undefined) {
...
}
Or
if (typeof(myVar) !== 'undefined') {
...
}