Did you know that with Moralis’ next-generation nodes, you can get NFT balances with just one RPC call? Our Extended RPC Methods and the eth_getNFTBalances endpoint make fetching NFT balances a breeze. Eager to learn how it works? Check out the endpoint in action below:

import fetch from 'node-fetch';

const options = {
 method: 'POST',
 headers: {
   accept: 'application/json',
   'content-type': 'application/json'
 },
 body: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getNFTBalances",
   "params": [
     {
       "address": "0xDc597929101c2DE50c97D43C8EA3A372Bf55fdc0",
       "limit": 10,
     }
   ]
 })
};

fetch('YOUR_NODE_URL', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

By calling the script above, you’ll receive the NFT balances of the specified wallet, enriched with metadata, addresses, collection data, and more. Here’s what it might look like:

{
  jsonrpc: '2.0',
  id: 1,
  result: {
    //...
    result: [
          {
      amount: '1',
      token_id: '1919',
      token_address: '0xbd3531da5cf5857e7cfaa92426877b022e612cf8',
      contract_type: 'ERC721',
      owner_of: '0xdc597929101c2de50c97d43c8ea3a372bf55fdc0',
      last_metadata_sync: '2024-08-25T23:35:51.384Z',
      last_token_uri_sync: '2024-08-25T23:35:50.893Z',
      metadata: '{"attributes":[{"trait_type":"Background","value":"Mint"},{"trait_type":"Skin","value":"Olive Green"},{"trait_type":"Body","value":"Turtleneck Pink"},{"trait_type":"Face","value":"Eyepatch"},{"trait_type":"Head","value":"Wizard Hat"}],"description":"A collection 8888 Cute Chubby Pudgy Penquins sliding around on the freezing ETH blockchain.","image":"ipfs://QmNf1UsmdGaMbpatQ6toXSkzDpizaGmC9zfunCyoz1enD5/penguin/1919.png","name":"Pudgy Penguin #1919"}',
      block_number: '19754671',
      block_number_minted: null,
      name: 'PudgyPenguins',
      symbol: 'PPG',
      token_hash: 'cbd8bd0901f422afb88e76615e3d2a1a',
      token_uri: 'https://ipfs.developers.moralis.com:2053/ipfs/bafybeibc5sgo2plmjkq2tzmhrn54bk3crhnc23zd2msg4ea7a4pxrkgfna/1919',
      minter_address: null,
      verified_collection: true,
      possible_spam: false,
      collection_logo: 'https://i.seadn.io/gae/yNi-XdGxsgQCPpqSio4o31ygAV6wURdIdInWRcFIl46UjUQ1eV7BEndGe8L661OoG-clRi7EgInLX4LPu9Jfw4fq0bnVYHqg7RFi?w=500&auto=format',
      collection_banner_image: 'https://i.seadn.io/gcs/files/8a26e3de0f309089cbb1e5ab969fc0bc.png?w=500&auto=format'
    	},
      //...
    ]
  }
}

That’s it! Fetching NFT balances requires only one RPC call when leveraging Moralis and our top-tier nodes. To learn more, join us in this tutorial or visit the eth_getNFTBalances documentation page.

You can also watch the Moralis YouTube video below to learn how to get the NFT balances of a wallet using ethers.js:

Ready to start using our Extended RPC Methods? Sign up for a free account with Moralis today!

Overview

Fetching the NFT balances of a wallet using RPC requests can be a bothersome and time-consuming task. With conventional methods, such as eth_call, it takes many requests, extensive manual data aggregation, and a lot of effort to get the data you need. Fortunately, there’s now a better alternative: Moralis’ Extended RPC Methods. 

Moralis logo.

But what exactly are our Extended RPC Methods? And how can they help you get NFT balances with just one RPC request? For the answers to these questions, join us in this article as we lay it all out for you. Let’s dive straight in! 

Moralis’ Next-Generation RPC Nodes – The Best Way to Get NFT Balances

Moralis is a prominent provider of top-tier, next-generation RPC nodes. With our intuitive user interface, you can set up nodes for all major chains with the click of a few buttons. Some supported chains include Ethereum, Polygon, BNB Smart Chain (BSC), Optimism, and Base. 

Moralis RPC nodes.

But why should you choose Moralis as your node provider?

  • Speed: With response times from 70 ms, we set the industry benchmark for speed. 
  • Reliability: Our nodes boast an impressive 99.9% uptime, giving you top-tier reliability. 
  • Secure: Protect your company’s data by choosing Moralis as your trusted SOC 2 Type 2 partner. 

In addition to high speed, impressive reliability, and enterprise-grade security, Moralis also provides Extended RPC Methods.

But what are they? And how do they work? 

Join us in the next section to find out!

Extended RPC Methods

Our Extended RPC Methods make it easy for you to fetch decoded, human-readable data via RPC nodes. A single call gives you NFT balances, decoded transactions, token prices, metadata, and much more. As such, when leveraging our next-generation nodes, you can streamline your developer experience and fetch on-chain data via RPC-style requests without breaking a sweat. 

Moralis Extended RPC Methods.

What methods are available? 

  • eth_getNFTBalances: Fetch the NFT balance of a wallet. 
  • eth_getNFTCollections: Get the collections held by a wallet.
  • eth_getTransactions: Query the native transaction history of a wallet. 
  • eth_getDecodedTransactions: Get a wallet’s full transaction history. 
  • eth_getTokenBalances: Fetch the ERC-20 balances of a wallet.
  • eth_getTokenMetadata: Get ERC-20 token metadata. 
  • eth_getTokenPrice: Access the price of any ERC-20 token. 

All in all, with the methods above, you can effortlessly fetch decoded, human-readable data using RPC-style requests.

eth_getNFTBalances – Easiest Way to Get NFT Balances with One RPC Call

The eth_getNFTBalances method is your go-to choice if you’re looking for an easy way to get NFT balances with just one RPC call. This method provides a full list of the specified wallet’s NFTs, enriched with metadata, addresses, symbols, collection data, and much more. As such, it has never been easier to get the NFT balances of a wallet using RPC nodes. 

Wallet surrounded by NFT and tokens.

But how exactly does this work? And what does an actual response look like? For the answers to these questions, join us in the next section, where we’ll walk you through a full tutorial on how to get NFT balances of a wallet with just one RPC request! 

Full Tutorial: Get the NFT Balances of a Wallet with One RPC Call

With our Extended RPC Methods and the eth_getNFTBalances endpoint, you can seamlessly get NFT Balances in three simple steps: 

  1. Sign up with Moralis & set up a node.
  2. Write a script calling eth_getNFTBalances.
  3. Run the code.

However, before we can get going, you need to handle a few prerequisites.

Prerequisites

Before you can get going with the tutorial, make sure you have the following ready: 

Step 1: Sign Up with Moralis & Set Up a Node

Hit the ”Start for Free” button at the top right and sign up for a free account with Moralis: 

Red arrow pointing at "Start for Free" button.

Log in, go to the ”Nodes” tab, and click ”+ Create Node” to set up a node: 

Red arrows pointing at "Nodes" tab and "+ Create Node" button.

Select ”Ethereum,” followed by ”Mainnet,” and click ”Create Node”: 

Ethereum node configurations.

Copy and keep one of your node URLs, as you’ll need it in the next step: 

Red arrows pointing at copy button for RPC node URLs.

Step 2: Write a Script Calling eth_getNFTBalances

Create a folder in your integrated development environment (IDE), open a new terminal, and run this command to initialize a new project:

npm init

Install the required dependencies with these terminal commands:

npm install node-fetch --save
npm install moralis @moralisweb3/common-evm-utils

Open your “package.json” file and add "type": "module" to the list:

"type": "module" highlighted in code editor.

Set up a new “index.js” file and add the following code:

import fetch from 'node-fetch';

const options = {
 method: 'POST',
 headers: {
   accept: 'application/json',
   'content-type': 'application/json'
 },
 body: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getNFTBalances",
   "params": [
     {
       "address": "0xDc597929101c2DE50c97D43C8EA3A372Bf55fdc0",
       "limit": 10,
     }
   ]
 })
};

