Skip to main content

Links

The Links extension represents a generic way to point to off-chain data. It consists of a list of link pairs, each of which contains a name and a uri. This can be used to point to any additional off-chain data or resources.

The Links extension can be created using either the allocate, create or update instruction.

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

await allocate(umi, {
asset,
payer,
extension: links([
{ name: 'homepage', value: 'https://nifty-oss.org' },
{ name: 'twitter', value: 'https://twitter.com/nifty_oss' }
]),
}).sendAndConfirm(umi);

Given an asset account, it is possible to retrieve the links 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 links = getExtension(asset, ExtensionType.Links);

if (links) {
links.values.forEach(({ name, uri }) => {
console.log(name + '=' + uri);
});
}