Shyft
Start BuildingSupportWebsite
  • Welcome
    • 👋Introducing Shyft
    • 🏗️Start Building
  • Solana Infrastructure
    • 🚁Shyft RPCs
  • Yellowstone gRPC Network
    • Decoding gRPC Latency
    • ⚡gRPC Docs
      • Introduction
      • Authentication
      • Subscribe Requests
      • FAQ
      • Getting Started
        • Initializing the Yellowstone Client
        • Making a gRPC connection
        • Adding a Reconnection Mechanism
        • 🔥Replaying Slots with Solana yellowstone gRPCs
        • Modifying your Subscribe Request
        • Closing a gRPC Connection
      • Subscribing to Transactions
        • All Transactions of an address
        • Subscribing to all transactions of a Liquidity Pool
        • Subscribing to all transactions of multiple addresses
        • Subscribing to all transactions of a Token
      • Subscribing to Accounts
        • Account Updates for a Program
        • Account Updates for an Address
        • Account updates using memcmp
      • Streaming Blocks & BlocksMeta
        • Streaming Block Updates
        • Subscribing to BlocksMeta
      • Modifying & Unsubscribing
  • Solana defi data
    • DeFI APIs
      • Get Pool By Address
      • Get Pools By Token Pair
      • Get All Pools for a Token
      • Get Liquidity Details of a Pool
  • Callbacks
    • ☎️What are Callbacks?
      • Transaction Callbacks
      • Account Callbacks
    • 📔Callback APIs
      • Response Structure
      • List Callbacks
      • Register callback
      • Remove callback
      • 🔥Pause a callback
      • 🔥Resume a callback
      • Update Callbacks
      • Add Addresses
      • Remove addresses
  • Solana Super Indexers
    • 🌩️GraphQL APIs
      • Getting Started
      • Building Queries
      • Paginating Response
      • Applying Filters
      • Ordering and Sorting Data
    • 📀Case Studies
      • Tensor
        • Get Active Listings of a Wallet
        • Get Active Bids of a Wallet
        • Get Active Listings of a Collection
        • Get all Bids of a Collection
        • Get all Pools of a Margin Account
        • Get all Pools by Owner
      • Raydium
        • Get Pool By Address
        • Get Pools By Token Address
        • Get Pools Created Between Time
        • Get Pool Burn Percentage
        • Get Liquidity Details of a Pool
        • Get Pool and OpenBook Market Info
        • Get Token Supply Percentage In Pool
      • Orca Whirlpool
        • Get Pool by Address
        • Get Pool by Token Address
        • Get Positions for a Pool
        • Get Positions for a Wallet
        • Get Liquidity Details of a Pool
      • Kamino
        • Get Borrow Details of a Wallet
        • Get Deposit Details of a Wallet
        • Get Reserve Details
      • Cross Marketplace Queries
        • Get active listings across marketplaces for a wallet
        • Get listings for a collection across marketplaces
        • Get floor price of a collection
      • Cross Defi Queries
        • Fetch Liquidity Pools for Token
      • Native Staking
        • Get Stakes for a Wallet
        • Get Stakes For Validator
      • Governance/Realms
        • Get DAO Token Owners
        • Get Proposals For Governing Mint
        • Get All Proposals For DAO
        • Get DAO Treasury Info
        • Get All Active Proposals For Wallet
      • Meteora
        • Get All LB Position Pairs
        • Get Position of a User Wallet
        • Get Pool by Token Addresses
        • Get All Deposits for a User
        • Get All Withdraws for a User
        • Get All Fees Claimed by a User
        • Get All User Positions and Deposits for a Pool
        • Get All User Positions and Withdrawals for a Pool
      • Fluxbeam
        • Get Pool by Address
        • Get Pool by Token Addresses
      • Drift
        • Get User account for Delegate
        • Get User accounts based on authority
        • Get User details based on Referrer
        • Get Borrow/Deposit Amount for an User
        • Get PrepPositions for an User Account
        • Getting OrderId and userOrderId
        • Get OpenOrders for a User Account
      • 🔥Pumpswap
        • 🔥Get Pool by Address
        • 🔥Get Pool by Creator Address
        • 🔥Get Pools by Token Addresses
      • Raydium Launchpad
        • Get Bonding Curve Details by Pool Address
        • Get All Pools for a Creator
        • Get Pools by Token Addresses
        • Get Migration details of a Pool
  • Solana APIs
    • API Reference
    • Transactions
      • Parsed Transaction Structure
      • Transaction APIs
        • History
        • Parse Signature
        • Parse Multiple Signatures
        • Send
        • Send Multiple
    • NFT
      • 🔥Create Gasless
      • Create
      • Read All
      • Burn
      • 🔥Burn Multiple NFTs V2
      • Update
      • 🔥Create NFT from Metadata
      • 🔥Read Wallet Nfts
      • 🔥Read Selected NFTs
      • 🔥Get NFT Owners
      • 🔥Update NFT Metadata Uri
      • 🔥Update V2
      • Search
      • Transfer
      • Transfer Multiple NFTs
      • Mint
      • Read
    • Wallet
      • Get Balance
      • Get Token Balance
      • Get All Tokens Balance
      • Get Portfolio
      • Resolve Address
      • Get All Domains
      • Get Stake Accounts
    • Fungible Tokens
      • Create
      • Mint
      • Burn
      • 🔥Update
      • Get Token Info
      • Transfer
      • Airdrop
Powered by GitBook
On this page
  • Coding begins
  • Connecting to Phantom wallet
  • Creating Wallet connect UI component
  • Adding the REST Call
  • Update App.js
  • It's Showtime now...
  • Resources

Was this helpful?

  1. Tutorials

Read all NFTs from a wallet

Shyft APIs makes it very easy to allow your applications to read all NFTs inside a wallet

Last updated 2 years ago

Was this helpful?

We are going to create a simple web site that displays all the NFTs in a wallet. We can do this by using 1 single Shyft API:

We need to have few things in place before we dive into reading wallets. These are:

  1. Installed browser extension for Phantom Wallet. to install it.

  2. npm and npx installed in your programming environment. If not already setup,.

Coding begins

First things first.

Get your Free Shyft API key

You need to get your API key to create the NFT. Head

and receive the api-key in your email id.

Setup react project

$ npx create-react-app my-first-nft-dapp

This creates the boilerplate code for your Dapp.

Updating package.json

Update the newly generated package.json dependency section and add:

"dependencies": {
    ...
    "@solana/wallet-adapter-phantom": "^0.9.7",
    "@solana/web3.js": "^1.50.0",
    "axios": "^0.27.2",    
    ...
  },

These dependencies are needed to make http requests, and connect to the phantom wallet.

Connecting to Phantom wallet

Lets create a new file under the /src directory called ListAll.js.

Now put the code snippet below, in this file.

import { useState } from "react";
import axios from "axios";
import { clusterApiUrl, Connection, PublicKey } from "@solana/web3.js";
import { PhantomWalletAdapter } from '@solana/wallet-adapter-phantom';

const ListAll = () => {
  const xKey = "<YOUR_API_KEY>";
  const [wallID, setWallID] = useState("");
  const [network, setNetwork] = useState("devnet");
  const [isLoaded, setLoaded] = useState(false);
  const [dataFetched, setDataFetched] = useState();
  const [connStatus, setConnStatus] = useState(false);

  // Phantom Adaptor
  const solanaConnect = async () => {
    console.log('clicked solana connect');
    const { solana } = window;
    if (!solana) {
      alert("Please Install Solana");
    }

    try {
      //const network = "devnet";
      const phantom = new PhantomWalletAdapter();
      await phantom.connect();
      const rpcUrl = clusterApiUrl(network);
      const connection = new Connection(rpcUrl, "confirmed");
      const wallet = {
        address: phantom.publicKey.toString(),
      };

      if (wallet.address) {
        console.log(wallet.address);
        setWallID(wallet.address);
        const accountInfo = await connection.getAccountInfo(new PublicKey(wallet.address), "confirmed");
        console.log(accountInfo);
        setConnStatus(true);
      }
    }
    catch (err) {
      console.log(err);
    }

  }
  
  return ();
};

Also, put your generated API key in variable xKey.

The above snippet has a function solanaConnect() that connects to the phantom browser extension.

Creating Wallet connect UI component

Now let's create a simple UI button to that allows a user to connect the phantom wallet. This UI component will invoke the solanaConnect() function that we created in the previous step.

In ListAll.js place the below JSX code snippet inside the return() function:

