Features

Write Inscription Data

After initializing an inscription account data can be written to it. This is also the case for associated inscriptions.

Write Inscription Data

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

await writeData(umi, {
  inscriptionAccount: inscriptionAccount.publicKey,
  inscriptionMetadataAccount,
  authority,
  value: Buffer.from(
    '{"description": "A bread! But on-chain!", "external_url": "https://breadheads.io"}'
  ),
  associatedTag: null,
  offset: 0,
})

For larger data it is recommended to first allocate the required space, wait for that transaction to finalize and then writeData. The following example allocates data in a associated Inscription account:

Allocate space

import { allocate } from '@metaplex-foundation/mpl-inscription';
const fs = require('fs');

// Open the image file to fetch the raw bytes.
const imageBytes: Buffer = await fs.promises.readFile('test/large_bread.png')
const resizes = Math.floor(imageBytes.length / 10240) + 1
for (let i = 0; i < resizes; i += 1) {
  await allocate(umi, {
    inscriptionAccount: associatedInscriptionAccount,
    inscriptionMetadataAccount,
    associatedTag: 'image/png',
    targetSize: imageBytes.length,
  }).sendAndConfirm(umi)
}
Previous
Initialize