PatrickAlphaC / nextjs-nft-marketplace-thegraph-fcc

39 stars 33 forks source link

Lesson 15: Issue with getting TokenURIs #28

Open eugenekhoo1 opened 1 year ago

eugenekhoo1 commented 1 year ago

[Also posted on main repo]

Hi, I am having issues getting the Token URIs using the useWeb3Contract function in NFTBox..as you can see my NFT boxes are not loading due to it being undefined.

Screenshot 2023-06-26 at 4 38 18 PM Screenshot 2023-06-26 at 4 38 32 PM

The issue seems to be with the follow code, but i cant seem to debug it:

const { runContractFunction: getTokenURI } = useWeb3Contract({
    abi: nftAbi,
    contractAddress: nftAddress,
    functionName: "tokenURI",
    params: {
      tokenId: tokenId,
    },
  });

I have checked my subgraph and it does show the correct nftAddress that the getTokenURI function uses as one of it params

Screenshot 2023-06-26 at 4 41 37 PM

I am also able to get the ActiveItems that the 'listings.js' code is calling.

Screenshot 2023-06-26 at 4 44 04 PM

Tried to troubleshoot, but seems like all the params for the useWeb3Contract are in order...so im not too sure what the issue is with loading..

Repos: NextJS code https://github.com/eugenekhoo1/nextjs-nft-marketplace

NFT Contracts https://github.com/eugenekhoo1/hardhat-nft-marketplace

Graph https://github.com/eugenekhoo1/graph-nft-marketplace

helloiampratyush commented 11 months ago

i have resolved this problem..if you still need then tell..

helloiampratyush commented 10 months ago

first of all graph is used for some test network or mainnet so in chainId section do "11155111" instead of "31337" i don`t think you are going to do it by the way..

tusharr1411 commented 4 months ago

With

const { runContractFunction: getTokenURI } = useWeb3Contract({
    abi: nftAbi,
    contractAddress: nftAddress,
    functionName: "tokenURI",
    params: {
      tokenId: tokenId,
    },
  });

you are explicitly telling tokenURI function to accept tokenId as a parameter and assigning it to tokenId variable. However in your BasicNFT.solcontract you have commented out the input tokenId in tokenURI function implementation so useWeb3Contract({..... ,params: {tokenId: tokenId,},}) never assign it to the tokenId variable. So you need to uncomment the input parameter variable of tokenURI function in you BasicNFT smartcontract. So it should be like this

     function tokenURI(uint256 tokenId) public view override returns (string memory) {
        return TOKEN_URI;
    }
Shradhesh71 commented 3 months ago

Can you help me solve this issue? I am experiencing the same problem. (In nextjs-nft-marketplace-thegraph-fcc) i have also uncomment the parameter variable of tokenURI function in you BasicNFT smartcontract.

Screenshot 2024-03-05 023937

tusharr1411 commented 3 months ago

please share your repo

Shradhesh71 commented 3 months ago

When I connect with Hardhat, errors occur; however, when I connect to Sepolia, no errors are shown, and all images are displayed.

When i am Moving blocks... in sepolia network this error are occur:) ProviderError: Unsupported method: evm_mine. See available methods at https://docs.alchemy.com/alchemy/documentation/apis at HttpProvider.request (C:\Users\shrad\Desktop\jgh\hh-BC\hardhat-nft-marketplace\node_modules\hardhat\src\internal\core\providers\http.ts:88:21) at processTicksAndRejections (node:internal/process/task_queues:95:5) at moveBlocks (C:\Users\shrad\Desktop\jgh\hh-BC\hardhat-nft-marketplace\utils\move-blocks.js:11:9)
at mine (C:\Users\shrad\Desktop\jgh\hh-BC\hardhat-nft-marketplace\scripts\mine.js:7:5) error Command failed with exit code 1.

GraphQL NftMarketPlace repo: https://github.com/Shradhesh71/GraphQL_NftMarketPlace Hardhat Nft-MarketPlace repo: https://github.com/Shradhesh71/Nft-MarketPlace

tusharr1411 commented 3 months ago

The evm_mine method used is in moveBlocks is for hardhat network not for sepolia or real testnet.

Coming to hardhat, try again with clearing activity and nonce data ( and make sure you're connected to hardhat network in metamask).

One important thing remember is that you can not query your local blockchain(hardhat) with GRAPH indexer.

Shradhesh71 commented 3 months ago

Thank you @tusharr1411 for helping me with this topic.

RajatSinghhh commented 1 month ago

I am getting a list of all the the active item's tokenId,nftAddress and other props which i am passing to nftBox. My question is this as the tokenUri function takes one value as parameter in the form of tokenId but i am getting all the Active TokenId's in tokenId varaible please help.