fetch('YOUR_NODE_URL', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

Replace YOUR_NODE_URL with the URL you copied during the first step, and configure the address parameter to fit your request:

Red arrows pointing at address and YOUR_NODE_URL parameters in code editor.

Step 3: Run the Code

Run this terminal command in your project’s root folder to execute the script:

node index.js

By running the script, you’ll receive an array of all tokens owned by the specified address. The response is enriched with metadata, addresses, symbols, collection data, and more for each element. Here’s a sample response:

{
  jsonrpc: '2.0',
  id: 1,
  result: {
    //...
    result: [
          {
      amount: '1',
      token_id: '1919',
      token_address: '0xbd3531da5cf5857e7cfaa92426877b022e612cf8',
      contract_type: 'ERC721',
      owner_of: '0xdc597929101c2de50c97d43c8ea3a372bf55fdc0',
      last_metadata_sync: '2024-08-25T23:35:51.384Z',
      last_token_uri_sync: '2024-08-25T23:35:50.893Z',
      metadata: '{"attributes":[{"trait_type":"Background","value":"Mint"},{"trait_type":"Skin","value":"Olive Green"},{"trait_type":"Body","value":"Turtleneck Pink"},{"trait_type":"Face","value":"Eyepatch"},{"trait_type":"Head","value":"Wizard Hat"}],"description":"A collection 8888 Cute Chubby Pudgy Penquins sliding around on the freezing ETH blockchain.","image":"ipfs://QmNf1UsmdGaMbpatQ6toXSkzDpizaGmC9zfunCyoz1enD5/penguin/1919.png","name":"Pudgy Penguin #1919"}',
      block_number: '19754671',
      block_number_minted: null,
      name: 'PudgyPenguins',
      symbol: 'PPG',
      token_hash: 'cbd8bd0901f422afb88e76615e3d2a1a',
      token_uri: 'https://ipfs.developers.moralis.com:2053/ipfs/bafybeibc5sgo2plmjkq2tzmhrn54bk3crhnc23zd2msg4ea7a4pxrkgfna/1919',
      minter_address: null,
      verified_collection: true,
      possible_spam: false,
      collection_logo: 'https://i.seadn.io/gae/yNi-XdGxsgQCPpqSio4o31ygAV6wURdIdInWRcFIl46UjUQ1eV7BEndGe8L661OoG-clRi7EgInLX4LPu9Jfw4fq0bnVYHqg7RFi?w=500&auto=format',
      collection_banner_image: 'https://i.seadn.io/gcs/files/8a26e3de0f309089cbb1e5ab969fc0bc.png?w=500&auto=format'
    	},
      //...
    ]
  }
}

Beyond How to Get NFT Balances with One RPC Call – Exploring Other Extended RPC Methods

Fetching the NFT balances of a wallet is only one of the many things you can do with our Extended RPC Methods. As such, let’s take a deeper dive into three other methods: 

  1. eth_getTransactions
  2. eth_getDecodedTransactions
  3. eth_getTokenBalances

eth_getTransactions

With the eth_getTransactions method, you can now easily get wallet transactions using RPC nodes with just one call. This means you no longer have to bother with endless requests, giving you a significantly more streamlined developer experience. Here’s an example showing the method in action: 

import fetch from 'node-fetch';

const options = {
 method: 'POST',
 headers: {
   accept: 'application/json',
   'content-type': 'application/json'
 },
 body: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getTransactions",
   "params": [
     {
       "address": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
       "limit": 100,
     }
   ]
 })
};

