Monday, March 27, 2023
No Result
View All Result
Blockchain Daily Report
Advertisement
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • METAVERSE
  • WEB3
  • SCAM ALERT
  • REGULATIONS
  • ANALYSIS
Crypto Marketcap
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • METAVERSE
  • WEB3
  • SCAM ALERT
  • REGULATIONS
  • ANALYSIS
Crypto Marketcap
Logo
No Result
View All Result
Home Web3

How to Get All Tokens Owned by a Wallet in 5 Steps

by Blockchain Daily Report
December 10, 2022
in Web3
Reading Time: 11 mins read
A A
0
How to Get All Tokens Owned by a Wallet in 5 Steps
Share on FacebookShare on Twitter


Do you need to know how one can get all tokens owned by a pockets? In that case, you’re in the precise place, as this tutorial demonstrates how to take action utilizing Moralis! Due to Moralis’ Token API, you may get all tokens owned by a pockets in 5 simple steps: 

Create a projectInstall Moralis by working the next command within the terminal: npm set up moralis @moralisweb3/common-evm-utils Arrange a brand new fileInput the next contents (add a Moralis API key, deal with, and the specified chain):const Moralis = require(‘moralis’).default;
const { EvmChain } = require(‘@moralisweb3/common-evm-utils’);

const runApp = async () => {
await Moralis.begin({
apiKey: “YOUR_API_KEY”,
// …and another configuration
});

const deal with=”0xBf6521AF44F5D56813A93dCE548E6594Daa00794″;

const chain = EvmChain.ETHEREUM;

const response = await Moralis.EvmApi.token.getWalletTokenBalances({
deal with,
chain,
});

console.log(response.toJSON());
}

runApp(); Name the ”getWalletTokenBalances” endpoint by working this system with this terminal command:node “FILE_NAME”

When you execute this system, you obtain a response containing all tokens owned by the required pockets. It ought to look one thing like this: 

{
“token_address”: “0xff20817765cb7f73d4bde2e66e067e58d11095c2”,
“title”: “Amp”,
“image”: “AMP”,
“brand”: “https://cdn.moralis.io/eth/0xff20817765cb7f73d4bde2e66e067e58d11095c2.png”,
“thumbnail”: “https://cdn.moralis.io/eth/0xff20817765cb7f73d4bde2e66e067e58d11095c2_thumb.png”,
“decimals”: 18,
“steadiness”: “24109691515670000000000”
}

For added info, take a look at the official endpoint documentation to get the steadiness by pockets! 

Overview 

Creating decentralized purposes (dapps) and different Web3 tasks requires related on-chain information. As such, Web3 builders desperately want a fast and efficient technique to question blockchain networks, which is the place Moralis enters the equation. With Moralis’ Web3 APIs, you’ll be able to seamlessly question any blockchain for information and obtain real-time responses. To display the accessibility of Moralis, we’ll on this article present you how one can use the Token API to get all tokens owned by a pockets. If this sounds fascinating, be part of us on this tutorial, as we’ll cowl this course of from begin to end! 

To point out you ways Moralis’ Token API works in follow, the article demonstrates how one can construct an software the place customers can enter an deal with and click on on a button to question the pockets’s token steadiness. Nonetheless, earlier than diving deeper into the central half, the article briefly recaps what a token pockets is. So, if you’re already aware of token wallets, be at liberty to skip straight into the ”Software Demo” part.

What’s extra, the Token API is just one of many instruments Moralis presents. There are a number of different distinguished options to find, which we advocate you do if you’re critical about stepping into Web3 improvement. For instance, take a look at the Auth API, permitting you to seamlessly combine blockchain-based authentication into your tasks with solely single strains of code. If this sounds fascinating, you’ll be able to, for example, discover ways to add an indication in with RainbowKit! 

Nonetheless, it doesn’t matter what blockchain improvement endeavor you embark on, join with Moralis now to leverage the complete potential of blockchain expertise! 

What’s a Token Pockets? 

If you wish to get into the Web3 house, step one is to accumulate a token pockets. Individuals use token wallets to retailer digital property similar to fungible and non-fungible tokens (NFTs). Together with the flexibility to carry property, token wallets additionally typically characteristic further performance. Amongst different issues, this consists of sending, shopping for, promoting, and swapping property. In flip, you’ll be able to totally handle your digital property by way of a token pockets. 

