Cloning OpenSea NFT Boilerplate Questions

The data returned from the API will be updated in next API call. You need a refresh button to refresh the data manually.
So every API result will update the state and then the change in state renders the page with new data.

Is there any way to refresh data inside the state without using the refresh button?

It is possible if the transaction or nft data you are fetching is also available in database classes. If the data is available on database you can use live query or subscriptions to auto update the data in your app.

1 Like

Hello I am listing NFTs for sale but for some reason moralis is not displaying “Buy” badge with the image. I checked the moralis dashboard and in there market item is created eg:


transaction hash: 0x0ae95e460b6f34c565159c62d93c4459cf361af80192593e9a20ee78b8464710
I also listed other nfts from the same contract in the marketplace and “buy” badge is displaying on them but mising on some. What might be the reason for this?

I think the buy item badge data is shown as per the data in the synced events table.
Can you check if the latest buy/sell events are synced to this table?

I don’t see any buy/sell sync column in this table. Can you tell me where can I see that information?

Wait, under the _EventSyncStatus I have this row and in this row “isSyncing” is false. Should I change it to true? Asking because I don’t want to mess things up

You can ignore this is_syncing column. Not sure if it is related to event syncing.

In the CreatedMarketItems class, do you see all the items listed for sale?

There will be a column in this class named sold which stores if the NFT is sold or not. I want you to verify if the sold column data is matching the NFT’s shown in your app.

All the columns are correct in the CreatedMarketItem.
Sold: false
Seller: my address
address: marketplace address
confirmed (transaction): true

okay. Do you see any errors in the browser console when you open the collection page?

no errors in the browser console

Did you modify any code in NFTTokenIds.jsx page, that is related to the buy tag.
This is the code that adds the buy tag. Check if this is matching.

And check if you are querying the correct database class in this function.

I checked my code and it’s exactly like yours. I listed some NFTs yesterday and on those NFTs “Buy Now” badge is showing but the ones I listed today there is no “Buy now” badge. Even tho transaction is confirmed on the blockchain and also the columns in the moralis have the desired values. I think it is the syncing issue but I am not sure what to do.

If the data is correct on database it should show the buy the tag. Don’t know what else could go wrong. It cant be a sync issue as the data is shown as per database.

You can try adding a console.log(result) in getMarketItem() function and Manually call this function with the desired NFT to check if the it is retuning the correct data from database.

So I spent some time trying to debug it but still had no success.getMarketItems returns undefined for the NFTs that I listed today. I checked those NFTs in the Moralis dashboard and their row is present with correct values. I don’t understand why the result for some NFTs is undefined even tho their data is present. I logged e.tokenId and their id was undefined.

 const getMarketItem = (nft) => {
    const result = fetchMarketItems?.find(
      (e) =>{
        console.log('e.tokenID',e.tokenId)
        return e.nftContract === nft?.token_address &&
        e.tokenId === nft?.token_id &&
        e.sold === false &&
        e.confirmed === true
        }
      );
      console.log('result',result)
    return result;
  };

Sorry if I am bothering you but I figured out what the issue is. I logged out fetchMarketItems and it is an array of the first 100 rows in the CreatedMarketItem and depending on that array Buy now tags are added to NFTs. I have more than 200 rows in the CreatedMarketItem table. How I do fetch the rest of the NFT details form moralis.

Also when in future someone will list an NFT for sale then rows will increase in CreatedMarketItem table. How will I manage that?

No worries. Glad you figured.
Try changing the slice attribuites NFTTokenIds.jsx to larger number or maybe remove the slice function.

Hope this fixes.

Removing slice hasn’t solved the issue. fetchMarketItems still only fetching first 100 rows.

Ohh…Do you have your code on GitHub?

I can push it to github if you want to have a look.
I came across this https://docs.moralis.io/moralis-dapp/database/live-queries . Maybe live queries can solve the issue for me. In the video he say live queries can be attached to the table so that when an item is created (in my case nft listed) it fires the event and the frontend is updated.
I am really new so I am not sure if I am making any sense right now