fetch('YOUR_NODE_URL', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In return for running the script above, you’ll get a list of the wallet’s past native transactions. Furthermore, each transaction is enriched with timestamps, address labels, gas prices, and more. Here’s what it might look like: 

{
  //...
    result: [
      {
        hash: '0xd89b02f289a08ae7b2feead06031fec20777bad8b73fc8d853f9040bc423a6c7',
        nonce: '0',
        transaction_index: '142',
        from_address: '0xda74ac6b69ff4f1b6796cddf61fbdd4a5f68525f',
        from_address_label: '',
        to_address: '0xdac17f958d2ee523a2206206994597c13d831ec7',
        to_address_label: 'Tether USD (USDT)',
        value: '0',
        gas: '207128',
        gas_price: '17020913648',
        input: '0xa9059cbb00000000000000000000000028c6c06298d514db089934071355e5743bf21d6000000000000000000000000000000000000000000000000000000017a1df1700',
        receipt_cumulative_gas_used: '8270587',
        receipt_gas_used: '41309',
        receipt_contract_address: null,
        receipt_root: null,
        receipt_status: '1',
        block_timestamp: '2023-01-22T15:00:11.000Z',
        block_number: '16463098',
        block_hash: '0x2439330d0a282f9a6464b0aceb9f766ac4d7b050c048b4a1322b48544c61e01d',
        transaction_fee: '0.000703116921885232'
      },
      //...
    ]
  }
}

