POST api/moralis/evmApi/getTokenPrice 404 (Not Found)

I have an array of tokens fetched by useEvmWalletTokenBalances() named tokens.

I then retrieve pricing and receive the error in the heading of this question.

I want to remove all tokens which fail on retrieving the price to be removed (tokens.splice(i,1))

however for some reason the try catch isn’t working for me. Could anyone fix my code to solve this?

const { fetch: native, data: nation } = useEvmNativeBalance()
    const { fetch: tok } = useEvmTokenPrice()

const price = async () => {
     
        const call = []
        for (let i = 0; i < tokens?.length; i++) {
            call.push({ chain: eth, include: "percent_change", address: tokens[i]?.token?.contractAddress })
        }
        const ethPrice = await tok({ chain: eth, include: "percent_change", address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" })

        
      
        const ethe = [{ balance: Number(native?.balance?.ether), price: native?.usdPrice, name: "ETH", change: native?.["24hrPercentChange"] }]

        setETH(ethe)
        for (let i = 0; i < call?.length; i++) {
            const tik = await tok(call[i])
            console.log(tik)

            tokens[i].change = tik?.["24hrPercentChange"]
            tokens[i].pricy = tik?.usdPrice
        }
       
        var walletVal = 0

        for (let i = 0; i < tokens.length; i++) {
            walletVal +=tokens[i]?.pricy * Number(tokens[i].value)
        }
        console.log(walletVal)

        setWalBal(walletVal + (Number(ethe[0]?.balance) * Number(ethe[0]?.price)))

        
    }

Hi @CleanMcGerk

I would recommend using our node js sdk in next js as our MoralisNext package is not upto date with latest next js 13/14 framework rules.

Okay could I please get an example whereby i’d eliminate coins that have no value?

if the above automatically removes tokens without price let me know and I’ll go ahead

Here is the endpoint using which you can get multiple token prices at once. You can fetch upto 25 token prices at once.