Lesson:10 TypeError: Cannot read properties of undefined (reading 'toString') #1165
Answered
by
technophile-04
Sunil-Reddy-Gummalla
asked this question in
Q&A
-
Hi I am getting this Below Error on UI When I tried to Remove the I followed #1054 not helped My LotteryEntrance.js import { abi, contractAddresses } from "../constants/index"
import { useMoralis, useWeb3Contract } from "react-moralis"
import { useEffect, useState } from "react"
export default function LotteryEntrance() {
const { chainId: chainIdHex, isWeb3Enabled } = useMoralis()
const chainId = parseInt(chainIdHex)
console.log(chainId)
const raffleAddress = chainId in contractAddresses ? contractAddresses[chainId][0] : null
let { entranceFee, setEntranceFee } = useState("0")
const { runContractFunction: getEntranceFee } = useWeb3Contract({
abi: abi,
contractAddress: raffleAddress, // specify the networkId
functionName: "getEntranceFee",
params: {},
})
useEffect(() => {
if (isWeb3Enabled) {
//try to read the Raffle Entrance Feee...
async function UpdateUI() {
const entranceFeeFromCall = await getEntranceFee()
setEntranceFee(entranceFeeFromCall)
console.log(entranceFee)
}
UpdateUI()
}
}, [isWeb3Enabled])
return (
<div>
<h2>
HI From LotteryEntrance!<div>{entranceFee}</div>
</h2>
</div>
)
} |
Beta Was this translation helpful? Give feedback.
Answered by
technophile-04
Jul 20, 2022
Replies: 1 comment 1 reply
-
Hii, useState returns an array...., For first error please check you are passing right contractAddress, abi, and functionName import { abi, contractAddresses } from "../constants/index"
import { useMoralis, useWeb3Contract } from "react-moralis"
import { useEffect, useState } from "react"
export default function LotteryEntrance() {
const { chainId: chainIdHex, isWeb3Enabled } = useMoralis()
const chainId = parseInt(chainIdHex)
console.log(chainId)
const raffleAddress = chainId in contractAddresses ? contractAddresses[chainId][0] : null
- let { entranceFee, setEntranceFee } = useState("0")
+ const [entranceFee, setEntranceFee ] = useState("0");
+ // Make sure you give it correct abi and correct function name
const { runContractFunction: getEntranceFee } = useWeb3Contract({
abi: abi,
contractAddress: raffleAddress, // specify the networkId
functionName: "getEntranceFee",
params: {},
})
useEffect(() => {
if (isWeb3Enabled) {
//try to read the Raffle Entrance Feee...
async function UpdateUI() {
const entranceFeeFromCall = await getEntranceFee()
setEntranceFee(entranceFeeFromCall)
console.log(entranceFee)
}
UpdateUI()
}
}, [isWeb3Enabled])
return (
<div>
<h2>
HI From LotteryEntrance!<div>{entranceFee}</div>
</h2>
</div>
)
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Sunil-Reddy-Gummalla
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hii, useState returns an array...., For first error please check you are passing right contractAddress, abi, and functionName