eth_getDecodedTransactions

The eth_getDecodedTransactions method allows you to easily get decoded wallet history using an RPC node. With just one request, you can seamlessly fetch any wallet’s full history, including native transactions, ERC-20 transfers, NFT transfers, and more. Here’s a script showing how eth_getDecodedTransactions works in practice: 

import fetch from 'node-fetch';

const options = {
 method: 'POST',
 headers: {
   accept: 'application/json',
   'content-type': 'application/json'
 },
 body: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getDecodedTransactions",
   "params": [
     {
       "address": "0xda74Ac6b69Ff4f1B6796cdDf61fBDd4A5f68525f",
     }
   ]
 })
};

fetch('YOUR_NODE_URL', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In return for executing the script above, you’ll get the wallet’s full history. What’s more, each transaction is enriched with category tags, event summaries, address labels, and other useful information. Here’s a sample response: 

{
  //...
    "result": [
      {
        "block_hash": "0x660274d577cd20b0b82c1bff5f3c5641ba6027544e005f9256d5add9c7447920",
        "block_number": "19868695",
        "block_timestamp": "2024-05-14T14:00:23.000Z",
        "from_address": "0xda74ac6b69ff4f1b6796cddf61fbdd4a5f68525f",
        "from_address_label": null,
        "from_address_entity": null,
        "from_address_entity_logo": null,
        "to_address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
        "to_address_label": "Tether USD (USDT)",
        "to_address_entity": null,
        "to_address_entity_logo": null,
        "gas": "55331",
        "gas_price": "13623172301",
        "hash": "0xc565260238f59fc3f35b74f3011375c7d637db9b075f77d342c30d19f946272e",
        "nonce": "14",
        "receipt_cumulative_gas_used": "13917979",
        "receipt_gas_used": "41309",
        "receipt_status": "1",
        "transaction_fee": "0.000562759624582009",
        "transaction_index": "75",
        "value": "0",
        "receipt_contract_address": null,
        "nft_transfers": [],
        "erc20_transfers": [
          {
            "token_name": "Tether USD",
            "token_symbol": "USDT",
            "token_logo": "https://logo.developers.moralis.com/0x1_0xdac17f958d2ee523a2206206994597c13d831ec7_3282f332c2ac2948929f01fe7d921c51",
            "token_decimals": "6",
            "from_address": "0xda74ac6b69ff4f1b6796cddf61fbdd4a5f68525f",
            "from_address_entity": null,
            "from_address_entity_logo": null,
            "from_address_label": null,
            "to_address": "0x28c6c06298d514db089934071355e5743bf21d60",
            "to_address_label": "Binance 14",
            "to_address_entity": "Binance",
            "to_address_entity_logo": "https://entities-logos.s3.us-east-1.amazonaws.com/binance.png",
            "address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
            "log_index": 338,
            "value": "50000000000",
            "possible_spam": false,
            "verified_contract": true,
            "direction": "send",
            "value_formatted": "50000"
          }
        ],
        "method_label": "transfer",
        "native_transfers": [],
        "summary": "Sent 50,000 USDT to Binance 14",
        "possible_spam": false,
        "category": "token send"
      },
      //...
    }
  ]
}

