-
In my lotteryEntrance.js file, the getEntranceFee() function returns "undefined" to my What could be the issue as entranceFee is set to 0.01 eth in my Here is the function async function updateUI() {
const entranceFeeFromCall = (await getEntranceFee()).toString()
setEntranceFee(entranceFeeFromCall)
console.log(entranceFeeFromCall)
} This is the complete code import { useWeb3Contract, useMoralis } from "react-moralis"
import { abi, contractAddresses } from "../constants"
import { useEffect, useState } from "react"
export default function LotteryEntrance() {
const { chainId: chainIdHex, isWeb3Enabled } = useMoralis() // This returns the hex value
const chainId = parseInt(chainIdHex)
const lotteryAddress =
chainId in contractAddresses ? contractAddresses[chainId][0] : null
const [entranceFee, setEntranceFee] = useState("0")
const { runContractFunction: getEntranceFee } = useWeb3Contract({
abi: abi,
contractAddress: lotteryAddress, // specify the networkId
functionName: "getEntranceFee",
params: {},
})
async function updateUI() {
const entranceFeeFromCall = (await getEntranceFee()).toString()
setEntranceFee(entranceFeeFromCall)
console.log(entranceFeeFromCall)
}
useEffect(() => {
if (isWeb3Enabled) {
updateUI()
}
}, [isWeb3Enabled])
return <div>{entranceFee}</div>
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
-
@PatrickAlphaC Please look into this if you can, there's no solution to this as of yet. I'm facing the same issue and I also tried Edit: Although, on second thought, the console in the browser does print 4 when I'm connected with the rinkeby network in metamask and I refresh, so the function may be fine. I'm not sure what the error could be then. Edit#2: I've figured out the solution to this issue. You can find it here: #685 (reply in thread) |
Beta Was this translation helpful? Give feedback.
@PatrickAlphaC Please look into this if you can, there's no solution to this as of yet. I'm facing the same issue and I also tried
console.log(chainIdHex)
afterconst { chainId: chainIdHex, isWeb3Enabled } = useMoralis()
and I'm getting nan in the terminal with the front-end deployment. It seems like the useMoralis itself might be broken or updated and is no longer giving us the chainId.Edit: Although, on second thought, the console in the browser does print 4 when I'm connected with the rinkeby network in metamask and I refresh, so the function may be fine. I'm not sure what the error could be then.
Edit#2: I've figured out the solution to this issue. You can find it here: #685 (reply i…