Getting Started

Fetch an NFT

Fetch NFT data from the Solana blockchain.

Fetch an NFT or a Collection

In the following section you can find a full code example and the parameters that you might need to change. You can learn more about fetching NFTs and collections in the Core documentation.

1import { fetchAsset, fetchCollection, mplCore } from '@metaplex-foundation/mpl-core';
2import { publicKey } from '@metaplex-foundation/umi';
3import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
4
5// Initialize UMI
6const umi = createUmi('https://api.devnet.solana.com')
7 .use(mplCore())
8
9// Fetch a Core Asset
10const assetAddress = publicKey('AssetAddressHere...')
11const asset = await fetchAsset(umi, assetAddress)
12
13// Fetch a Core Collection
14const collectionAddress = publicKey('CollectionAddressHere...')
15const collection = await fetchCollection(umi, collectionAddress)
16
17console.log('Asset fetched:', asset)
18console.log('Name:', asset.name)
19console.log('Owner:', asset.owner)
20console.log('URI:', asset.uri)
21
22console.log('\nCollection fetched:', collection)
23console.log('Name:', collection.name)
24console.log('URI:', collection.uri)

Parameters

Customize these parameters for your fetch:

ParameterDescription
assetAddressThe public key of the NFT asset
collectionAddressThe public key of the collection (optional)

How It Works

The fetch process involves these steps:

  1. Get the address - You need the public key of the NFT asset or collection you want to fetch
  2. Fetch asset data - Use fetchAsset to retrieve NFT information including name, URI, owner, and plugins
  3. Fetch collection data - Use fetchCollection to retrieve collection information (optional)

NFT and Collection Data

When you fetch an asset, you get back all its data:

  • Name - The NFT's name
  • URI - Link to the metadata JSON
  • Owner - The wallet that owns the NFT
  • Update Authority - Who can modify the NFT
  • Plugins - Any attached plugins like royalties or attributes

When you fetch a collection, you get:

  • Name - The collection's name
  • URI - Link to the collection metadata JSON
  • Update Authority - Who can modify the collection
  • Num Minted - Number of assets in the collection
  • Plugins - Any attached plugins like royalties or attributes