I am using moralis web3 to connect to my smart contract in the front end.
It seems i am having problems with executing and retrieving a function value inside my smart contract.
const { Moralis, isWeb3Enabled} = useMoralis()
const electionAddress = "0x45eB0c2FDdf1fE0dB656E1900140fD0DED94053e"
const {runContractFunction: getCandidatesNumber} = useWeb3Contract({
abi: abi,
contractAddess: electionAddress ,
functionName: "getCandidatesNumber",
params:{}
})
async function updateUIValues() {
// Another way we could make a contract call:
// const options = { abi, contractAddress: raffleAddress }
// const fee = await Moralis.executeFunction({
// functionName: "getEntranceFee",
// ...options,
// })
const number = await getCandidatesNumber()
console.log(number)
setcandidatesNumber(number)
}
useEffect(() => {
if (isWeb3Enabled) {
updateUIValues()
}
}, [isWeb3Enabled])
please can someone help me, I am following a youtube guide but i am stuck in this phase. because i can’t console log the value when i am testing.
PS: i tested my getCandidatesNumber() in my hardhat when i deployed and it works.