Getting Started
Fetch an NFT
Last updated March 12, 2025
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)
1# Fetch an NFT using the Metaplex CLI
2
3# Fetch asset by ID
4mplx core fetch asset <assetId>
5
6# Download all files to a directory
7mplx core fetch asset <assetId> --download --output ./assets
8
9# Download only the image
10mplx core fetch asset <assetId> --download --image
11
12# Download only the metadata
13mplx core fetch asset <assetId> --download --metadata
1// npm install @metaplex-foundation/umi @metaplex-foundation/umi-bundle-defaults @metaplex-foundation/digital-asset-standard-api
2import { publicKey } from '@metaplex-foundation/umi'
3import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
4import { dasApi } from '@metaplex-foundation/digital-asset-standard-api'
5
6// Initialize Umi with a DAS-enabled RPC endpoint
7const umi = createUmi('https://api.devnet.solana.com').use(dasApi())
8
9// The address of the NFT you want to fetch
10const assetAddress = publicKey('YOUR_NFT_ADDRESS')
11
12// Fetch the asset using DAS API
13const asset = await umi.rpc.getAsset(assetAddress)
14
15console.log('Asset ID:', asset.id)
16console.log('Name:', asset.content.metadata?.name)
17console.log('Description:', asset.content.metadata?.description)
18console.log('Image:', asset.content.links?.image)
19console.log('Owner:', asset.ownership.owner)
20console.log('Interface:', asset.interface)
1# Fetch an NFT using the DAS API
2curl -X POST \
3 -H "Content-Type: application/json" \
4 -d '{
5 "jsonrpc": "2.0",
6 "id": 1,
7 "method": "getAsset",
8 "params": {
9 "id": "<NFT Mint Address>"
10 }
11 }' \
12 https://api.devnet.solana.com
Parameters
Customize these parameters for your fetch:
| Parameter | Description |
|---|---|
assetAddress | The public key of the NFT asset |
collectionAddress | The public key of the collection (optional) |
How It Works
The fetch process involves these steps:
- Get the address - You need the public key of the NFT asset or collection you want to fetch
- Fetch asset data - Use
fetchAssetto retrieve NFT information including name, URI, owner, and plugins - Fetch collection data - Use
fetchCollectionto 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
