In today’s tutorial, we’ll show you how to list all the coins in an ETH address using the Moralis Token API – the industry’s leading tool for ERC-20 data. Thanks to the accessibility of the Token API, you can get all the coins of any address with a single call to the getWalletTokenBalances()
endpoint. Here’s a little sneak peek of what the code might look like:
const Moralis = require("moralis").default; const { EvmChain } = require("@moralisweb3/common-evm-utils"); const runApp = async () => { await Moralis.start({ apiKey: "YOUR_API_KEY", // ...and any other configuration }); const address = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"; const chain = EvmChain.ETHEREUM; const response = await Moralis.EvmApi.token.getWalletTokenBalances({ address, chain, }); console.log(response.toJSON()); }; runApp();
You simply have to add your Moralis API key, configure address
to fit your query and run the code. In return, you’ll get a response containing a list of all the coins from the specified ETH address.
That’s it; it doesn’t have to be more challenging than that when working with Moralis. However, if you want a more detailed breakdown of the entire process, join us in this tutorial or check out the Moralis documentation page on how to get all tokens owned by an address!
Also, if you wish to call the Token API yourself, don’t forget to sign up with Moralis. You can set up your account without paying a dime, and you’ll get instant access to all our industry-leading Web3 APIs!
Overview
We’ll kickstart today’s article by diving into the ins and outs of ETH addresses. In doing so, we’ll cover what they are and what they are used for. From there, we’ll jump straight into the tutorial and show you how to list all the coins in an ETH address in three straightforward steps using Moralis’ Token API:
- Get a Moralis API Key
- Write a Script Calling the
getWalletTokenBalances()
Endpoint - Run the Code
From there, we’ll explore some prominent use cases for listing all the coins in an ETH address before we top things off by diving deeper into Moralis!
Now, without further ado, let’s get going and explore the intricacies of ETH addresses!
What is an ETH Address?
An ETH address is a 42-character long, alphanumerical hex string serving as a unique and public identifier for an externally owned account (EOA) or smart contract on the Ethereum blockchain. Such an address is mostly used for sending, receiving, and storing digital assets like fungible and non-fungible tokens (NFTs)!
There are two types of ETH addresses, and we’ll briefly cover both below:
- Account Addresses: An account address – also commonly referred to as a ”wallet address” or ”blockchain address” – corresponds to a public user account on the blockchain controlled by a private key. Account addresses are used to send, receive, and store digital assets, along with interacting with smart contracts and dapps.
- Contract Addresses: Contract addresses are associated with smart contracts deployed on the blockchain. A contract address is not controlled by an individual or entity like an account address but rather represents the location where the smart contract resides on the network.
All in all, ETH addresses are unique identifiers for Ethereum accounts and smart contracts. Furthermore, they are commonly used for sending, receiving, and storing digital assets like fungible tokens and NFTs!
Since ETH addresses are public, we can use them to look up information about accounts and smart contracts. This includes things such as token balances, which we’ll show you how you can fetch in the following section using Moralis!
Full Tutorial: List All the Coins in An ETH Address
The easiest way to list all the coins in an ETH address is to leverage Moralis’ Token API – the ultimate interface for real-time ERC-20 data. In fact, thanks to the accessibility of this industry-leading tool, you can get all the information you need straight from the Ethereum blockchain in three simple steps:
- Get a Moralis API Key
- Write a Script Calling the
getWalletTokenBalances()
Endpoint - Run the Code
However, before jumping into the initial step of this tutorial, you must first take care of a couple of prerequisites!
Prerequisites
Moralis’ Web3 APIs are compatible with multiple programming languages, including Python, TypeScript, etc. However, for this tutorial, we’ll be sticking to JavaScript. As such, before you proceed, please make sure you have the following ready:
- Node.js v14+
- Yarn/npm
Step 1: Get a Moralis API Key
To call the Token API, you need a Moralis API key, which you can get for free by signing up with Moralis. As such, if you haven’t already, click on the ”Start for Free” button at the top right of the Moralis homepage to create your account:
With an account at hand, select a project, go to the ”Settings” tab using the navigation bar to the left, scroll down to the ”API Keys” section, and copy your key:
Save the key for now, as you’ll need it in the next step when initializing the Moralis software development kit (SDK)!
Step 2: Write a Script Calling the getWalletTokenBalances()
Endpoint
For the second step, start by setting up a new project folder in your preferred IDE. From there, open a new terminal and run the following command in the root folder to install the Moralis SDK:
npm install moralis @moralisweb3/common-evm-utils
Next, create a new ”index.js” file and add the following code:
const Moralis = require("moralis").default; const { EvmChain } = require("@moralisweb3/common-evm-utils"); const runApp = async () => { await Moralis.start({ apiKey: "YOUR_API_KEY", // ...and any other configuration }); const address = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"; const chain = EvmChain.ETHEREUM; const response = await Moralis.EvmApi.token.getWalletTokenBalances({ address, chain, }); console.log(response.toJSON()); }; runApp();
Before running the code, you need to make a few minor configurations. Start by replacing YOUR_API_KEY
with the key you copied during the first step. Doing so will initialize the Moralis SDK:
Keep in mind that you don’t want to expose your Moralis API key. As such, when building production-ready dapps, make sure to use environment variables and other best practices.
From here, you also need to configure the address
const by adding the ETH address from which you want to get the list of all coins:
We then pass along address
and chain
as parameters when calling the getWalletTokenBalances()
endpoint:
That’s it for the code; you’re now ready to run the script and fetch a list of all the coins in the specified ETH address!
Step 3: Run the Code
To run the code, go ahead and launch a new terminal, cd
into the project’s root folder, and execute the following command:
node index.js
Once you run the code, you’ll get a response containing a list of all the coins in the specified ETH address. It should look something like this:
[ { "token_address": "0xff20548405c6f024264b5c8dc954625285b799e1", "symbol": "BTCETF", "name": "BTCETF", "logo": null, "thumbnail": null, "decimals": 18, "balance": "166000000000000000000000", "possible_spam": false }, { "token_address": "0xe90cc7d807712b2b41632f3900c8bd19bdc502b1", "symbol": "KUMA", "name": "Kuma", "logo": null, "thumbnail": null, "decimals": 18, "balance": "3000000000000000000000000000", "possible_spam": false }, //... ]
Congratulations; you now know how to get a list of all the coins in an ETH address!
Now, if you want inspiration on what to do with this data, join us in the following section. In doing so, we’ll explore some common use cases for listing all the coins in an ETH address!
Use Cases for Listing All the Coins in An ETH Address
There are many use cases for listing all the coins in an ETH address, and we won’t be able to cover them all in this section. Instead, we’ll briefly list four prominent examples of platforms that need access to address balances in some capacity:
- Portfolio Trackers: A crypto portfolio tracker is a digital platform that allows you to oversee all your cryptocurrency holdings in one place. Some great examples include Delta, Koinly, and Kubera.
- Decentralized Exchanges (DEXs): A DEX is a crypto exchange facilitating peer-to-peer (P2P) transactions without intermediary involvement. Examples of well-established platforms include Uniswap, Curve Finance, and PancakeSwap.
- Block Explorers: A block explorer is a digital tool that allows you to search for real-time and historical information about a blockchain network. This includes everything from block data to token balances of a particular address. Some prominent examples of block explorers include Etherscan, PolygonScan, and BscScan.
- Web3 Wallets: Web3 wallets are digital platforms that allow you to store and manage your digital assets, including buying, selling, and swapping tokens. Examples of Web3 wallets are MetaMask, Coinbase Wallet, and Ledger.
Now that you know how to list all the coins in an ETH address and some instances when this data can be helpful, let’s explore Moralis’ capabilities further in the next section!
Beyond Querying a List of All the Coins in An ETH Address – Exploring Moralis Further
Moralis is the industry’s premier Web3 API provider, and the capabilities of our dynamic toolset extend far beyond the Token API!
In Moralis’ industry-leading Web3 API suite, you’ll find multiple interfaces for various use cases, and down below, we’ll explore three examples:
- Wallet API: Our Wallet API is the ultimate tool if you’re looking to build Web3 wallets or integrate wallet functionality into your dapps. With single API calls, you can effortlessly fetch wallet balances, real-time transfers, profile data, and much more. For instance, here’s an example of how easy it is to fetch the native balance of any wallet with the
getNativeBalance()
endpoint:
const response = await Moralis.EvmApi.balance.getNativeBalance({ "chain": "0x1", "address": "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022" });
- NFT API: Moralis’ NFT API is the industry’s leading tool for NFT-related data. With this premier interface, you can get NFT metadata, balances, on-chain prices, and more with only single lines of code. For example, with the
getWalletNFTs()
endpoint, you can seamlessly fetch the NFT balance of any wallet:
const response = await Moralis.EvmApi.nft.getWalletNFTs({ "chain": "0x1", "address": "0xff3879b8a363aed92a6eaba8f61f1a96a9ec3c1e" });
- Blockchain API: With the Blockchain API, you can unlock the power of raw and decoded blockchain data. Fetch block data, smart contract logs, events, and much more with ease. For instance, here’s an example of how you can get block data – including hashes, timestamps, etc. – with the
getBlock()
endpoint:
const response = await Moralis.EvmApi.block.getBlock({ "chain": "0x1", "blockNumberOrHash": "18541416" });
So, it doesn’t matter if you’re building Web3 wallets, NFT dapps, blockchain explorers, or any other platform; Moralis has the perfect tools for your needs. If you’d like to explore all our premier interfaces, check out our official Web3 API page!
However, at this point, you might still be asking yourself, ”Why should I leverage Moralis’ Web3 APIs?”. To answer this question, let’s explore some prominent benefits of Moralis in the following subsection!
Benefits of Moralis’ Web3 APIs
Besides allowing you to build Web3 projects faster and more efficiently, Moralis provides many advantages. However, unfortunately, we will not be able to cover all the benefits in this article. Instead, we have narrowed it down to three prominent examples of why you should use Moralis:
- Top Performance: There are many good Web3 API providers on the market; however, Moralis stands out as the best when it comes to performance. Whether you want to measure by reliability, speed, coverage, or any other metric, Moralis always comes out on top.
- Unparalleled Scalability: Moralis’ APIs offer unparalleled scalability. Consequently, our APIs will scale without fault as your user base grows.
- Cross-Chain Compatibility: Our Web3 APIs are chain agnostic, supporting all major blockchain networks. This includes Ethereum, BNB Smart Chain, Solana, etc., along with several prominent ETH layer-2 scaling solutions. As such, when working with Moralis, you’ll have no trouble building cross-chain compatible dapps!
So, if you’re serious about building Web3 projects, make sure to sign up with Moralis. You can create your account for free, and you’ll gain instant access to all our industry-leading Web3 development tools!
Summary: How to List All the Coins in An ETH Address
In today’s article, we kicked things off by diving into the ins and outs of ETH addresses. In doing so, we learned that they serve as unique identifiers for EOAs and smart contracts on the Ethereum blockchain.
From there, we then jumped straight into the main tutorial and showed you how to list all the coins in an ETH address in three steps using the Moralis Token API:
- Get a Moralis API Key
- Write a Script Calling the
getWalletTokenBalances()
Endpoint - Run the Code
So, if you have followed along this far, you now know how to fetch all the tokens of Ethereum addresses!
We then also explored some prominent use cases for this data. In doing so, we briefly covered Web3 wallets, portfolio trackers, DEXs, and block explorers. If you liked this tutorial on how to list all the coins in an ETH address, consider reading more content here on the Moralis blog. For example, check out our most recent Starknet faucet guide or explore the ins and outs of Web3 social media.
Also, if you want to leverage our Web3 APIs in your development endeavors, don’t forget to sign up with Moralis. You can set up your account for free, and you’ll be able to start building dapps faster and smarter today!