Customers, decentralized purposes (dapps), and different good contracts want the tackle of an ERC-20 token to name features, ship transactions, or question knowledge. Nonetheless, what precisely is a token tackle? And the way do you get them? When you’re in search of the solutions to those queries, be a part of us on this tutorial, as we’ll present you the best method to get the tackle of any ERC-20 token!
Overview
In in the present day’s article, we’ll kick issues off by exploring the intricacies of ERC-20 token addresses. From there, we’ll bounce straight into the principle matter and present you the best way to get the tackle of any ERC-20 token utilizing the {industry}’s main token explorer – Moralis Cash – and a block explorer like Etherscan. Subsequent, we’ll additionally cowl different methods to get ERC-20 token addresses utilizing Moralis and its varied APIs, which may also help you in your Web3 improvement endeavors. Extra particularly, we’ll discover the next endpoints:Â
getWalletTokenBalances()getTopERC20TokensByMarketCap()getTopERC20TokensByPriceMovers()
Lastly, to high issues off, we’ll offer you an in-depth tutorial on the best way to get the addresses of all ERC-20 tokens in a pockets utilizing Moralis!Â
All through this text, we’re going to make the most of Moralis’ Web3 Market Knowledge API and Token API to get the addresses of ERC-20 tokens. Nonetheless, in the event you’re severe about constructing Web3 initiatives, we urge you to discover some extra Moralis instruments as effectively. As an example, take a look at the Value API and discover the best method to get costs of crypto.
With the instruments in Moralis’ Web3 API suite, you may construct Web3 initiatives sooner and extra effectively. As such, in the event you haven’t already, be certain that to enroll with Moralis and get fast entry to our blockchain improvement instruments free of charge!
What’s an ERC-20 Token Handle?Â
ERC-20 – brief for Ethereum Request for Remark 20 – is probably the most extensively adopted customary for creating tokens on the Ethereum blockchain. The usual defines a set of necessities, features, and occasions all fungible tokens should implement to be thought-about ERC-20 compliant. Some distinguished examples embrace features for transferring tokens between addresses, checking the token’s whole provide, and so forth.
One of many key targets of the ERC-20 customary is to ensure an identical values between tokens. For instance, one ETH token will all the time equal one other ETH.Â
The uniformity of the ERC-20 token customary is important for the Ethereum ecosystem, making it considerably simpler for Web3 wallets, decentralized purposes (dapps), and different platforms to combine tokens into their software program. That is, for instance, why you may seamlessly add any ERC-20 token to a pockets like MetaMask, a activity that will be considerably more durable with out a distinguished customary.Â
That mentioned, what’s the tackle of an ERC-20 token?
ERC-20 tokens are created by inputting some knowledge right into a template good contract chargeable for controlling and managing the token. When the token creator first deploys it to the blockchain, an tackle that appears just like any public Ethereum pockets tackle is generated. Consequently, an ERC-20 token tackle is actually a novel sequence of letters and numbers performing as a novel identifier for the good contract in query.   Â
So, why is that this tackle crucial?Â
So as so that you can work together with a token, you want the tackle of the good contract. You’ll be able to consider it this manner: if you wish to ship or obtain something to your account, you employ your public tackle. Equally, in the event you’re going to ship or obtain an ERC-20 token, you need to work together with its tackle!
Best Method to Get the Handle of Any ERC-20 Token
With an outline of what a token tackle is, we’re prepared to leap into the principle tutorial. On this half, we’ll present you the best way to get the tackle of an ERC-20 token utilizing two totally different instruments:Â
Token explorersBlock explorers
So, with out additional ado, let’s have a look at how one can get an ERC-20 token’s tackle utilizing a token explorer!Â
Use a Token Explorer to Get the Handle of an ERC-20 Token
On this part, we’ll present you the best way to get the tackle of an ERC-20 token utilizing the {industry}’s premier token explorer – Moralis Cash!
Due to the accessibility of Moralis Cash, you may effortlessly get any token tackle in three simple steps:Â
Step 2: Enter a token identify within the search bar on the high and click on on it. Doing so takes you to the coin’s token web page, and on this case, we’ll be utilizing USDC for example:Â
Step 3: Click on on the copy button subsequent to ”Coin Handle”:Â
That’s it; when working with a token explorer like Moralis Cash, it’s simple to get the tackle of an ERC-20 token!
What’s extra, Moralis Cash helps a number of blockchain networks. This implies you may seamlessly discover any ERC-20 token’s tackle throughout varied chains, together with Ethereum, Polygon, Arbitrum, and lots of others.
Use a Block Explorer to Get the Handle of an ERC-20 Token
You can even use different instruments like block explorers to simply get an ERC-20 token’s tackle. On this part, we’ll present you the way it works utilizing Etherscan!Â
Step 2: Add the token identify to the search bar on the high and click on on it. On this case, we’ll even be utilizing USDC for example:Â
Step 3: Copy the tackle below the ”Different Information” part:
That’s it; it doesn’t should be more difficult than that to get the tackle of an ERC-20 token when utilizing a block explorer like Etherscan!Â
Nonetheless, a major disadvantage to utilizing block explorers is that they’re normally tied to at least one particular community. As an example, Etherscan is used for Ethereum, PolygonScan is used for Polygon, and so forth. This implies you may’t discover token addresses throughout chains like when working with Moralis Cash!Â
Use Moralis to Get ERC-20 Token AddressesÂ
Along with utilizing token and block explorers, you can even leverage Moralis and our varied APIs to get ERC-20 token addresses in different methods which might be extra helpful when constructing Web3 initiatives. To provide you a number of examples, within the following sections, we are going to cowl three distinguished endpoints that permit you to seamlessly get ERC-20 token addresses:Â
getWalletTokenBalances()getTopERC20TokensByMarketCap()getTopERC20TokensByPriceMovers()
If this sounds intriguing, be a part of us under as we present you the getWalletTokenBalances() endpoint, permitting you to get the addresses of all ERC-20 tokens owned by a pockets in a heartbeat!Â
getWalletTokenBalances()
The simplest method to get the addresses of all ERC-20 tokens owned by a pockets is to leverage the Moralis Token API. With the Token API, you may effortlessly get the info you’re after with a single name to the getWalletTokenBalances() endpoint. Right here’s an instance of what it’d seem like:Â
const response = await Moralis.EvmApi.token.getWalletTokenBalances({
“chain”: “0x1”,
“tackle”: “0x1f9090aaE28b8a3dCeaDf281B0F12828e676c326”
});
All you need to do is configure the tackle and chain parameters to suit your question. On this occasion, the tackle parameter is the pockets tackle from which you need to get the tokens. When you name the getWalletTokenBalances() endpoint, you’ll get a response containing an array of all tokens and their addresses. It is going to look one thing like this:Â
[
{
“token_address”: “0xefd6c64533602ac55ab64442307f6fe2c9307305”,
“name”: “APE”,
“symbol”: “APE”,
“logo”: null,
“thumbnail”: null,
“decimals”: 18,
“balance”: “101715701444169451516503179”
},
{
“token_address”: “0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2”,
“name”: “Wrapped Ether”,
“symbol”: “WETH”,
“logo”: “https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.webp”,
“thumbnail”: “https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_thumb.webp”,
“decimals”: 18,
“balance”: “85000000000000000”
}
]
getTopERC20TokensByMarketCap()
Your only option for fetching the addresses of the highest ERC-20 tokens by market cap is to make use of the Moralis Market Knowledge API. With this software, you may get the job achieved with a single API name to the getTopERC20TokensByMarketCap() endpoint. And that is what it appears like:Â Â
const response = await Moralis.EvmApi.marketData.getTopERC20TokensByMarketCap();
In return for calling the endpoint above, you’ll get a listing of the highest ERC-20 tokens by market cap, together with every token’s tackle. Right here’s an instance of what the response would possibly seem like: Â
[
{
“rank”: “1”,
“token_name”: “Wrapped Ether”,
“token_symbol”: “WETH”,
“token_logo”: “https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png”,
“token_decimals”: “18”,
“contract_address”: “0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2”,
“price_usd”: “0.0285”,
“price_24h_percent_change”: “0.0285”,
“price_7d_percent_change”: “0.0285”,
“market_cap_usd”: “0.0285”
}
//…
]
getTopERC20TokensByPriceMovers()
You can even leverage the Market Knowledge API to get the addresses of the highest ERC-20 tokens primarily based on worth change. All it requires is a single name to the getTopERC20TokensByPriceMovers() endpoint, and it appears one thing like this:Â
const response = await Moralis.EvmApi.marketData.getTopERC20TokensByPriceMovers();
Calling the getTopERC20TokensByPriceMovers() endpoint provides you with the highest gainers and losers primarily based on worth change. And every token within the response may have an tackle connected to it. Right here’s an instance of what the JSON response ought to seem like:Â
{
“gainers”: [
{
“rank”: 1,
“token_name”: “Amber phantom Butterfly”,
“token_symbol”: “APB”,
“token_logo”: “https://market-data-images.s3.us-east-1.amazonaws.com/tokenImages/0x1650ec11bc9cfe2f3a4a18a9fcf5c2ad5e7979e8b5e92fae7cff5475d51f2bb4.png”,
“token_decimals”: “18”,
“contract_address”: “0x23da77203eead71e72d7326654c431ef563567a4”,
“price_usd”: “0.00009505”,
“price_24h_percent_change”: “1362.31”,
“price_7d_percent_change”: “8.1”,
“market_cap_usd”: “1072500”
},
//…
],
“losers”: [
{
“rank”: 1,
“token_name”: “ONSTON”,
“token_symbol”: “ONSTON”,
“token_logo”: “https://market-data-images.s3.us-east-1.amazonaws.com/tokenImages/0x52d802cacaf06b3f80e8c974091a44a171110ff7cf2a64db147209a9f92b2b02.png”,
“token_decimals”: “18”,
“contract_address”: “0x47b9f01b16e9c9cb99191dca68c9cc5bf6403957”,
“price_usd”: “0.0004902”,
“price_24h_percent_change”: “-78.89”,
“price_7d_percent_change”: “-78.27”,
“market_cap_usd”: “2320060”
},
//…
]
}
Full Tutorial: Tips on how to Get the Addresses of All ERC-20 Tokens in a Pockets
On this part, we’ll present a whole tutorial on the best way to get the addresses of all ERC-20 tokens in a pockets utilizing Moralis’ Token API. Due to the accessibility of this software, we are able to effortlessly get the info we’d like in three simple steps:Â
Get a Moralis API keyWrite a script calling the getWalletTokenBalances() endpointRun the code
Nonetheless, earlier than we are able to bounce into step one of the tutorial, you’ll want to care for a number of stipulations!Â
ConditionsÂ
Whereas the Token API helps a number of programming languages, we can be utilizing JavaScript on this tutorial. So, earlier than you may proceed, be sure to have the next prepared:Â
Step 1: Get a Moralis API KeyÂ
A Moralis API key’s one requirement for calling the Token API and the getWalletTokenBalances() endpoint. As such, in the event you don’t have already got one, be certain that to enroll with Moralis right away by clicking on the ”Begin for Free” button on the high proper of the Moralis homepage:Â
With a Moralis account at hand, you may navigate to the ”Settings” tab, scroll right down to the ”Secrets and techniques” part, and duplicate your API key:Â
Hold the important thing for now, as you’ll want it within the following step to provoke the Moralis SDK!Â
Step 2: Write a Script Calling the getWalletTokenBalances() EndpointÂ
Open your most popular built-in improvement surroundings (IDE) and arrange a brand new undertaking. From right here, you’ll want to set up the Moralis SDK. As such, open a brand new terminal and run the next command in your undertaking’s root folder:Â
npm set up moralis @moralisweb3/common-evm-utils
Subsequent, create a brand new ”index.js” file and add the next code:Â
const Moralis = require(“moralis”).default;
const { EvmChain } = require(“@moralisweb3/common-evm-utils”);
const runApp = async () => {
await Moralis.begin({
apiKey: “YOUR_API_KEY”,
// …and some other configuration
});
const tackle = “0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d”;
const chain = EvmChain.ETHEREUM;
const response = await Moralis.EvmApi.token.getWalletTokenBalances({
tackle,
chain,
});
console.log(response.toJSON());
};
runApp();
You then must provoke the Moralis SDK by changing YOUR_API_KEY with the important thing you copied in step one:Â
From there, configure the tackle and chain parameters to suit your request. On this case, the tackle parameter is the pockets tackle from which you need to question the token addresses:
We then cross alongside the parameters when calling the getWalletTokenBalances() endpoint:Â
And that’s it; you’re now able to run the code! Â
Step 3: Run the CodeÂ
For the ultimate step, open a brand new terminal, cd into your undertaking’s root folder, and run the next command to execute the script:Â
node index.js
In return, you’ll get an array of all tokens contained inside the pockets in query. Right here’s an instance of what the response would possibly seem like:Â
[
{
“token_address”: “0xefd6c64533602ac55ab64442307f6fe2c9307305”,
“name”: “APE”,
“symbol”: “APE”,
“logo”: null,
“thumbnail”: null,
“decimals”: 18,
“balance”: “101715701444169451516503179”
},
{
“token_address”: “0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2”,
“name”: “Wrapped Ether”,
“symbol”: “WETH”,
“logo”: “https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.webp”,
“thumbnail”: “https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_thumb.webp”,
“decimals”: 18,
“balance”: “85000000000000000”
}
]
As you may see within the response above, every aspect or token has a token_address parameter. And with this knowledge, you may simply get every ERC-20 token’s tackle!
Congratulations; you now know the best way to get the addresses of all ERC-20 tokens in a pockets utilizing Moralis and the Token API!Â
Abstract: Tips on how to Get the Handle of an ERC-20 Token
In in the present day’s article, we kicked issues off by exploring the ins and outs of ERC-20 token addresses. In doing so, we realized that they’re a novel sequence of numbers and letters used to determine and work together with ERC-20 tokens. Consequently, as you may think about, they’re basic to the Web3 ecosystem.Â
From there, we additionally confirmed you the best way to seamlessly get the tackle of an ERC-20 token utilizing Moralis Cash – an industry-leading token explorer. With this software, you may effortlessly get the tackle of any ERC-20 token in three simple steps:Â
Step 1: Go to Moralis Cash Step 2: Go to the coin’s token pageStep 3: Copy the tackle
As such, if in case you have adopted alongside this far, you now know the best way to get the tackle of an ERC-20 token utilizing Moralis Cash!Â
Along with the tactic above, we confirmed you the best way to get the addresses of ERC-20 tokens utilizing Moralis APIs. In doing so, we lined the next three endpoints:Â
getWalletTokenBalances()getTopERC20TokensByMarketCap()getTopERC20TokensByPriceMovers()
So, you now know the best way to get the addresses of ERC-20 tokens utilizing the Moralis API!
When you preferred this information on the best way to get the tackle of an ERC-20 token, think about diving into extra content material right here on the weblog. As an example, discover the ERC-4337 customary or learn to use the getLogs technique.Â
Additionally, in the event you’re severe about constructing blockchain-based initiatives, be certain that to discover some extra Moralis APIs. As an example, in the event you’re into NFT improvement, you then’ll undoubtedly need to take a look at the NFT API. With this software, you may get verified NFT collections, get all NFT tokens owned by a consumer tackle, and extra!Â
If you’d like entry to those industry-leading improvement instruments, enroll with Moralis instantly!Â