I am trying to get the funds of my smart contract. The function is:
function totalBalance() public view returns (uint256) {
return address(this).balance;
}
I am using moralis and react-moralis for the frontend. I have defined the function to call the totalBalance
const { runContractFunction: getFund } = useWeb3Contract({
abi,
contractAddress: address,
functionName: "totalBalance",
params: {}
});
I then async/await it in useEffect
const updateUI = async () => {
const funds = await getFund();
console.log(funds)
}
useEffect(() => {
if (isWeb3Enabled) {
updateUI()
}
}, [isWeb3Enabled])
The problem is that on the first render i get undefined, but when i save/change the code in VSCode, it prints out the result.