digital image showing a wallet inside a smartphone with bitcoin assets

Together with offering a simple technique to handle your property, token wallets open the door to the blockchain realm. Accordingly, wallets are gateways to the Web3 ecosystem, enabling anybody to work together with dapps and platforms on varied blockchain networks. As such, token wallets play a vital position in blockchain! 

Listed here are some distinguished examples of token pockets suppliers that you may take into account: 

MetaMaskCoinbase WalletPhantomArgentTrust Pockets

What’s extra, if you wish to be taught extra about token wallets, take a look at our information right here on the Web3 weblog exploring Web3 wallets! 

Nonetheless, now that you’re extra aware of token wallets, it’s nearly time to dive into the central a part of this tutorial. Nonetheless, earlier than doing so, we offer a fast demo of the appliance you’ll be taught to create on this article! 

Get All Tokens Owned by a Pockets – Software Demo 

This tutorial teaches you how one can create an easy NextJS software from which customers can get all tokens owned by a pockets. That mentioned, earlier than leaping into the tutorial, this part gives a fast software demo. By overlaying the intricacies of the app, you acquire a greater understanding of what you’re working in direction of! 

Nonetheless, you will discover a screenshot of the app’s touchdown web page down beneath: 

landing page of our get any wallet's token balance app

The appliance options three fundamental elements: a heading, an enter area, and a ”Submit” button. The sphere takes a Web3 pockets deal with as enter, and when you click on on the ”Submit” button, it returns a desk presenting all tokens owned by the required pockets: 

white background with a blue letter title stating get all tokens owned by a wallet

Because the picture above illustrates, the app returns the thumbnail, title, and USD steadiness for all tokens throughout the pockets. Nonetheless, Moralis’ Token API gives further info, similar to every token’s deal with and image. (we’ve simply determined to not show this info on the app’s consumer interface [UI]).

If you wish to discover ways to construct this software, be part of us within the following part, the place we present you how one can get all tokens owned by a pockets in solely 5 simple steps! 

5-Step Breakdown – Methods to Get All Tokens Owned By a Pockets 

With a extra profound understanding of what you’re working in direction of, it’s time to present you how one can get all tokens owned by a pockets. Furthermore, to take action, the next sections train you how one can create an easy NextJS software the place you’ll be able to enter an deal with and get all tokens from a specified pockets in return. What’s extra, due to Moralis’ Token API, it is possible for you to to create this software in solely 5 straightforwards steps: 

Finishing Stipulations and Setting Up a Moralis AccountGet Your Moralis API KeyProject SetupCode Breakdown: ”index.js” and ”header.js”Code Breakdown: ”fundamental.js”

By finishing the steps above, you’ll find out how Moralis’ Token API works and how one can get all tokens owned by a pockets. By the tip of this tutorial, you should have the information so as to add comparable performance to your future dapps! 

moralis in grey lettering

Nonetheless, with out additional ado, allow us to bounce straight into step one and canopy the required conditions! 

Step 1: Finishing Stipulations and Setting Up a Moralis Account

To kick issues off, you initially have to take care of a few conditions on this first step. Particularly, it’s essential guarantee that you’ve got put in NodeJS and npm. You will get these two elements by visiting the NodeJS web site and putting in the latest model.

nodejs symbol on white background

Together with NodeJS and npm, you should join with Moralis. In case you have not already, create a Moralis account proper now. Organising an account solely takes a few minutes and is totally free! 

Step 2: Get Your Moralis API Key 

The primary purpose why it’s essential join with Moralis is that you just want entry to an API key. As we beforehand talked about, you’ll use Moralis’ Token API to get all tokens owned by a pockets. However, to work together with the varied endpoints of this API, you want a Moralis Web3 API key. So, the place are you able to get one? 

After you have an account at your disposal, log in to the Moralis admin panel. Click on on the ”Web3 APIs” tab and find your API key. What’s extra, go forward and duplicate the API key by clicking on the ”Copy” button, as you want the important thing for the following step: 

web3 api page on moralis showing the api key a user can copy

Step 3: Undertaking Setup 

On this third step, it’s time to arrange the appliance. To make this tutorial as accessible as doable, we’ll use an already pre-made undertaking. You will see that the entire software code within the GitHub repository down beneath: 

