• About
  • Landing Page
  • Buy JNews
SB Crypto Guru News- latest crypto news, NFTs, DEFI, Web3, Metaverse
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • WEB3
  • METAVERSE
  • REGULATIONS
  • SCAM ALERT
  • ANALYSIS
No Result
View All Result
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • WEB3
  • METAVERSE
  • REGULATIONS
  • SCAM ALERT
  • ANALYSIS
No Result
View All Result
SB Crypto Guru News- latest crypto news, NFTs, DEFI, Web3, Metaverse
No Result
View All Result

How one can Get All Tokens Owned by a Pockets in 5 Steps

SB Crypto Guru News by SB Crypto Guru News
December 10, 2022
in Web3
0 0
0
How one can Get All Tokens Owned by a Pockets in 5 Steps


Do you wish to know the right way to get all tokens owned by a pockets? If that’s the 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: 

  1. Create a challenge
  2. Set up Moralis by operating the next command within the terminal: 
npm set up moralis @moralisweb3/common-evm-utils
  1. Arrange a brand new file
  2. Enter the next contents (add a Moralis API key, tackle, 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 some other configuration
  });
  
  const tackle="0xBf6521AF44F5D56813A93dCE548E6594Daa00794";

  const chain = EvmChain.ETHEREUM;

  const response = await Moralis.EvmApi.token.getWalletTokenBalances({
    tackle,
    chain,
  });
  
  console.log(response.toJSON());
}

runApp();
  1. Name the ”getWalletTokenBalances” endpoint by operating 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 extra 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 knowledge. As such, Web3 builders desperately want a fast and efficient method to question blockchain networks, which is the place Moralis enters the equation. With Moralis’ Web3 APIs, you possibly can seamlessly question any blockchain for knowledge and obtain real-time responses. To reveal the accessibility of Moralis, we are going to on this article present you the right way to use the Token API to get all tokens owned by a pockets. If this sounds attention-grabbing, be a part of us on this tutorial, as we are going to cowl this course of from begin to end! 

To indicate you ways Moralis’ Token API works in apply, the article demonstrates the right way to construct an utility the place customers can enter an tackle 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 accustomed to token wallets, be at liberty to skip straight into the ”Utility Demo” part.

What’s extra, the Token API is just one of many instruments Moralis gives. There are a number of different distinguished options to find, which we suggest you do if you’re severe about entering 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 traces of code. If this sounds attention-grabbing, you possibly can, for example, learn 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! 

scale with moralis

What’s a Token Pockets? 

If you wish to get into the Web3 house, step one is to amass a token pockets. Folks use token wallets to retailer digital belongings comparable to fungible and non-fungible tokens (NFTs). Together with the power to carry belongings, token wallets additionally usually characteristic further performance. Amongst different issues, this contains sending, shopping for, promoting, and swapping belongings. In flip, you possibly can absolutely handle your digital belongings by way of a token pockets. 

digital image showing a wallet inside a smartphone with bitcoin assets

Together with offering a simple method to handle your belongings, 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 numerous blockchain networks. As such, token wallets play a necessary function in blockchain! 

Listed below are some distinguished examples of token pockets suppliers that you would be able to take into account: 

  • MetaMask
  • Coinbase Pockets
  • Phantom
  • Argent
  • Belief Pockets

What’s extra, if you wish to study 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 accustomed to 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 study to create on this article! 

Get All Tokens Owned by a Pockets – Utility Demo 

This tutorial teaches you the right way to create an easy NextJS utility from which customers can get all tokens owned by a pockets. That mentioned, earlier than leaping into the tutorial, this part gives a fast utility 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 major parts: a heading, an enter discipline, and a ”Submit” button. The sphere takes a Web3 pockets tackle 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, comparable to every token’s tackle and image. (we’ve simply determined to not show this info on the app’s consumer interface [UI]).

If you wish to learn to construct this utility, be a part of us within the following part, the place we present you the right way to get all tokens owned by a pockets in solely 5 simple steps! 

5-Step Breakdown – How one can 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 the right way to get all tokens owned by a pockets. Furthermore, to take action, the next sections train you the right way to create an easy NextJS utility the place you possibly can enter an tackle and get all tokens from a specified pockets in return. What’s extra, because of Moralis’ Token API, it is possible for you to to create this utility in solely 5 straightforwards steps: 

  1. Finishing Stipulations and Setting Up a Moralis Account
  2. Get Your Moralis API Key
  3. Venture Setup
  4. Code Breakdown: ”index.js” and ”header.js”
  5. Code Breakdown: ”major.js”

