Features

Fetching Inscription Data

Once Inscription Accounts are initialized their Metadata can be read from chain again. Once data is written it can also be read. To fetch inscriptions you also have to use different functions according to the inscription type.

Fetch inscription Metadata

Both inscription types use a metadata account. This Account contains for example the inscriptionRank, associatedInscriptions, updateAuthorities and more. The Metadata can be fetched like so:

Fetch Inscription Metadata

import { safeFetchInscriptionMetadataFromSeeds } from '@metaplex-foundation/mpl-inscription'

const inscriptionMetadataAccount = await safeFetchInscriptionMetadataFromSeeds(
  umi,
  {
    inscriptionAccount: inscriptionAccount.publicKey,
  }
)

console.log(inscriptionMetadataAccount)

Fetch mint inscription

To fetch the deserialized mint inscription you can use safeFetchMintInscriptionFromSeeds like so:

Fetch Mint Inscription

import { fetchInscription, safeFetchMintInscriptionFromSeeds, safeFetchInscriptionMetadataFromSeeds } from '@metaplex-foundation/mpl-inscription'

const mintInscription = await safeFetchMintInscriptionFromSeeds(umi, {
  mint,
})

const inscriptionMetadataAccount = await safeFetchInscriptionMetadataFromSeeds(
  umi,
  {
    inscriptionAccount: inscriptionAccount.publicKey,
  }
)

const associatedInscriptionAccount = findAssociatedInscriptionPda(umi, {
  associated_tag: inscriptionMetadataAccount.associatedInscriptions[0].tag,
  inscriptionMetadataAccount.publicKey,
})
const imageData = await fetchInscription(umi, associatedInscriptionAccount[0])

Fetch data inscription

To read Inscription Data that is not attached to NFTs a different function is used:

Fetch Inscription

import { fetchInscription } from '@metaplex-foundation/mpl-inscription'

const inscription = fetchInscription(umi, inscriptionAddress)

Fetch current Inscription count

The current total inscription count can be fetched like so:

Fetch current Inscription count

import {
  fetchAllInscriptionShard,
  findInscriptionShardPda,
} from '@metaplex-foundation/mpl-inscription'

const shardKeys: Pda[]
for (let shardNumber = 0; shardNumber < 32; shardNumber += 1) {
  shardKeys.push(findInscriptionShardPda(umi, { shardNumber }))
}

const shards = await fetchAllInscriptionShard(umi, shardKeys)
let numInscriptions = 0
shards.forEach((shard) => {
  const rank = 32 * Number(shard.count) + shard.shardNumber
  numInscriptions = Math.max(numInscriptions, rank)
})

console.log(`Currently there are ${numInscriptions} Metaplex Inscriptions`)
Previous
Write Data