Get All Tokens Owned by a Pockets Repo – https://github.com/MoralisWeb3/youtube-tutorials/tree/fundamental/get-any-wallets-token-balance

You’ll be able to open the repository and clone the undertaking to your native listing. Doing so ought to give you a neighborhood copy of the code, and it’s best to end up with a file construction just like the one within the picture beneath: 

file structure of the code inside visual studio code

From right here, open a brand new terminal, ”cd” into the undertaking’s root folder, and run the command beneath to put in the Moralis SDK: 

npm set up moralis @moralisweb3/common-evm-utils

Subsequent up, create a brand new file known as ”.env.native” and add an setting variable to your Moralis API key. It ought to look one thing like this (exchange “YOUR_API_KEY” with the precise key): 

NEXT_PUBLIC_MORALIS_API_KEY=”YOUR_API_KEY”

That covers the mandatory steps in making the appliance operational. Nonetheless, we’ve but to elucidate how the appliance works or how one can get all tokens. As such, we break down the code within the following two steps and discover the appliance logic in additional element. This gives perception into how Moralis’ Token API works, permitting you to make use of the identical basic ideas for any future Web3 tasks! 

Step 4: Code Breakdown: ”index.js” & ”header.js” 

With a neighborhood copy of the undertaking at your disposal and the mandatory configurations all full, we’ll take the next part to discover two recordsdata: ”index.js” and ”header.js”. So, allow us to kick issues off by diving into the code of the ”index.js” file! 

”index.js” – The code contained throughout the ”index.js” file is chargeable for rendering the app’s homepage. The contents of the file are comparatively simple, and it appears to be like like this: import Head from “subsequent/head”;
import types from “../types/Dwelling.module.css”;

import Header from “../elements/header”;
import Principal from “../elements/fundamental”;

export default perform Dwelling() {
return (
<part className={types.container}>
<Head>
<title>Get Token Value</title>
<meta title=”description” content material=”Generated by create subsequent app” />
<hyperlink rel=”icon” href=”https://moralis.io/favicon.ico” />
</Head>

<fundamental className={types.fundamental}>
<Header />
<Principal />
</fundamental>
</part>
);
}

On the backside of the file, you will see the code chargeable for rendering two elements: ”Header” and ”Principal”, which make up the 2 further recordsdata we’ll dive deeper into. So, let’s progress by taking a short take a look at ”header.js”. 

”header.js” – The code of the ”header.js” file is kind of simple and is solely chargeable for the app’s title and brand displayed on the UI:import Picture from “subsequent/picture”;
import types from “../types/Dwelling.module.css”;

import Emblem from “../public/property/Moralis_logo.png”;

export default perform Header() {
return (
<part className={types.header}>
<Picture src={Emblem} alt=”Emblem picture” width=”102″ top=”82″ />
<h1 className={types.title}>Get Any Pockets’s Token Steadiness</h1>
</part>
);
}

Within the subsequent step, we’ll dive into ”fundamental.js”, which is the place we discover the appliance logic! 

Step 5: Code Breakdown: ”fundamental.js” 

The ”fundamental.js” file comprises the logic for the appliance and the code enabling us to get all tokens owned by a pockets. This one is kind of in depth if we examine it to the opposite recordsdata we noticed within the earlier step. Consequently, we’ll cut up the file into smaller sections and give attention to the core elements, making it simpler to comply with alongside. So, to start with, allow us to briefly cowl the preliminary 4 strains of the file: 

import { useState } from “react”;
const Moralis = require(“moralis”).default;
const { EvmChain } = require(“@moralisweb3/common-evm-utils”);
import types from “../types/Dwelling.module.css”;

These preliminary strains are chargeable for the mandatory imports. That is additionally the place you put in Moralis and the EVM utils. Following the imports, the rest of the code is the ”header()” perform. This perform does, in flip, characteristic ”handleSubmit()”, containing the logic for buying the tokens owned by a pockets: 

