はじめに

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)

パラメータ

取得に合わせて以下のパラメータをカスタマイズしてください:

パラメータ説明
assetAddressNFTアセットの公開鍵
collectionAddressコレクションの公開鍵(オプション)

仕組み

取得プロセスには以下の手順が含まれます:

  1. アドレスを取得 - 取得したいNFTアセットまたはコレクションの公開鍵が必要です
  2. アセットデータを取得 - fetchAssetを使用して、名前、URI、所有者、プラグインを含むNFT情報を取得します
  3. コレクションデータを取得 - fetchCollectionを使用してコレクション情報を取得します(オプション)

NFTとコレクションデータ

アセットを取得すると、すべてのデータが返されます:

  • Name - NFTの名前
  • URI - メタデータJSONへのリンク
  • Owner - NFTを所有するウォレット
  • Update Authority - NFTを変更できる人
  • Plugins - ロイヤリティや属性などの添付プラグイン

コレクションを取得すると、以下が返されます:

  • Name - コレクションの名前
  • URI - コレクションメタデータJSONへのリンク
  • Update Authority - コレクションを変更できる人
  • Num Minted - コレクション内のアセット数
  • Plugins - ロイヤリティや属性などの添付プラグイン