getAllTokensId returning empty data [SOLVED]

Guys im starting to learning solidity now, and im the Ultimate NFT Programming Tutorial - FULL COURSE from Moralis Web3 Youtube, excelent tutorial btw. Im having some troubles to retrieve getAllTokensIds from my ACCOUNT ADDRESS, the return is empty. What can be this problem? What i need to do to solve this, is on remix ethereum? When i use the ACCOUNT ADDRESS that is used in video, returns all data.

Thanks!!

Could you send an example address and a chain?

I’ve these 3, all in rinkeby chain.

const CONTRACT_ADDRESS_ACCOUNT1 = “0x64A9be3A6E71896012F8ec12a23e4B6214a9F6aB”;

const CONTRACT_ADDRESS_DEV = “0xbA10Ef17C48749c246CC49Fb50ca16755bc8311e”;

const CONTRACT_ADDRESS_DEV2 = “0x9ac0FD9144f69f59dB582BFf9c11C4e3b4C7dff6”;

These are adresses of a wallet, not of a contract

Your wallet 0x9ac0FD9144f69f59dB582BFf9c11C4e3b4C7dff6 has NFT:
0x906e8acd2ca5a8625b9d66bb20cb4f38b1ca34a4

const options = {
          address: "0x906e8acd2ca5a8625b9d66bb20cb4f38b1ca34a4", //contract address
          chain: "rinkeby"
        };
        const NFTs = await Moralis.Web3API.token.getAllTokenIds(options);
        console.log(NFTs);

i just change the address but is showing the same result, why?

Note! This serverURL and ApplicationId is from video. When i try with my server shows errors too.

!

I can not debug your screens

https://docs.moralis.io/moralis-server/web3-sdk/token#getalltokenids

getAllTokenIds
Returns an object with number of NFTs and an array with NFT metadata (name, symbol) for a given token contract address (asynchronous).

This api call doesn’t depend on what Moralis server you are using, it will return same thing.

2 Likes

Please send your code as a code and addresses. Thanks :raised_hands:

I suggest you to add the console.log() to your code to find the place where the data is incorrect

Moralis.initialize("zUAslaQCPxdWxFtnIAPVbkc9LUNAjOoN8eMCKgTw");
Moralis.serverURL = "https://suwkhta9idij.usemoralis.com:2053/server";
const CONTRACT_ADDRESS = "0x57bb84aB1624c444Fc835540b6fF7414400E4ef9";

function fetchNFTMetadata(NFTs) {
    console.log(NFTs)
    let promises = [];
    for (let i = 0; i < NFTs.length; i++) {
        let nft = NFTs[i];
        let id = nft.token_id;
        //Call moralis cloud function -> static json file
        promises.push(fetch("https://suwkhta9idij.usemoralis.com:2053/server/functions/getNFT?_ApplicationId=zUAslaQCPxdWxFtnIAPVbkc9LUNAjOoN8eMCKgTw&nftId=" + id)
        .then(res => res.json())
        .then(res => JSON.parse(res.result))
        .then(res => {nft.metadata = res})
        .then(res => {
            const options = { address: CONTRACT_ADDRESS, token_id : id, chain: "rinkeby" };
            return Moralis.Web3API.token.getTokenIdOwners(options)
        })
        .then( (res) => {
            nft.owners = [];
            res.result.forEach(element => {
                nft.owners.push(element.ownerOf);
            });

            return nft;
        }))
    }
    return Promise.all(promises);
}

function renderInventory (NFTs) {
    const parent = document.getElementById("app");
    for (let i = 0; i < NFTs.length; i++) {
        const nft = NFTs[i];
        console.log(nft)
        let htmlString = `
        
        <div class="card">
            <img class="card-img-top" src="${nft.metadata.image}" alt="Card image cap">
            <div class="card-body">
                <h5 class="card-title">${nft.metadata.name}</h5>
                <p class="card-text">${nft.metadata.description}</p>
                <p class="card-text">Tokens in circulation: ${nft.amount}</p>
                <p class="card-text">Number of Owners: ${nft.owners.length}</p>
                <a href="/mint.html?nftId=${nft.token_id}" class="btn btn-primary">Mint</a>
            </div>
        </div>
        `
        let col = document.createElement("div");
        col.className = "col col-md-3"
        col.innerHTML = htmlString;
        parent.appendChild(col);
    }
}

async function initializeApp() {
    let currentUser = Moralis.User.current();
    
    if (!currentUser) {
        currentUser = await Moralis.Web3.authenticate();
    }

    const options = { address: CONTRACT_ADDRESS, chain: "rinkeby" }
    let NFTs = await Moralis.Web3API.token.getAllTokenIds(options);
    let NFTWithMetadata = await fetchNFTMetadata(NFTs.result);
    renderInventory(NFTWithMetadata);
}

initializeApp();
1 Like

i just uploaded the code on Github.

You need to create your own server, and make own cloud function. You see the same result because data is fetched from Filip’s server

Moralis.Web3API.token.getAllTokenIds() itself works correctly

Now i understand whats the error… the main problem is that i need to use my own cloud functions, but the httpRequest was wrong… The problem was solved, thanks a lot guys…

1 Like