I am trying to determine wether or not an address I pull from the request objects is a smart contract or an externally owned address. I came up with this function which seems to work but somehow it is not always correct.
Moralis.Cloud.define("isContract", async request => {
if (!request.params.address) return;
try {
const result = await web3.eth.getCode(request.params.address);
if (result !== "0x") {
return true;
}
return false;
} catch (error) {
logger.info("Error: " + error);
}
});
For example when I feed this function with the address 0x64a078926ad9f9e88016c199017aea196e3899e1
it returns this value
0x608060405234801561001057600080fd5b5060043610610โฆ
which according to my function above should return โtrueโ but it is saved in my database as false. Anyone sees where Im going wrong here?