Do you need to get and combine the web value of any pockets into your decentralized functions (dapps)? With Moralis’ Pockets Web Price endpoint, it’s now simpler than ever. All you want is a single API name to get the full internet value of any ERC20 crypto pockets throughout most blockchains!Â
In case you’re wanting to dive straight into the code, try the instance beneath, the place we write a brief script for calling the endpoint to get ERC20 pockets internet value information:Â
import fetch from ‘node-fetch’;
const choices = {
technique: ‘GET’,
headers: {
settle for: ‘utility/json’,
‘X-API-Key’: ‘YOUR_API_KEY’
},
};
fetch(‘https://deep-index.moralis.io/api/v2.2/wallets/0xd8da6bf26964af9d7eed9e03e53415d37aa96045/net-worth?chainspercent5B0percent5D=eth&chainspercent5B1percent5D=polygon&exclude_spam=true&exclude_unverified_contracts=true’, choices)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
In return for operating the code above, you’ll get the full internet value of the required ERC20 pockets. You’ll additionally get the person values for every chain included as parameters of your question. Right here’s an instance of what the response would possibly appear like:Â
{
“total_networth_usd”: “4286806.08”,
“chains”: [
{
“chain”: “eth”,
“native_balance”: “1085515469813080189177”,
“native_balance_formatted”: “1085.515469813080189177”,
“native_balance_usd”: “3550067.16”,
“token_balance_usd”: “735008.04”,
“networth_usd”: “4285075.20”
},
{
“chain”: “polygon”,
“native_balance”: “426857449018746625825”,
“native_balance_formatted”: “426.857449018746625825”,
“native_balance_usd”: “445.31”,
“token_balance_usd”: “1285.57”,
“networth_usd”: “1730.88”
}
]
}
In case you’d prefer to be taught extra about this premier endpoint, try the official Pockets Web Price documentation web page, watch the video beneath, or be a part of us on this information!Â
Additionally, if you happen to want to observe alongside on this tutorial, don’t neglect to enroll with Moralis. You’ll be able to create an account freed from cost, and also you’ll acquire immediate entry to our top-tier Web3 API suite!Â
OverviewÂ
Whether or not you’re constructing or trying to scale a cryptocurrency pockets, portfolio tracker, or every other platform integrating pockets elements in some capability, you want a seamless method to get the web value of any handle. However what’s the best method to get the web value of an ERC20 crypto pockets by way of API?Â
On this tutorial, we’ll present you learn how to fetch the web value of a crypto handle utilizing Moralis’ industry-leading Pockets API. With this top-tier API and the Pockets Web Price endpoint, you may seamlessly get the information you want with just a few traces of code. So, if you wish to construct or scale a cryptocurrency pockets, portfolio tracker, or every other Web3 platform, be a part of us all through this information. Now, let’s dive straight in!Â
Exploring Crypto Pockets Web Price
The online value of a cryptocurrency pockets refers back to the whole worth of all belongings saved within the portfolio, together with native, ERC20, and non-fungible tokens (NFTs). This is a vital metric that cryptocurrency wallets, tax instruments, portfolio trackers, and different initiatives combine into their platforms!
Calculating the web value of a pockets is a tedious and time-consuming process. It sometimes includes manually gathering information throughout a number of blockchain networks, leading to separate requires ERC20 token balances, native balances, costs, and to not point out NFTs. The results of it is a advanced workflow that calls for a variety of growth time and may result in hundreds of hundreds of API calls.
However there must be a greater approach, proper?Â
To streamline this course of, we launched the Pockets Web Price endpoint to Moralis’ Pockets API. With this endpoint, now you can seamlessly and precisely get ERC20 pockets internet value information and routinely calculate the web value with only one single API name!
So, how does this work?
Get ERC20 Pockets Web Price with a Single API NameÂ
With Moralis’ Pockets Web Price endpoint, now you can effortlessly and precisely get the pockets internet value of any handle with a number of traces of code. To showcase the accessibility of working with our APIs, try the easy script beneath for calling the endpoint in query:Â
import fetch from ‘node-fetch’;
const choices = {
technique: ‘GET’,
headers: {
settle for: ‘utility/json’,
‘X-API-Key’: ‘YOUR_API_KEY’
},
};
fetch(‘https://deep-index.moralis.io/api/v2.2/wallets/0xd8da6bf26964af9d7eed9e03e53415d37aa96045/net-worth?chainspercent5B0percent5D=eth&chainspercent5B1percent5D=polygon&exclude_spam=true&exclude_unverified_contracts=true’, choices)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
All it’s important to do earlier than operating the script above your self is to put in the required dependencies, change YOUR_API_KEY, configure the handle parameter, specify the chains you want to embrace, and run the script.Â
Within the question above, we set each exclude_spam and exclude_unverified_contracts to true. That approach, we will take away spam tokens and unverified contracts from the response.Â
In return for operating the script above, you’ll get a response that appears one thing like this:
{
“total_networth_usd”: “4286806.08”,
“chains”: [
{
“chain”: “eth”,
“native_balance”: “1085515469813080189177”,
“native_balance_formatted”: “1085.515469813080189177”,
“native_balance_usd”: “3550067.16”,
“token_balance_usd”: “735008.04”,
“networth_usd”: “4285075.20”
},
{
“chain”: “polygon”,
“native_balance”: “426857449018746625825”,
“native_balance_formatted”: “426.857449018746625825”,
“native_balance_usd”: “445.31”,
“token_balance_usd”: “1285.57”,
“networth_usd”: “1730.88”
}
]
}
As you may see, this straightforward but refined response contains each the full internet value of the ERC20 pockets and separate metrics for every chain specified within the question. From right here, now you can seamlessly combine this information into any of your initiatives!Â
Why Do You Want the ERC20 Pockets Web Price Endpoint?Â
Since you may leverage the Pockets Web Price endpoint to keep away from the tedious and time-consuming process of manually calculating the web value of any pockets, it offers a variety of advantages to Web3 builders. Under, we’ll briefly discover three distinguished examples:
Easy Web Price Calculations: Now you can effortlessly fetch the web value of any pockets, eradicating the necessity for handbook information aggregation. Correct Value Knowledge: Moralis offers up-to-date, real-time value information, making certain exact portfolio assessments. Lowered Complexities: With the Pockets Web Price endpoint, you don’t should manually fetch and calculate the full worth of a pockets. As such, this endpoint facilitates a extra accessible developer expertise, leading to fewer API calls and a a lot less complicated workflow.
![Net worth of ERC20 wallet graph](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-Benefits-of-Moralis-.png)
By launching this endpoint, we’re empowering builders worldwide to do extra sooner and with fewer API calls. As such, the Pockets Web Price endpoint frees up a variety of time, enabling you and your staff to give attention to what’s actually essential: constructing a compelling person expertise and rising buyer worth.Â
In-Depth Tutorial: Find out how to Get the Web Price of Any ERC20 Pockets in 3 StepsÂ
With an outline of our premier endpoint, we’ll now present you learn how to get a pockets’s ERC20 internet value in three easy steps:Â
Step 1: Fetch Your Moralis API KeyStep 2: Write a Script Calling the Pockets Web Price EndpointStep 3: Run the Code
Nonetheless, earlier than we will proceed, you want to maintain a number of important stipulations!Â
Conditions
In in the present day’s tutorial, we’ll be utilizing JavaScript and Node.js. As such, if you happen to haven’t already, be sure to have the next prepared:Â
Step 1: Fetch Your Moralis API Key
The very first thing you’ll want is a Moralis account. As such, begin by signing up with Moralis by clicking on the sign-up button on the high proper of Moralis’ homepage:Â
![Step 1 to get ERC20 wallet net worth: Sign up with Moralis for free](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-Start-For-Free.png)
Subsequent, go to the ”Settings” tab, discover the ”API Keys” part, and replica your key:Â
![Step 1 Continued: Copy ERC2- Wallet Net Worth Endpoint API Key inside the Moralis admin UI](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-Get-Moralis-API-Key.png)
Please reserve it for now, as you’ll want it within the subsequent part.
Step 2: Write a Script Calling the Pockets Web Price Endpoint
Open your most well-liked IDE and arrange a folder. Subsequent, launch a brand new terminal and run the next command to initialize a undertaking:Â
npm init
Run the next instructions within the terminal to put in the required dependencies:Â
npm set up node-fetch –save
npm set up moralis @moralisweb3/common-evm-utils
You’ll be able to then open your ”bundle.json” file and add ”sort”: ”module” to the listing:Â
![Step 2: open your ”package.json” file and add ”type”: ”module” to the list](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-Type-Module.png)
Subsequent, create an ”index.js” file and add this code:Â
import fetch from ‘node-fetch’;
const choices = {
technique: ‘GET’,
headers: {
settle for: ‘utility/json’,
‘X-API-Key’: ‘YOUR_API_KEY’
},
};
fetch(‘https://deep-index.moralis.io/api/v2.2/wallets/0xd8da6bf26964af9d7eed9e03e53415d37aa96045/net-worth?chainspercent5B0percent5D=eth&chainspercent5B1percent5D=polygon&exclude_spam=true&exclude_unverified_contracts=true’, choices)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
From right here, you’ll need to configure the code barely. Begin by including your Moralis API key by changing YOUR_API_KEY:
![Step 2 continued: replace the parameter with your coped API key](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-Add-API-Key.png)
Then, you may also configure the parameters of your question. As an illustration, you may swap the handle if you happen to want to question one other pockets, and you may add further chains if you wish to embrace tokens from different networks:
![Step 2 continued: showing examples of chains to choose from when getting the ERC20 net worth of a wallet](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-Configure-Query-Parameters.png)
Additionally, word that we embrace exclude_spam and exclude_unverified_contracts as parameters and set them to true. That approach, our outcomes will exclude spam tokens and non-verified contracts.Â
That’s it; you’re now able to run the code!Â
Step 3: Run the Code
Open a brand new terminal and run this command within the root folder of the undertaking to execute the code:Â
node index.js
In return, you’ll get a response together with the full internet value of the pockets, together with the separate values for every chain included within the question. Right here’s an instance of what it’d appear like:Â
{
“total_networth_usd”: “4286806.08”,
“chains”: [
{
“chain”: “eth”,
“native_balance”: “1085515469813080189177”,
“native_balance_formatted”: “1085.515469813080189177”,
“native_balance_usd”: “3550067.16”,
“token_balance_usd”: “735008.04”,
“networth_usd”: “4285075.20”
},
{
“chain”: “polygon”,
“native_balance”: “426857449018746625825”,
“native_balance_formatted”: “426.857449018746625825”,
“native_balance_usd”: “445.31”,
“token_balance_usd”: “1285.57”,
“networth_usd”: “1730.88”
}
]
}
With this information, now you can seamlessly get ERC20 pockets internet value information and combine it into your initiatives!Â
Pockets Web Price Use Instances: Why Do You Must Get the Web Price of an ERC20 Pockets? Â
The Pockets Web Price endpoint has a variety of utility and can be helpful for anybody constructing dapps that function some kind of pockets part. Nonetheless, to present you some examples, let’s discover three distinguished use instances beneath!Â
Cryptocurrency Wallets: Cryptocurrency wallets are software program that permits customers to retailer their digital belongings, together with NFTs and fungible tokens. Essentially the most distinguished wallets additionally present performance for purchasing, promoting, and buying and selling crypto. As such, they offer customers the instruments to handle their belongings totally. Some notable examples of cryptocurrency wallets embrace MetaMask, Coinbase Pockets, and Rainbow.Â
![Wallet Net Worth ERC20 Balances Project example](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-Wallets.png)
Crypto Tax Platforms: Crypto tax platforms are functions designed to assist each people and companies calculate taxes on their cryptocurrency transactions. With the advanced nature of crypto transactions and evolving rules, these instruments have turn into fairly beneficial for merchants and traders. An incredible instance of a crypto tax platform is Koinly.Â
![ERC20 wallet net worth on a crypto tax platform](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-Tax-Tools.png)
Knowledge and Analytics Instruments: Knowledge and analytics instruments are platforms giving customers in-depth perception into the efficiency of cryptocurrencies. These instruments can present a variety of options, together with market analytics, portfolio monitoring, blockchain analytics, and extra. A distinguished instance of an industry-leading information and analytics device is Moralis Cash!Â
![Moralis Money platform - Example of tool that uses ERC20 Net Worth data](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-Token-Analytics.png)
The use instances above are just a few distinguished examples, and also you’ll possible discover the Pockets Web Price endpoint helpful in most of your growth endeavors!Â
Past Getting the Pockets Web Price – Exploring the Pockets API AdditionalÂ
Moralis’ Pockets API is the {industry}’s premier device for anybody trying to construct cryptocurrency wallets or combine pockets performance into dapps. This interface helps greater than 300 million addresses throughout essentially the most distinguished blockchains, together with Ethereum, Polygon, Solana, and plenty of others!Â
![Graphic art illustration - Token API marketing banner](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-Token-API.png)
With the Pockets API, you may effortlessly question blockchain information. This contains pockets balances, profile information, transactions, and even the web value of a pockets! Plus, you are able to do so with solely single traces of code. As such, when utilizing the Pockets API, you may construct every part from crypto wallets to tax instruments with out breaking a sweat.Â
To spotlight the capabilities of this premier API, let’s discover some further endpoints beneath:Â
Token Balances with Costs: The Token Balances with Costs endpoint allows you to fetch a pockets’s ERC20 token balances together with metadata, costs, and so on. Furthermore, you are able to do so with solely a single API name. Right here’s an instance of what it’d appear like:import fetch from ‘node-fetch’;
const choices = {
technique: ‘GET’,
headers: {
settle for: ‘utility/json’,
‘X-API-Key’: ‘YOUR_API_KEY’
},
};
fetch(‘https://deep-index.moralis.io/api/v2.2/wallets/0xcB1C1FdE09f811B294172696404e88E658659905/tokens?chain=eth’, choices)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
In return for operating the code above, you’ll get a response that appears one thing like this:Â
{
//…
“outcome”: [
{
“token_address”: “0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48”,
“symbol”: “USDC”,
“name”: “USD Coin”,
“logo”: “https://cdn.moralis.io/eth/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png”,
“thumbnail”: “https://cdn.moralis.io/eth/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_thumb.png”,
“decimals”: 6,
“balance”: “4553447”,
“possible_spam”: false,
“verified_contract”: true,
“balance_formatted”: “4.553447”,
“usd_price”: 1.001818879776249,
“usd_price_24hr_percent_change”: 0.1818879776249283,
“usd_price_24hr_usd_change”: 0.0018221880998897314,
“usd_value”: 4.561729172660522,
“usd_value_24hr_usd_change”: 0.008297236936878599,
“native_token”: false,
“portfolio_percentage”: 100
},
//…
]
}
To be taught extra about how this works, try our most up-to-date information exploring the last word crypto portfolio tracker endpoint!Â
getWalletNFTs(): With the getWalletNFTs() endpoint, you may seamlessly get the NFT stability of any pockets. You’ll discover an instance of what it’d appear like right here: import Moralis from ‘moralis’;
strive {
await Moralis.begin({
apiKey: “YOUR_API_KEY”
});
const response = await Moralis.EvmApi.nft.getWalletNFTs({
“chain”: “0x1”,
“format”: “decimal”,
“mediaItems”: false,
“handle”: “0xff3879b8a363aed92a6eaba8f61f1a96a9ec3c1e”
});
console.log(response.uncooked);
} catch (e) {
console.error(e);
}
In return, you’ll get an array of all NFTs the pockets in query holds. It should look one thing like this: Â
{
//…
{
“quantity”: “1”,
“token_id”: “5021”,
“token_address”: “0xfff54e6fe44fd47c8814c4b1d62c924c54364ad3”,
“contract_type”: “ERC721”,
“owner_of”: “0xff3879b8a363aed92a6eaba8f61f1a96a9ec3c1e”,
“last_metadata_sync”: null,
“last_token_uri_sync”: “2024-02-27T13:25:49.783Z”,
“metadata”: null,
“block_number”: “14647390”,
“block_number_minted”: “14647390”,
“identify”: “Youtopia”,
“image”: “Youtopia”,
“token_hash”: “d4719eaf84eabcf443065b0a463f5886”,
“token_uri”: “http://api.youtopia-official.xyz/ipfs/5021”,
“minter_address”: “0x13f11fd2c7c7be94674651386370d02b7aac9653”,
“verified_collection”: false,
“possible_spam”: true,
“collection_logo”: “https://i.seadn.io/gae/e3uNxyaqT0FfnhcF9SuMqCZd3pdF36wgcnpRJ0VDjLOP71g_LwrFRgLweNNCMvsMqR5ZZ4dh5Wble12PBzvncmpLbtmdVdjr5zMy8w?w=500&auto=format”,
“collection_banner_image”: “https://i.seadn.io/gae/n9j18OhplkvqP5SOtuYDwpUVkJSwF6WkIV6vZMWjcm0D5qCpbd12cAaVlfZS8-3gjxjYsnjL_tIlVIsjXz28KejPB3D19Jc_MZ9Z?w=500&auto=format”
},
//…
]
} getWalletTransactions(): You need to use the getWalletTranscactions() endpoint to question the native transaction historical past of any pockets. Try the instance beneath to see the way it works:Â import Moralis from ‘moralis’;
strive {
await Moralis.begin({
apiKey: “YOUR_API_KEY”
});
const response = await Moralis.EvmApi.transaction.getWalletTransactions({
“chain”: “0x1”,
“handle”: “0x1f9090aaE28b8a3dCeaDf281B0F12828e676c326”
});
console.log(response.uncooked);
} catch (e) {
console.error(e);
}
In return for calling the endpoint above, you’ll get a listing of the pockets’s native transactions. Right here’s an instance of what it’d appear like:Â
{
//…
“outcome”: [
{
“hash”: “0xc2dae4e9323e4b4daae845d56bb2b0b1963b65b4cebd232a30c600147bd0d394”,
“nonce”: “516871”,
“transaction_index”: “343”,
“from_address”: “0x1f9090aae28b8a3dceadf281b0f12828e676c326”,
“from_address_label”: “rsync-builder”,
“to_address”: “0x388c818ca8b9251b393131c08a736a67ccb19297”,
“to_address_label”: “Lido: Execution Layer Rewards Vault”,
“value”: “126626152737137840”,
“gas”: “22111”,
“gas_price”: “46932278594”,
“input”: “0x”,
“receipt_cumulative_gas_used”: “29863868”,
“receipt_gas_used”: “22111”,
“receipt_contract_address”: null,
“receipt_root”: null,
“receipt_status”: “1”,
“block_timestamp”: “2024-02-27T13:29:59.000Z”,
“block_number”: “19319196”,
“block_hash”: “0xaf38cea22f06e3d31e24dadc8cc27daa65f09c68713ce8343489536dde6ea22d”,
“transfer_index”: [
19319196,
343
]
},
//…
]
}
In case you’d prefer to discover all of the endpoints of this API, please try the official Pockets API documentation web page!Â
Abstract: Find out how to Get the Web Price of Any ERC20 Pockets by way of API
From a standard perspective, it has all the time been a tedious and time-consuming process to get the web value of any ERC20 crypto pockets by way of API. Moreover, it has sometimes required you to manually acquire information throughout a number of blockchains, leading to separate API requires ERC20 token balances, native balances, costs, and so on. The result of it is a advanced workflow that takes up a variety of growth sources and time. Nonetheless, now you can circumvent this complete course of utilizing Moralis’ Pockets API and the Pockets Web Price endpoint!Â
![Illustration - showing wallets and their ERC20 net worth balances](https://moralis.io/wp-content/uploads/2024/02/Get-ERC20-Wallet-Net-Worth-What-is-Net-Worth-Summary.png)
With Moralis’ Pockets Web Price endpoint, you solely want a single API name to get ERC20 pockets internet value information throughout the largest blockchains. As such, when working with Moralis, it has by no means been simpler to construct cryptocurrency wallets, portfolio trackers, or every other platforms that combine the web value of an ERC20 pockets!Â
Did you want this tutorial exhibiting learn how to get the web value of an ERC20 pockets utilizing Moralis’ API? If that’s the case, think about testing extra content material right here on the weblog. As an illustration, learn one in every of our most up-to-date articles that exhibits you learn how to question the Ethereum blockchain! Additionally, if you happen to want to use the Pockets API, don’t neglect to enroll with Moralis. You’ll be able to create an account totally free, and also you’ll acquire instantaneous entry to our premier growth instruments!