By finishing the steps above, you’ll learn the way Moralis’ Token API works and the right way to get all tokens owned by a pockets. By the tip of this tutorial, you’ll have the information so as to add related performance to your future dapps! 

moralis in grey lettering

Nonetheless, with out additional ado, allow us to soar 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 must take care of a few conditions on this first step. Particularly, you must guarantee that you’ve got put in NodeJS and npm. You will get these two parts by visiting the NodeJS web site and putting in the latest model.

nodejs symbol on white background

Together with NodeJS and npm, you have to 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 solely free! 

Step 2: Get Your Moralis API Key 

The primary cause why you must 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? 

Upon getting 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: Venture Setup 

On this third step, it’s time to arrange the appliance. To make this tutorial as accessible as attainable, we are going to use an already pre-made challenge. You can see the entire utility code within the GitHub repository down beneath: 

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

You may open the repository and clone the challenge to your native listing. Doing so ought to give you a neighborhood copy of the code, and you must 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 challenge’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 referred to as ”.env.native” and add an atmosphere variable on your Moralis API key. It ought to look one thing like this (substitute “YOUR_API_KEY” with the precise key): 

NEXT_PUBLIC_MORALIS_API_KEY=”YOUR_API_KEY”

That covers the required steps in making the appliance operational. Nonetheless, now we have 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 elementary ideas for any future Web3 tasks! 

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

With a neighborhood copy of the challenge at your disposal and the required configurations all full, we are going to 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 answerable 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/House.module.css";

import Header from "../parts/header";
import Predominant from "../parts/major";

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

      <major className={types.major}>
        <Header />
        <Predominant />
      </major>
    </part>
  );
}

On the backside of the file, you can see the code answerable for rendering two parts: ”Header” and ”Predominant”, which make up the 2 further recordsdata we are going to 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 answerable for the app’s title and brand displayed on the UI:
import Picture from "subsequent/picture";
import types from "../types/House.module.css";

import Brand from "../public/belongings/Moralis_logo.png";

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

Within the subsequent step, we are going to dive into ”major.js”, which is the place we discover the appliance logic! 

Step 5: Code Breakdown: ”major.js” 

The ”major.js” file accommodates 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 are going to break up the file into smaller sections and deal with the core components, making it simpler to comply with alongside. So, to start with, allow us to briefly cowl the preliminary 4 traces of the file: 

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

These preliminary traces are answerable for the required 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 () => {
    tackle = 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({
      tackle,
      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 tackle from the UI, which we retailer within the ”tackle” variable. Subsequent, the code specifying the ”chain” variable to equal ”evmChain.ETHEREUM” signifies that you just wish to question an tackle 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 ends in the ”response” variable. 

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

return (
    <part className={types.major}>
      <kind
        className={types.getTokenForm}
        title="create-profile-form"
        technique="POST"
        motion="#"
      >
        <label className={types.label} htmlFor="walletAddress">
          Add ERC20 Pockets Handle
        </label>
        <enter
          className={types.walletAddress}
          sort="textual content"
          id="walletAddress"
          title="walletAddress"
          maxLength="120"
          required
        />
      </kind>
      <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 can see a video tutorial overlaying the complete 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 the right way to get all tokens owned by a pockets, because of Moralis’ Token API. To indicate this API in motion, the article demonstrated the right way to create an easy NextJS dapp permitting anybody to question a pockets’s token steadiness primarily based on its tackle. What’s extra, because of the accessibility of Moralis, you have been capable of create this app in solely 5 steps: 

  1. Finishing Stipulations and Setting Up a Moralis Account
  2. Get Your Moralis API Key
  3. Venture Setup
  4. Code Breakdown: ”index.js” & ”header.js”
  5. Code Breakdown: ”major.js”

If you happen to 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 learn to get NFT collections utilizing Python! Furthermore, if Ethereum improvement pursuits you essentially the most, take a look at our articles exploring the right way to get the steadiness of ERC20 tokens, the last word ERC20 token API, and the very best ERC20 token steadiness API for dapp improvement!

Nonetheless, if you wish to absolutely leverage the facility of blockchain, join with Moralis instantly. You may arrange your account without spending a dime, and it solely takes seconds, so you don’t have anything to lose! 





Source link

Tags: Bitcoin NewsCrypto NewsCrypto UpdatesLatest News on CryptoownedSB Crypto Guru NewsStepstokensWallet
Previous Post

Argentina Organizes Nationwide Blockchain Committee to Implement State Stage Technique – Blockchain Bitcoin Information

Next Post

The Final Crypto Market Information Supplier Information 2023 | by Patrick Mehrhoff | The Capital | Dec, 2022

Next Post
The Final Crypto Market Information Supplier Information 2023 | by Patrick Mehrhoff | The Capital | Dec, 2022

The Final Crypto Market Information Supplier Information 2023 | by Patrick Mehrhoff | The Capital | Dec, 2022

  • Trending
  • Comments
  • Latest
Meta Quest Pro Discontinued! Enterprise-Grade MR Headset is No Longer Available

Meta Quest Pro Discontinued! Enterprise-Grade MR Headset is No Longer Available

January 6, 2025
Big XR News from Google, Samsung, Qualcomm, Sony, XREAL, Magic Leap, Lynx, Meta, Microsoft, TeamViewer, Haply

Big XR News from Google, Samsung, Qualcomm, Sony, XREAL, Magic Leap, Lynx, Meta, Microsoft, TeamViewer, Haply

December 13, 2024
How to Get Token Prices with an RPC Node – Moralis Web3

How to Get Token Prices with an RPC Node – Moralis Web3

September 3, 2024
Meta Pumps a Further  Million into Horizon Metaverse

Meta Pumps a Further $50 Million into Horizon Metaverse

February 24, 2025
Exploring Moonbeam – Why Build on Moonbeam? – Moralis Web3

Exploring Moonbeam – Why Build on Moonbeam? – Moralis Web3

September 11, 2024
How to Get NFT Balances with One RPC Call – Moralis Web3

How to Get NFT Balances with One RPC Call – Moralis Web3

August 30, 2024
XRP drops 34% from January peak as crypto reserve plan fall short

XRP drops 34% from January peak as crypto reserve plan fall short

0
Pi bets on games to bolster ecosystem amidst price struggles

Pi bets on games to bolster ecosystem amidst price struggles

0
Daon Announces Strategic Partnership with Giesecke+Devrient

Daon Announces Strategic Partnership with Giesecke+Devrient

0
Ethereum Poised For A 5-Figure Breakout – Volatility Is Shaking ‘Weak Hands’

Ethereum Poised For A 5-Figure Breakout – Volatility Is Shaking ‘Weak Hands’

0
London Gallery Weekend 2025: the best shows for photography lovers

London Gallery Weekend 2025: the best shows for photography lovers

0
5 Proven XR and AI Training Use Cases for Enterprises

5 Proven XR and AI Training Use Cases for Enterprises

0
XRP drops 34% from January peak as crypto reserve plan fall short

XRP drops 34% from January peak as crypto reserve plan fall short

June 2, 2025
Ethereum Poised For A 5-Figure Breakout – Volatility Is Shaking ‘Weak Hands’

Ethereum Poised For A 5-Figure Breakout – Volatility Is Shaking ‘Weak Hands’

June 2, 2025
Pi bets on games to bolster ecosystem amidst price struggles

Pi bets on games to bolster ecosystem amidst price struggles

June 2, 2025
London Gallery Weekend 2025: the best shows for photography lovers

London Gallery Weekend 2025: the best shows for photography lovers

June 2, 2025
5 Proven XR and AI Training Use Cases for Enterprises

5 Proven XR and AI Training Use Cases for Enterprises

June 2, 2025
Snorter Token Presale Hits 0K Within Hours — The Crypto Presale Gems to Discover With Real Utility

Snorter Token Presale Hits $100K Within Hours — The Crypto Presale Gems to Discover With Real Utility

June 2, 2025
SB Crypto Guru News- latest crypto news, NFTs, DEFI, Web3, Metaverse

Find the latest Bitcoin, Ethereum, blockchain, crypto, Business, Fintech News, interviews, and price analysis at SB Crypto Guru News.

CATEGORIES

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

SITE MAP

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

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

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

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.