<div className="grd-back">
  <div className="container-lg">
    <div className="py-4 text-center">
      <h1>List All Your NFTs</h1>
      <p>
        This is a sample project which will list all your NFTs associated
        with your wallet
      </p>
    </div>
  </div>

  <div className="container-lg">
    {!connStatus && (<div className="card border border-primary rounded py-3 px-5 w-50 mx-auto">
      <div className="card-body text-center">
        <h2 className="card-title p-2">Connect Your Wallet</h2>
        <p className="card-text p-1">You need to connect your wallet to deploy and interact with your contracts.</p>
        <button className="btn btn-primary mt-5 px-3" onClick={solanaConnect}>Connect Phantom Wallet</button>
        {/* <select className="form-select" onChange={(e) => {
          console.log(e.target.value);
          (e.target.value === 'mtmsk') ? mtmskConnect() : solanaConnect();
        }}>
          <option value="none">Connect</option>
          <option value="phntm">Phantom</option>
        </select> */}
      </div>
    </div>)}
    {connStatus && (<div className="w-50 border border-primary rounded-3 mx-auto">
      <div className="form-container p-3">
        <form>
          <div className="row d-flex justify-content-center">

            <div className="col-12 p-2">
              <select
                name="network"
                className="form-control form-select"
                id=""
                onChange={(e) => setNetwork(e.target.value)}
              >
                <option value="devnet">Devnet</option>
                <option value="testnet">Testnet</option>
                <option value="mainnet-beta">Mainnet Beta</option>
              </select>
            </div>
            <div className="col-12 p-2">
              <input
                type="text"
                className="form-control"
                placeholder="Enter Wallet Id"
                value={wallID}
              />
            </div>

          </div>
          <div className="text-center p-3">
            <button
              className="btn btn-primary"
              onClick={fetchNFTs}
            >
              Get
            </button>
          </div>
        </form>
      </div>
    </div>)}
  </div>

  <div className="container-lg">
    <div className="cards-section py-4">
      <div className="row">
        {isLoaded &&
          dataFetched.result.map((item) => (
            <div className="col-xs-12 col-sm-3 p-3" key={item.mint}>
              <div className="card nft-card">
                <div className="card-body">
                  <a href={`/get-details?token_address=${item.mint}&apiKey=${xKey}`} target="_blank" rel="noreferrer">
                    <img className="img-fluid" src={item.image_uri} alt="img" />
                  </a>
                  <a href={`/get-details?token_address=${item.mint}&apiKey=${xKey}`} target="_blank" rel="noreferrer">
                    <h5>{item.name}</h5>
                  </a>
                </div>
              </div>
            </div>
          ))}

      </div>
    </div>
  </div>
</div>

Adding the REST Call

It's time to invoke the almighty read_all Shyft's API to read the NFTs in a wallet.

To do this create another function fetchNFTs() , inside the ListAl() function.

const fetchNFTs = (e) => {
    e.preventDefault();

    //Note, we are not mentioning update_authority here for now
    let nftUrl = `https://api.shyft.to/sol/v1/nft/read_all?network=${network}&address=${wallID}`;
    axios({
      // Endpoint to send files
      url: nftUrl,
      method: "GET",
      headers: {
        "Content-Type": "application/json",
        "x-api-key": xKey,
      },
      // Attaching the form data
    })
      // Handle the response from backend here
      .then((res) => {
        console.log(res.data);
        setDataFetched(res.data);
        setLoaded(true);
      })

      // Catch errors if any
      .catch((err) => {
        console.warn(err);
      });
  };

Update App.js

Before we can run the project last thing we have to do is to modify our App.js file:

import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import ListAll from "./ListAll";

function App() {
  return (
    <div className="App">
      <Router>
        <Routes>
          <Route exact path="/" element={<ListAll />} />
        </Routes>
      </Router>
    </div>
  );
}

export default App;

It's Showtime now...

Let's run this app by running, on console.:

npm start

Go ahead and connect your wallet, on successful connection you will be prompted to choose a Solana network

After selecting your desired network, hit get. And there you go, all your NFTs will be visible to you.

A lot more tutorials coming up, to help developers create super powerful dapps, quickly.

STAY TUNED!!

Resources

Thank you for your time. Happy hacking.

The final code for ListAll.js can be found .

Head over to your and you will see a simple UI like this one:

We have already created this project for you to play around, with a good looking UI. The entire source code is available in this repository . Make sure you FORK it and have fun playing around with it.

Also, this dapp is already deployed and available . Congratulations now, you are one step closer to creating super flexible web3 dapps, for your users.

Join our

here
localhost
https://github.com/Shyft-to/list-all-nfts-from-wallet
here
SHYFT API Documentation
Shyft Website
Get API Key
Github
Discord
here
Refer here
refer here
Read_All
Wallet connect action box
Network Selection
All NFTs available in your wallet
Page cover image