eth_getTokenBalances

With Moralis’ eth_getTokenBalances method, you can effortlessly get ERC-20 token balances using RPC nodes. This means you no longer have to make multiple requests and stitch the data together yourself. One request and you get all the information you need. Here’s an example showing the method in action:

import fetch from 'node-fetch';

const options = {
 method: 'POST',
 headers: {
   accept: 'application/json',
   'content-type': 'application/json'
 },
 body: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getTokenBalances",
   "params": [
     {
       "address": "0xcB1C1FdE09f811B294172696404e88E658659905",
     }
   ]
 })
};

fetch('YOUR_NODE_URL', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

Calling the script above gives you the ERC-20 token balances of the specified address. Moreover, all tokens in the list will be enriched with logos, decimals, spam indicators, thumbnails, and more. Here’s a sample response: 

{
  //...
  result: [
    {
      token_address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
      name: 'Wrapped Ether',
      symbol: 'WETH',
      decimals: 18,
      logo: 'https://logo.developers.moralis.com/0x1_0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_a578c5277503e547a072ae32517254ca',
      thumbnail: 'https://logo.developers.moralis.com/0x1_0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_a578c5277503e547a072ae32517254ca',
      balance: '10000000000000000',
      possible_spam: false,
      verified_contract: true,
      total_supply: '2746607222348759943423350',
      total_supply_formatted: '2746607.22234875994342335',
      percentage_relative_to_total_supply: 3.64085549569e-7
    },
    //...
  ]
}

To learn more about all our methods, please visit the official Extended RPC Methods documentation page. 

Diving Deeper Into Moralis’ Web3 APIs

Moralis is the industry’s leading Web3 data provider, and in addition to our Extended RPC Methods, we offer a comprehensive suite of Web3 APIs, such as the Wallet API, Token API, Streams API, and more. With Moralis, you get all crypto data in one place.

Moralis logo.

But what makes our Web3 APIs unique?

  • One Call – All Data: Our APIs are outcome-oriented, providing more data with fewer requests. Get token balances, a wallet’s full history, NFT metadata, and much more with a single call.
  • Cross-Chain: Moralis offers full feature parity across major chains, including Ethereum, Polygon, Optimism, BSC, Base, and others.
  • Security & Reliability: Moralis is SOC 2 Type 2 certified, highlighting our commitment to providing enterprise-grade security and reliability.

To learn more about our suite of leading development tools, let’s dive into three of our prominent APIs!

Wallet API

Moralis’ Wallet API is the ultimate tool if you’re looking to build wallets or integrate wallet functionality into your dapps. With this premier interface, you can effortlessly get a wallet’s full history, token balances, NFT balances, net worth, profitability, and much more. 

Wallet API.

To highlight the power of this tool, let’s take a look at one of our endpoints in action. For instance, this is how easy it is to fetch the net worth of a wallet: 

import fetch from 'node-fetch';

const options = {
 method: 'GET',
 headers: {
   accept: 'application/json',
   'X-API-Key': 'YOUR_API_KEY'
 },
};

fetch('https://deep-index.developers.moralis.com/api/v2.2/wallets/0x1f9090aaE28b8a3dCeaDf281B0F12828e676c326/net-worth', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In return for calling the script above, you’ll get the total net worth of the specified wallet, along with individual chain breakdowns. Here’s a sample response: 

{
  total_networth_usd: '9906.41',
  chains: [
    {
      chain: 'eth',
      native_balance: '3138317588449827590',
      native_balance_formatted: '3.13831758844982759',
      native_balance_usd: '8069.70',
      token_balance_usd: '1836.70',
      networth_usd: '9906.41'
    }
  ]
}

So, if you’re looking for an impressive array of features, top-tier flexibility, and unparalleled scalability, make sure to check out the Wallet API! 

Token API

The Token API is your go-to tool for ERC-20 data. This premier interface covers all tokens across all the biggest chains, including stablecoins like USDC, meme coins like Shiba Inu, and everything in between. 

Token API.

With the Token API, you can seamlessly fetch token balances, prices, transfers, metadata, and much more. To showcase the accessibility of this tool, here’s a sample script showing you how easy it is to get the price of a token: 

import fetch from 'node-fetch';

const options = {
 method: 'GET',
 headers: {
   accept: 'application/json',
   'X-API-Key': 'YOUR_API_KEY'
 },
};

fetch('https://deep-index.developers.moralis.com/api/v2.2/erc20/0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0/price?chain=eth&include=percent_change', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In return for calling the script above, you’ll get the price of the token denominated in both the native currency and USD. Here’s what it might look like: 

{
  tokenName: 'Matic Token',
  tokenSymbol: 'MATIC',
  tokenLogo: 'https://logo.developers.moralis.com/0x1_0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0_89c931b3fcf74fe39db7a195bf8a3aa5',
  tokenDecimals: '18',
  nativePrice: {
    value: '172371569340575',
    decimals: 18,
    name: 'Ether',
    symbol: 'ETH',
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
  },
  usdPrice: 0.44344021067602557,
  usdPriceFormatted: '0.443440210676025551',
  exchangeName: 'Uniswap v3',
  exchangeAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
  tokenAddress: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0',
  priceLastChangedAtBlock: '20634460',
  blockTimestamp: '1724937179000',
  possibleSpam: false,
  verifiedContract: true,
  pairAddress: '0x290a6a7460b308ee3f19023d2d00de604bcf5b42',
  pairTotalLiquidityUsd: '1592811.47',
  '24hrPercentChange': '-1.1406370639269006',
  securityScore: 55
}

If you’re looking to build platforms like DEXs, token explorers, or other similar projects, make sure to start using the Token API! 

NFT API

Moralis’ NFT API is the ultimate interface for NFT data, covering over three million NFT collections and counting across all major chains, including Ethereum, Polygon, BSC, Base, and many more. With this premier interface, you only need single lines of code to get NFT balances, metadata, prices, etc. 

NFT API.

To highlight the power of this tool, check out the example script below, showing you how easy it is to get the metadata of an NFT: 

import fetch from 'node-fetch';

const options = {
 method: 'GET',
 headers: {
   accept: 'application/json',
   'X-API-Key': 'YOUR_API_KEY’
 },
};

fetch('https://deep-index.developers.moralis.com/api/v2.2/nft/0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB/200?chain=eth', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In return for executing the code above, you’ll get the metadata of the specified NFT, enriched with addresses, collection data, rarity indicators, and much more. Here’s what it might look like: 

{
  amount: '1',
  token_id: '200',
  token_address: '0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb',
  contract_type: 'CRYPTOPUNKS',
  owner_of: '0xa858ddc0445d8131dac4d1de01f834ffcba52ef1',
  last_metadata_sync: '2024-08-29T17:03:32.616Z',
  last_token_uri_sync: '2024-08-29T17:03:32.302Z',
  metadata: '{"image":"https://www.larvalabs.com/cryptopunks/cryptopunk200.png","name":"CryptoPunk 200","attributes":["Wild Hair"],"description":"Female"}',
  block_number: '14401717',
  block_number_minted: null,
  name: 'CRYPTOPUNKS',
  symbol: 'Ͼ',
  token_hash: 'dec72aa6108829bae90dc826a9204c24',
  token_uri: 'Invalid uri',
  minter_address: null,
  rarity_rank: 469,
  rarity_percentage: 4.69,
  rarity_label: 'Top 5%',
  verified_collection: true,
  possible_spam: false,
  collection_logo: 'https://i.seadn.io/gae/BdxvLseXcfl57BiuQcQYdJ64v-aI8din7WPk0Pgo3qQFhAUH-B6i-dCqqc_mCkRIzULmwzwecnohLhrcH8A9mpWIZqA7ygc52Sr81hE?w=500&auto=format',
  collection_banner_image: 'https://i.seadn.io/gae/48oVuDyfe_xhs24BC2TTVcaYCX7rrU5mpuQLyTgRDbKHj2PtzKZsQ5qC3xTH4ar34wwAXxEKH8uUDPAGffbg7boeGYqX6op5vBDcbA?w=500&auto=format'
}

With the NFT API, you can seamlessly integrate NFT data into your NFT marketplace, Web3 game, or other platform that needs this information! 

If you want to explore all our premier interfaces, please check out our official Web3 API page! 

Summary: How to Get NFT Balances with One RPC Call 

Querying the NFT balances of a wallet can be a time-consuming and resource-intensive process. With conventional methods, it takes multiple requests and a lot of manual data aggregation, making it a bothersome task. Fortunately, you now have the option to streamline your developer experience using Moralis’ Extended RPC Methods. 

Wallet with NFTs and tokens on a platform.

Our Extended RPC Methods make querying decoded data using RPC nodes a breeze. With single RPC requests, you can now fetch NFT balances, token balances, decoded transactions, token prices, and much more. 

For instance, check out our eth_getNFTBalances method in action, showing you how easy it is to get NFT balances with just one RPC call: 

import fetch from 'node-fetch';

const options = {
 method: 'POST',
 headers: {
   accept: 'application/json',
   'content-type': 'application/json'
 },
 body: JSON.stringify({
   "jsonrpc": "2.0",
   "id": 1,
   "method": "eth_getNFTBalances",
   "params": [
     {
       "address": "0xDc597929101c2DE50c97D43C8EA3A372Bf55fdc0",
       "limit": 10,
     }
   ]
 })
};

fetch('YOUR_NODE_URL', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In return for calling the script above, you’ll get the full NFT balance of the specified wallet, enriched with metadata, collection data, and much more. Here’s what it might look like: 

{
  jsonrpc: '2.0',
  id: 1,
  result: {
    //...
    result: [
          {
      amount: '1',
      token_id: '1919',
      token_address: '0xbd3531da5cf5857e7cfaa92426877b022e612cf8',
      contract_type: 'ERC721',
      owner_of: '0xdc597929101c2de50c97d43c8ea3a372bf55fdc0',
      last_metadata_sync: '2024-08-25T23:35:51.384Z',
      last_token_uri_sync: '2024-08-25T23:35:50.893Z',
      metadata: '{"attributes":[{"trait_type":"Background","value":"Mint"},{"trait_type":"Skin","value":"Olive Green"},{"trait_type":"Body","value":"Turtleneck Pink"},{"trait_type":"Face","value":"Eyepatch"},{"trait_type":"Head","value":"Wizard Hat"}],"description":"A collection 8888 Cute Chubby Pudgy Penquins sliding around on the freezing ETH blockchain.","image":"ipfs://QmNf1UsmdGaMbpatQ6toXSkzDpizaGmC9zfunCyoz1enD5/penguin/1919.png","name":"Pudgy Penguin #1919"}',
      block_number: '19754671',
      block_number_minted: null,
      name: 'PudgyPenguins',
      symbol: 'PPG',
      token_hash: 'cbd8bd0901f422afb88e76615e3d2a1a',
      token_uri: 'https://ipfs.developers.moralis.com:2053/ipfs/bafybeibc5sgo2plmjkq2tzmhrn54bk3crhnc23zd2msg4ea7a4pxrkgfna/1919',
      minter_address: null,
      verified_collection: true,
      possible_spam: false,
      collection_logo: 'https://i.seadn.io/gae/yNi-XdGxsgQCPpqSio4o31ygAV6wURdIdInWRcFIl46UjUQ1eV7BEndGe8L661OoG-clRi7EgInLX4LPu9Jfw4fq0bnVYHqg7RFi?w=500&auto=format',
      collection_banner_image: 'https://i.seadn.io/gcs/files/8a26e3de0f309089cbb1e5ab969fc0bc.png?w=500&auto=format'
    	},
      //...
    ]
  }
}

That’s it; it doesn’t have to be more challenging to get NFT balances using RPC nodes. 

If you liked this tutorial on how to get NFT balances with one RPC call, consider checking out more content here on the blog. For example, explore our Blockchain Address Labeling API

Also, if you wish to start using our Extended RPC Methods yourself, don’t forget to sign up with Moralis. You can create an account for free, giving you access to all our premier development tools.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *