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:
“`javascript
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:
“`json
{
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.moralis.io: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 DeFi Daily News 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.
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.
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.
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.
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:
Log in, go to the ”Nodes” tab, and click ”+ Create Node” to set up a node: