I have the following cloud code function to return stats about the latest block. When the cId is mainnet (0x1) the function returns fine, but when it is another chain (0x4, 0x3 etc) there is this error: Error: Could not find provider. This used to work on an older version of the dapp I am building (different server also). Am I doing something wrong with the new version (the cloud code was copy and pasted)? Any tips are greatly appreciated.
Moralis.Cloud.define(“getNetworkStats”, async function (request) {
let cId = request.params.cId;
let block = 0;
let avgGas = 0;
if(!cId == null || !cId == 0){
const web3 = Moralis.web3ByChain(cId);
block = await web3.eth.getBlockNumber();
avgGas = await web3.eth.getGasPrice();
avgGas = web3.utils.fromWei(avgGas, “gwei”)
}
let response = [block, avgGas];
return response;
});