Skip to main content

Metadata

The Metadata extension allows for assets to have on-chain description, symbol and uri pointing to off-chain metadata, for compatibility with existing NFT standards.

The extension consists of:

Each of these fields is limited to 255 length, but their size is not fixed — data is stored on-chain only when a value is set.

Creating Metadata

The Metadata extension can be created using either the allocate, create or update instructions.

import { allocate, metadata } from '@nifty-oss/asset';

await allocate(umi, {
asset,
payer,
extension: metadata({
symbol: 'SMB',
description: 'A metadata extension',
uri: 'https://arweave.net/62Z5yOFbIeFqvoOl-aq75EAGSDzS-GxpIKC2ws5LVDc',
}),
}).sendAndConfirm(umi);

Fetching Metadata

Given an asset account, it is possible to retrieve the metadata information of an asset. Note that not all assets might have the extension, therefore it is necessary to assert if the extension was found.

import {
ExtensionType,
fetchAsset,
getExtension
} from '@nifty-oss/asset';

const asset = await fetchAsset(umi, address);
const metadata = getExtension(asset, ExtensionType.Metadata);

if (metadata) {
console.log("Symbol: " + metadata.symbol);
console.log("Description: " + metadata.description);
console.log("URI: " + metadata.uri);
}