Moralis.EvmApi.token.getMultipleTokenPrices function does not exist

The Moralis.EvmApi.token.getMultipleTokenPrices function does not exist. It has been altered or deprecated, as I discovered in the documentation: https://docs.moralis.io/web3-data-api/evm/reference/get-multiple-token-prices?tokens=[]&chain=eth&include=percent_change. I tested it according to the documentation, but this function is not working in my code. Please help.

Hi @bjolbordi, can you please share the exact error you are getting? and also share your code (where you are calling this endpoint) so we can try to replicate this?

1 Like
       try {
            
           const tokens = [{ to_block: 16314545, token_address: "0xae7ab96520de3a18e5e111b5eaab095312d7fe84", exchange: "uniswapv2" }];
         
            const response = await Moralis.EvmApi.token.getMultipleTokenPrices({ chain: 'eth', include: 'percent_change', body: { tokens } });
            console.log(response.raw);
        } catch (e) {
            console.error(e);
        }

TypeError: Moralis.EvmApi.token.getMultipleTokenPrices is not a function , Only this function is not working all other morelis functions working good.

Hi @bjolbordi

Please try upgrading to the latest sdk. This seems to have released in the last week. Here is an example on how to test it.

const response = await Moralis.EvmApi.token.getMultipleTokenPrices(
  {
    chain: "0x1",
    include: "percent_change",
  },
  {
    tokens: [
      {
        tokenAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7",
      },
    ],
  }
);
1 Like

I was assessing the getMultipleTokenPrices endpoint and came across an error. This error arises when a token lacks a price for a certain block. Additionally, I applied the same method on the Moralis platform where it functions correctly; the first object’s response is normal, and the second object, which cannot find a price, returns null. However, in my code, it results in an error:

Failed to fetch token prices: TypeError: Cannot read properties of null (reading ‘tokenName’)

const response = await Moralis.EvmApi.token.getMultipleTokenPrices({
                "chain": "0x38",
                include: "percent_change"
            }, {
                "tokens": [
                    {
                      "tokenAddress": "0x3be9e3b7bfeab71fe2a8ea2e12f5bb6d5a1a2da1",
                      "toBlock": "0x0118adeb"
                    },
                    {
                      "tokenAddress": "0x3be9e3b7bfeab71fe2a8ea2e12f5bb6d5a1a2da1",
                      "toBlock": "0x013c3409"
                    }
                  ]
            });

This is my code :

// Import Moralis
const Moralis = require("moralis").default;



// Function to run your Moralis code
async function runMoralisCode() {
  try {
   await Moralis.start({  apiKey: "my api key" });
    // Start Moralis session

    // Get multiple token prices
    const response = await Moralis.EvmApi.token.getMultipleTokenPrices({
        "chain": "0x38",
        "include": "percent_change"
      },{
        "tokens": [
          {
            "tokenAddress": "0x3be9e3b7bfeab71fe2a8ea2e12f5bb6d5a1a2da1",
            "toBlock": "0x013c3409"
          },
          {
            "tokenAddress": "0x3be9e3b7bfeab71fe2a8ea2e12f5bb6d5a1a2da1",
            "toBlock": "0x0118adeb"
          }
        ]
      });
      console.log(response);
    } catch (e) {
      console.error(e);
    }
}

// Execute the function
runMoralisCode();

I got this error :
TypeError: Cannot read properties of null (reading ‘tokenName’)

But same code in moralis live test platform is working and getting first object and second is null :

[
  {
    "tokenName": "Braination",
    "tokenSymbol": "BRN",
    "tokenLogo": null,
    "tokenDecimals": "9",
    "nativePrice": {
      "value": "69643900495",
      "decimals": 18,
      "name": "Binance Chain Native Token",
      "symbol": "BNB",
      "address": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"
    },
    "usdPrice": 0.000020819972610138,
    "usdPriceFormatted": "0.000020819972610138",
    "exchangeName": "PancakeSwap v2",
    "exchangeAddress": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
    "tokenAddress": "0x3be9e3b7bfeab71fe2a8ea2e12f5bb6d5a1a2da1",
    "toBlock": "20722697",
    "priceLastChangedAtBlock": "20702339",
    "verifiedContract": false,
    "24hrPercentChange": "2.042814537335242"
  },
  null
]

I used curl and it is now working but with sdk was above problem

Thanks for the report. Let me pass it to the devs🙏

1 Like

Hi @bjolbordi

The issue has been fixed.
The null returned in the response is causing the issue so we have removed the null item from the result array. SDK should run without any error now.

1 Like