Lesson 15: getting undefined for the tokenURI on console #3145
Answered
by
narendra-sajwani
narendra-sajwani
asked this question in
Q&A
-
In Lesson 15, at timestamp 1:02:59:16 / 1:07:54:30, where we are checking for the tokenURI on console, I am getting undefined. I have checked all possibilities like correct nftAddress, tokenId, correct nftAbi. Couldn't figure out what's going wrong? Here is the respective code in NFTBox component: import { useEffect, useState } from "react"
import { useWeb3Contract, useMoralis } from "react-moralis"
import nftMarketplaceAbi from "../constants/NftMarketplace.json"
import nftAbi from "../constants/BasicNft.json"
export default function NFTBox({ price, nftAddress, tokenId, marketplaceAddress, seller }) {
const { isWeb3Enabled } = useMoralis()
const { imageURI, setImageURI } = useState("")
const { runContractFunction: getTokenURI } = useWeb3Contract({
abi: nftAbi,
contractAddress: nftAddress,
functionName: "tokenURI",
params: {
tokenId: tokenId,
},
})
async function updateUI() {
// get the tokenURI
// using the image tag from the tokenURI, get the image
const tokenURI = await getTokenURI()
console.log(tokenURI)
}
useEffect(() => {
if (isWeb3Enabled) {
updateUI()
}
}, [isWeb3Enabled])
} The complete repo link is nft-moralis-repo Could someone please help? |
Beta Was this translation helpful? Give feedback.
Answered by
narendra-sajwani
Oct 8, 2022
Replies: 1 comment
-
Resolved it finally! Figured out that I wasn't conencted to any of the hardhat accounts on localhost in metamask. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
narendra-sajwani
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Resolved it finally! Figured out that I wasn't conencted to any of the hardhat accounts on localhost in metamask.