1

I'm creating a marketplace where at the homepage I need to show up all the nuts at once on the homepage. Is there way I can make loading faster? It takes a lot of time to fetch data from the chain. I'm a frontend developer working with ethers and hardhat by the way. Here is my function only returning one item at a time contracts are written by somebody else and he is not ready to change the code.

function createCollectible(
    string memory _tokenURI,
    string memory _TIER,
    string memory _BREED_COUNT,
    string memory _AGILITY,
    string memory _WEIGHT,
    string memory _STAMINA,
    string memory _HEALTH,
    string memory _LUCK
) public returns (uint256) {
    uint256 newTokenId = tokenCounter;
    _safeMint(msg.sender, newTokenId);
    _setTokenURI(newTokenId, _tokenURI);
    NFTList[newTokenId] = dog(
        msg.sender,
        block.timestamp,
        _TIER,
        _BREED_COUNT,
        _AGILITY,
        _WEIGHT,
        _STAMINA,
        _HEALTH,
        _LUCK,
        _tokenURI
    );
    tokenCounter = tokenCounter + 1;
    emit CreateCollectible(
        msg.sender,
        block.timestamp,
        _TIER,
        _BREED_COUNT,
        _AGILITY,
        _WEIGHT,
        _STAMINA,
        _HEALTH,
        _LUCK,
        newTokenId
    );
    return newTokenId;
}

Any kind of help would be appreciated. Thanks in advance.

2
  • How are you fetching the NTFs? If you want faster time probably you'll have to implement some sort of cache/indexer for the blockchain queries.
    – Ismael
    May 11, 2022 at 16:55
  • just figured it out just using nft aapis of moralis and building my own on subgraph
    – baibars313
    Aug 26, 2022 at 20:09

1 Answer 1

1

who are coming after watching nadir dabit video I suppose them to check moralis nft apis they have lot m ore surprise you can easily fetch nfts this is moralis docs how we connect moralis with react

https://v1docs.moralis.io/moralis-dapp/connect-the-sdk/connect-with-react

thats the link for nft api

https://v1docs.moralis.io/moralis-dapp/web3-api/nft-api

Returns an object with the NFT count for the specified contract and an NFT array belonging to the given address for the specified contract (asynchronous). Options: chain(optional): The blockchain to get data from. Valid values are listed on Supported Chains. Default value Eth. format (optional): The format of the token id. Available values : decimal, hex. Default value : decimal. cursor (optional): The next page of data to retrieve. Next page cursor value returned from each request. limit(optional): limit (max 100). address (optional): The owner of a given token (i.e. 0x1a2b3x...). If specified, the user attached to the query is ignored and the address will be used instead. token_address(required): Address of the contract


import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
​
const Web3Api = useMoralisWeb3Api();
​
const fetchNFTsForContract = async () => {
  const options = {
    chain: "polygon",
    address: "0x75e3e9c92162e62000425c98769965a76c2e387a",
    token_address: "0x2953399124F0cBB46d2CbACD8A89cF0599974963",
  };
  const polygonNFTs = await Web3Api.account.getNFTsForContract(options);
  console.log(polygonNFTs);
};
2
  • Please, can you expand your answer with an example. It isn't helpful as it is.
    – Ismael
    Aug 29, 2022 at 5:36
  • ok Im going to edit answer
    – baibars313
    Aug 29, 2022 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.