시작하기
NFT 가져오기
Last updated March 12, 2025
Solana 블록체인에서 NFT 데이터를 가져옵니다.
NFT 또는 컬렉션 가져오기
다음 섹션에서 전체 코드 예제와 변경이 필요할 수 있는 파라미터를 확인할 수 있습니다. NFT와 컬렉션 가져오기에 대한 자세한 내용은 Core 문서를 참조하세요.
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
파라미터
가져오기에 맞게 다음 파라미터를 커스터마이징하세요:
| 파라미터 | 설명 |
|---|---|
assetAddress | NFT 자산의 공개 키 |
collectionAddress | 컬렉션의 공개 키 (선택 사항) |
작동 방식
가져오기 과정은 다음 단계를 포함합니다:
- 주소 가져오기 - 가져오려는 NFT 자산 또는 컬렉션의 공개 키가 필요합니다
- 자산 데이터 가져오기 -
fetchAsset을 사용하여 이름, URI, 소유자, 플러그인을 포함한 NFT 정보를 조회합니다 - 컬렉션 데이터 가져오기 -
fetchCollection을 사용하여 컬렉션 정보를 조회합니다 (선택 사항)
NFT와 컬렉션 데이터
자산을 가져오면 모든 데이터가 반환됩니다:
- Name - NFT의 이름
- URI - 메타데이터 JSON 링크
- Owner - NFT를 소유한 지갑
- Update Authority - NFT를 수정할 수 있는 사람
- Plugins - 로열티나 속성 같은 첨부된 플러그인
컬렉션을 가져오면 다음이 반환됩니다:
- Name - 컬렉션의 이름
- URI - 컬렉션 메타데이터 JSON 링크
- Update Authority - 컬렉션을 수정할 수 있는 사람
- Num Minted - 컬렉션 내 자산 수
- Plugins - 로열티나 속성 같은 첨부된 플러그인
