2

I am aware that we could find all the NFTs owned by a user using alchemy’s NFTs API. However, I was wondering if there was a way to them compute the value of that particular users portfolio.

1 Answer 1

3

If you like to get the user's NFT portfolio value, then you can use Moralis to provide you with such data.

Simply sign up to Moralis to get the API key and install the SDK:

npm install moralis

Then, you can copy the following code for getting the value of NFTs that are listed on OpenSea NFT Marketplace, particularly it will return you the trades of NFTs on OpenSea.

import Moralis from 'moralis';

try {
  await Moralis.start({
    apiKey: "YOUR_API_KEY"
  });

  const response = Moralis.EvmApi.nft.getNFTTrades({
    "chain": "eth",
    "marketplace": "opensea",
    "address": "0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB"
  });

  console.log(response.raw);
} catch (e) {
  console.error(e);
}

This shall return you a response with following data structure:

{
  "total": null,
  "page": 0,
  "page_size": 100,
  "cursor": null,
  "result": [
    {
      "transaction_hash": "0x5eba5d8d84c20a7f30b92d74afaee764d9476b62a1637b017319c721269245ed",
      "transaction_index": "90",
      "token_ids": [
        "1002",
        "7228",
        "1",
        "1"
      ],
      "seller_address": "0xe7f35f06a80a6a2a5edc823379fa147d9f9948a8",
      "buyer_address": "0xd7c708080553068217a2fe6f44eccf9cac309915",
      "token_address": "0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb",
      "marketplace_address": "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
      "price": "18980000000000000000",
      "price_token_address": "0x60e4d786628fea6478f785a6d7e704777c86a7c6",
      "block_timestamp": "2022-03-18T22:21:07.000Z",
      "block_number": "14413068",
      "block_hash": "0x50e740dd733efc1e7252e3863e76368624d146e1a8447fab32c9697685cf581d"
    }
  ]
}

and you should be able to use the price field as your NFT value. Of course, if the NFT was never listed then it is hard to value those NFT and therefore can be considered to have zero value.

In addition, if you would like to just use one API provider, Moralis also provides a Get NFTs of an address API in order to fetch the list of user NFTs very easily throughout multiple EVM chains and there are options of non-EVMs as well such as Solana and Aptos.

Hope this helps! Let me know if you have any questions~

P.S. I work at Moralis

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.