const handleSubmit = async () => {
deal with = doc.querySelector(“#walletAddress”).worth;
const chain = EvmChain.ETHEREUM;

await Moralis.begin({
apiKey: course of.env.NEXT_PUBLIC_MORALIS_API_KEY,
});

const response = await Moralis.EvmApi.token.getWalletTokenBalances({
deal with,
chain,
});

console.log(response.toJSON());
setResult(response.toJSON());
setShowResult(true);
doc.querySelector(“#walletAddress”).worth = “”;
};

Within the first a part of the ”handleSubmit()” perform, you purchase the pockets deal with from the UI, which we retailer within the ”deal with” variable. Subsequent, the code specifying the ”chain” variable to equal ”evmChain.ETHEREUM” signifies that you just need to question an deal with on the Ethereum community. 

From there, the code initializes Moralis utilizing the ”Moralis.begin()” perform, passing your API key as an argument. Lastly, by way of the ”getWalletTokenBalances()” perform, you name the Moralis Token API endpoint and retailer the leads to the ”response” variable. 

The rest of the code renders the app’s UI parts and decides what information to show to the customers: 

return (
<part className={types.fundamental}>
<type
className={types.getTokenForm}
title=”create-profile-form”
technique=”POST”
motion=”#”
>
<label className={types.label} htmlFor=”walletAddress”>
Add ERC20 Pockets Tackle
</label>
<enter
className={types.walletAddress}
kind=”textual content”
id=”walletAddress”
title=”walletAddress”
maxLength=”120″
required
/>
</type>
<button className={types.form_btn} onClick={handleSubmit}>
Submit
</button>
<part className={types.consequence}>
{showResult &&
consequence.map((token) => {
return (
<part
className={types.tokenContainer}
key={consequence.indexOf(token)}
>
<img src={token.thumbnail} />
<p className={types.title}>{token.title}</p>
<p className={types.quantity}>
{(token.steadiness / 10 ** token.decimals).toFixed(2)}
</p>
</part>
);
})}
</part>
</part>
);

That covers the central a part of the appliance code! For a extra detailed breakdown, take a look at the video from Moralis’ YouTube channel beneath. On this clip, you will see a video tutorial overlaying all the course of in additional element: 

As well as, take a look at the official “getWalletTokenBalances” endpoint documentation and the entire Token API documentation for extra details about the Token API and the endpoint used on this tutorial! 

Get All Tokens Owned by a Pockets – Abstract

On this article, you noticed how one can get all tokens owned by a pockets, due to Moralis’ Token API. To point out this API in motion, the article demonstrated how one can create an easy NextJS dapp permitting anybody to question a pockets’s token steadiness based mostly on its deal with. What’s extra, due to the accessibility of Moralis, you have been capable of create this app in solely 5 steps: 

Finishing Stipulations and Setting Up a Moralis AccountGet Your Moralis API KeyProject SetupCode Breakdown: ”index.js” & ”header.js”Code Breakdown: ”fundamental.js”

When you discovered this text useful, there are different thrilling guides so that you can take a look at on Moralis’ Web3 weblog. For instance, discover the intricacies of Ethereum webhooks or discover ways to get NFT collections utilizing Python! Furthermore, if Ethereum improvement pursuits you probably the most, take a look at our articles exploring how one can get the steadiness of ERC20 tokens, the final word ERC20 token API, and the most effective ERC20 token steadiness API for dapp improvement!

Nonetheless, if you wish to totally leverage the facility of blockchain, join with Moralis instantly. You’ll be able to arrange your account free of charge, and it solely takes seconds, so you don’t have anything to lose! 



Source link

Tags: OwnedStepsTokensWallet
Share76Tweet47

Related Posts

Hong Kong blockchain initiatives natural evolution for finance hub, says Signum Digital CEO

Hong Kong blockchain initiatives natural evolution for finance hub, says Signum Digital CEO

by Blockchain Daily Report
March 24, 2023
0

After the worldwide crypto failures and bankruptcies in 2022 and China’s recognized distaste for cryptocurrencies, Hong Kong regulators stunned with...

Hong Kong poised for ambitious changes

Hong Kong poised for ambitious changes

by Blockchain Daily Report
March 23, 2023
0

Welcome to Future Guidelines, March 23, 2023 – introduced by Joel Flynn.2023 is shaping as much as be a yr...

How DAOs can be remade to be more successful

How DAOs can be remade to be more successful

by Blockchain Daily Report
March 23, 2023
0

Centralized crypto finance took a beating over the past 12 months.However the folks and buyers who relied on centralized constructions...

How to Get a Wallet Balance on Aptos

How to Get a Wallet Balance on Aptos

by Blockchain Daily Report
March 23, 2023
0

Discover the best method to get a pockets steadiness on Aptos with the Web3 Information API from Moralis. With this...

Get Crypto Data Using a Python API for Cryptocurrency

Get Crypto Data Using a Python API for Cryptocurrency

by Blockchain Daily Report
March 22, 2023
0

This tutorial will educate you to make use of the Python-compatible Web3 Knowledge API from Moralis to tug cryptocurrency costs,...

Load More
  • Trending
  • Comments
  • Latest
Mine CLORE Coins Used by the CLORE.AI Distributed Computing Platform

Mine CLORE Coins Used by the CLORE.AI Distributed Computing Platform

January 23, 2023
WildRig Multi 0.36.4 beta Now With Faster NEXA Performance and Lower Fee

WildRig Multi 0.36.4 beta Now With Faster NEXA Performance and Lower Fee

January 23, 2023
These Are The Key Takeaways From Shibarium Docs

These Are The Key Takeaways From Shibarium Docs

March 27, 2023
The Crypto Momentum of Traditional Brokers

The Crypto Momentum of Traditional Brokers

March 27, 2023
The 100 most popular art museums in the world—who has recovered and who is still struggling?

The 100 most popular art museums in the world—who has recovered and who is still struggling?

March 27, 2023
A Look at the Fed’s Recent Custodia Bank Denial and the Central Bank’s Push Back Against Narrow Banking – Economics Bitcoin News

A Look at the Fed’s Recent Custodia Bank Denial and the Central Bank’s Push Back Against Narrow Banking – Economics Bitcoin News

March 27, 2023
ARK Invest Scoops Up Coinbase, Block Shares for Second Straight Day

ARK Invest Scoops Up Coinbase, Block Shares for Second Straight Day

March 27, 2023
US Lawmaker Introduces Bill to Affirm Blockchain Developers and Non-Custodial Services Are Not Money Transmitters – Regulation Bitcoin News

US Lawmaker Introduces Bill to Affirm Blockchain Developers and Non-Custodial Services Are Not Money Transmitters – Regulation Bitcoin News

March 27, 2023
Terra Co-Founder Do Kwon Plans to Appeal Detention Extension After Arrest in Montenegro – Bitcoin News

Terra Co-Founder Do Kwon Plans to Appeal Detention Extension After Arrest in Montenegro – Bitcoin News

March 26, 2023
Animoca Brands refutes claims of scaling back metaverse fund target and plummeting valuation

Animoca Brands refutes claims of scaling back metaverse fund target and plummeting valuation

March 26, 2023
Facebook Twitter Instagram Youtube RSS

Find the latest Bitcoin, Ethereum, blockchain, crypto, Business, Fintech News, interviews, and price analysis at Blockchain Daily Report.

CATEGORIES

  • Altcoin
  • Analysis
  • Bitcoin
  • Blockchain
  • Crypto Exchanges
  • Crypto Mining
  • Crypto Updates
  • DeFi
  • Ethereum
  • Metaverse
  • NFT
  • Regulations
  • Scam Alert
  • Uncategorized
  • Web3

SITE MAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2022 Blockchain Daily Report.
Blockchain Daily Report is not responsible for the content of external sites.

No Result
View All Result
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • METAVERSE
  • WEB3
  • SCAM ALERT
  • REGULATIONS
  • ANALYSIS

Copyright © 2022 Blockchain Daily Report.
Blockchain Daily Report is not responsible for the content of external sites.

  • bitcoinBitcoin(BTC)$27,959.000.49%
  • ethereumEthereum(ETH)$1,765.66-0.81%
  • USDEXUSDEX(USDEX)$1.07-0.53%
  • tetherTether(USDT)$1.00-0.41%
  • binancecoinBNB(BNB)$328.770.16%
  • usd-coinUSD Coin(USDC)$1.00-0.35%
  • rippleXRP(XRP)$0.4700471.62%
  • cardanoCardano(ADA)$0.352464-2.02%
  • staked-etherLido Staked Ether(STETH)$1,768.88-0.84%
  • dogecoinDogecoin(DOGE)$0.073888-1.79%