2.45 NFT (Native API example) At a glance What it is Create and update an NFT collection, mint and transfer. Futureverse’s Native API example for The Root Network, with its README and source. Where it sits Part II — Building · Chapter 2.45 Covers Examples · Source files Source github.com/futureversecom/trn-examples/tree/main/examples/substrate/use-nft
| At a glance | |
|---|---|
| What it is | Create and update an NFT collection, mint and transfer. Futureverse’s Native API example for The Root Network, with its README and source. |
| Where it sits | Part II — Building · Chapter 2.45 |
| Covers | Examples · Source files |
| Source | github.com/futureversecom/trn-examples/tree/main/examples/substrate/use-nft |
Create and update an NFT collection, mint and transfer. Reference: nft pallet.
Copied from Futureverse’s
futureversecom/trn-examples, deleted with its GitHub organisation, at commit44c9e16of 2024-10-31. Apache-2.0: license. Before you run it, read Running the examples.
Offline destinations
Some places this page points to did not answer when last checked:
docs-beta.therootnetwork.com— does not resolve (checked 2026-10-18)stackblitz.com/github/futureversecom— StackBlitz loads these projects from the deleted futureversecom organisation on GitHub (checked 2026-10-18)
Run in StackBlitz (repository deleted, checked 2026-10-18) · Pallet Documentation (offline, checked 2026-10-18)
IMPORTANT
Ensure the following ENV vars are available before running the examples
CALLER_PRIVATE_KEY- Private key of an account that submits the transaction. Follow this guide to create and fund an account with some test tokens on Porcini (testnet) if you don't have one yet.
2.45.1 Examples
bash
# change your working directory to this example first
cd examples/substrate/use-nft
# export all required environments
export CALLER_PRIVATE_KEY=
# creates new collection
pnpm call:createCollection
# update collection info
pnpm call:updateCollection
# mint token(s)
pnpm call:mint
# transfer token(s)
pnpm call:transfer2.45.2 Source files
src/createCollection.ts2.45.2.1
ts
import { stringToHex } from "@polkadot/util";
import { filterExtrinsicEvents } from "@trne/utils/filterExtrinsicEvents";
import { formatEventData } from "@trne/utils/formatEventData";
import { sendExtrinsic } from "@trne/utils/sendExtrinsic";
import { withChainApi } from "@trne/utils/withChainApi";
/**
* Use `nft.createCollection` extrinsic to create a new NFT collection.
*
* Assumes the caller has XRP to pay for gas.
*/
withChainApi("porcini", async (api, caller, logger) => {
const collectionName = "MyCollection";
const initialIssuance = 0; // start from token 0
const maxIssuance = null; // no max issuance
const collectionOwner = caller.address;
const metadataScheme = stringToHex("https://example.com/token/");
const royaltiesSchedule = {
entitlements: [[collectionOwner, 10_000 /* one percent */]],
};
const crossChainCompatibility = { xrpl: false };
logger.info(
{
parameters: {
collectionName,
initialIssuance,
maxIssuance,
collectionOwner,
metadataScheme,
royaltiesSchedule,
crossChainCompatibility,
},
},
`create a "nft.createCollection" extrinsic`
);
const extrinsic = api.tx.nft.createCollection(
collectionName,
initialIssuance,
maxIssuance,
collectionOwner,
metadataScheme,
royaltiesSchedule,
crossChainCompatibility
);
logger.info(`dispatch extrinsic from caller="${caller.address}"`);
const { result, extrinsicId } = await sendExtrinsic(extrinsic, caller, { log: logger });
const [createEvent] = filterExtrinsicEvents(result.events, ["Nft.CollectionCreate"]);
logger.info(
{
result: {
extrinsicId,
blockNumber: result.blockNumber,
createEvent: formatEventData(createEvent.event),
},
},
"receive result"
);
});src/mint.ts2.45.2.2
ts
import { filterExtrinsicEvents } from "@trne/utils/filterExtrinsicEvents";
import { formatEventData } from "@trne/utils/formatEventData";
import { sendExtrinsic } from "@trne/utils/sendExtrinsic";
import { withChainApi } from "@trne/utils/withChainApi";
const COLLECTION_ID = 1124;
/**
* Use `nft.mint` extrinsic to mint new tokens.
*
* Assumes the caller is the owner of the collection, and has XRP to pay for gas.
*/
withChainApi("porcini", async (api, caller, logger) => {
const quantity = 10;
const tokenOwner = caller.address;
const collectionId = COLLECTION_ID;
logger.info(
{
parameters: {
collectionId,
quantity,
tokenOwner,
},
},
`create a "nft.mint" extrinsic`
);
const extrinsic = api.tx.nft.mint(collectionId, quantity, tokenOwner);
logger.info(`dispatch extrinsic from caller="${caller.address}"`);
const { result, extrinsicId } = await sendExtrinsic(extrinsic, caller, { log: logger });
const [mintEvent] = filterExtrinsicEvents(result.events, ["Nft.Mint"]);
logger.info(
{
result: {
extrinsicId,
blockNumber: result.blockNumber,
mintEvent: formatEventData(mintEvent.event),
},
},
"receive result"
);
});src/transfer.ts2.45.2.3
ts
import { BOB } from "@trne/utils/accounts";
import { filterExtrinsicEvents } from "@trne/utils/filterExtrinsicEvents";
import { formatEventData } from "@trne/utils/formatEventData";
import { sendExtrinsic } from "@trne/utils/sendExtrinsic";
import { withChainApi } from "@trne/utils/withChainApi";
const COLLECTION_ID = 1124;
/**
* Use `nft.transfer` extrinsic to transfer tokens to someone else.
*
* Assumes the caller is the owner of the transferring tokens, and has XRP to pay for gas.
*/
withChainApi("porcini", async (api, caller, logger) => {
const serialNumbers = [1, 2, 3];
const newOwner = BOB;
const collectionId = COLLECTION_ID;
logger.info(
{
parameters: {
collectionId,
serialNumbers,
newOwner,
},
},
`create a "nft.mint" extrinsic`
);
const extrinsic = api.tx.nft.transfer(collectionId, serialNumbers, newOwner);
logger.info(`dispatch extrinsic from caller="${caller.address}"`);
const { result, extrinsicId } = await sendExtrinsic(extrinsic, caller, { log: logger });
const [transferEvent] = filterExtrinsicEvents(result.events, ["Nft.Transfer"]);
logger.info(
{
result: {
extrinsicId,
blockNumber: result.blockNumber,
transferEvent: formatEventData(transferEvent.event),
},
},
"receive result"
);
});src/updateCollection.ts2.45.2.4
ts
import { stringToHex } from "@polkadot/util";
import { filterExtrinsicEvents } from "@trne/utils/filterExtrinsicEvents";
import { formatEventData } from "@trne/utils/formatEventData";
import { sendExtrinsic } from "@trne/utils/sendExtrinsic";
import { withChainApi } from "@trne/utils/withChainApi";
const COLLECTION_ID = 1124;
/**
* Use `nft.setBaseUri` extrinsic to update the collection `metadataScheme`.
*
* Similar extrinsics are available to update different properties of a collection
* - setMaxIssuanace
* - setName
* - setOwner
* - setRoyaltiesSchedule
* Check out the pallet documentation (linked in README) for more details
*
* Assumes the caller is the owner of the collection, and has XRP to pay for gas.
*/
withChainApi("porcini", async (api, caller, logger) => {
const collectionId = COLLECTION_ID;
const baseUri = stringToHex("https://example.com/token/");
logger.info(
{
parameters: {
collectionId,
baseUri,
},
},
`create a "nft.setBaseUri" extrinsic`
);
const extrinsic = api.tx.nft.setBaseUri(collectionId, baseUri);
logger.info(`dispatch extrinsic from caller="${caller.address}"`);
const { result, extrinsicId } = await sendExtrinsic(extrinsic, caller, { log: logger });
const [setEvent] = filterExtrinsicEvents(result.events, ["Nft.BaseUriSet"]);
logger.info(
{
result: {
extrinsicId,
blockNumber: result.blockNumber,
setEvent: formatEventData(setEvent.event),
},
},
"receive result"
);
});package.json2.45.2.5
json
{
"scripts": {
"call": "tsx --tsconfig ../../../tsconfig.json",
"call:createCollection": "pnpm call src/createCollection.ts",
"call:updateCollection": "pnpm call src/updateCollection.ts",
"call:mint": "pnpm call src/mint.ts",
"call:transfer": "pnpm call src/transfer.ts"
}
}Source:
futureversecom/trn-examples, examples/substrate/use-nft (deleted) · commit 44c9e16, 2024-10-31 · Apache-2.0, license · part of Code examplesAssociated docs
Where else you might go from here. Following one is optional — this chapter stands without them.
- Back matter — read in order
See also— The whole of Back matter as one continuous page, reprinted from its chapters without change.- Code examples
See also— Futureverse’s code examples for The Root Network: scripts for the native API and the EVM, and two contract projects, each with its README and source.- Contents
See also— Every chapter in this book, each with the one line that tells you what you get by reading it.- Front matter — read in order
See also— The whole of Front matter as one continuous page, reprinted from its chapters without change.- Guides for the code examples
See also— How Futureverse’s TRN code examples get a test account: create one in MetaMask and fund it from the Porcini faucet.- Index · B
See also— 302 index terms that start with B, each linked to the pages that define or use it.- Index · C
See also— 550 index terms that start with C, each linked to the pages that define or use it.- Index · M
See also— 492 index terms that start with M, each linked to the pages that define or use it.