I just tried using Moralis in calling functions in the deployed contract in Ganache.
I successfully did one transaction, but if I call a simple view function, I got this error:
moralis.js:42616 Uncaught (in promise) Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method=āgetCredslength()ā, errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.6.0)
This is the view function:
function getCredslength()
public
view
returns(uint total){
total = allCreds.length;
return(total);
}
and this is the function I used in calling the method:
async function getIssuedCreds(){
const credlength = {
contractAddress: "0x0566200D13627204e7AE3D7cf3976B13A1E5e6d4",
functionName: "getCredslength",
abi: CredentialsArtifact.abi,
}
const l = await Moralis.executeFunction(credlength);
console.log(l);
}
Iām not sure why Iām getting this error. It says in CALL_EXCEPTION that it might be because:
- the code does not exist on-chain
- wrong code is being accessed
- wrong ABI is being used
- Iām connected to a different network than the contract deployed
On the code does not exist on-chain
, wrong code is being accessed
, :
I was able to successfully make a transaction and mine a block using the same contract. Itās also in the Ganache UI
On wrong ABI is being used
:
Iām importing the JSON file of the deployed contract and stored it in a variable and got the ABI from there.
So I think Iām left with this, I'm connected to a different network than the contract deployed
.
Does this mean if metamask is connected to the ganache? or the project is connected to ganache?