功能

获取 Core Collection

Last updated April 8, 2026

fetchCollection 通过地址从 Solana 获取 Core Collection 账户并将其反序列化为类型化对象。

Summary

fetchCollection 读取 Collection 账户并返回所有链上字段 — 名称、URI、Update Authority、插件数据和成员数量。

  • 需要合集的公钥
  • 返回包含所有链上字段的类型化 Collection 对象
  • 如果地址不是有效的 Collection 账户则抛出错误

通过地址获取 Collection

将合集的公钥传入 fetchCollection 以获取账户。

获取 Core Collection

fetch-collection.ts
import { fetchCollection } from '@metaplex-foundation/mpl-core'
import { publicKey } from '@metaplex-foundation/umi'
const collectionId = publicKey('11111111111111111111111111111111')
const collection = await fetchCollection(umi, collectionId)
console.log(collection)

Notes

  • 如果地址不存在或不是 Core Collection 账户,fetchCollection 会抛出错误
  • currentSize 反映合集中当前的 Asset 数量;numMinted 是历史总数
  • 在写入操作后验证状态,请在 sendAndConfirm 之后调用 fetchCollection

Quick Reference

项目
JS 函数fetchCollection
必填参数合集公钥
返回值Collection 对象
源码GitHub