data-book="docs" ERC-1155 (EVM example) | The Root Network
Skip to content

2.30 ERC-1155 (EVM example) ​
At a glance
What it isCreate and update an SFT collection, create a token and mint, through the precompiles. Futureverse’s EVM example for The Root Network, with its README and source.
Where it sitsPart II — Building · Chapter 2.30
CoversExamples · Source files
Sourcegithub.com/futureversecom/trn-examples/tree/main/examples/evm/use-erc1155

Create and update an SFT collection, create a token and mint, through the precompiles. Reference: ERC-1155 precompile.

Copied from Futureverse’s futureversecom/trn-examples, deleted with its GitHub organisation, at commit 44c9e16 of 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) · Precompile Documentation (offline, checked 2026-10-18)

IMPORTANT

Ensure the following ENV vars are available before running the examples

2.30.1 Examples ​

bash
# change your working directory to this example first
cd examples/evm/use-erc1155

# export all required environments
export CALLER_PRIVATE_KEY=

# creates new collection
pnpm call:createCollection

# update collection info
pnpm call:updateCollection

#  create new token for a collection
pnpm call:createToken

# # update token info
pnpm call:updateToken

# mint token(s)
pnpm call:mint

2.30.2 Source files ​

src/createCollection.ts2.30.2.1 ​

ts
import { SFT_PRECOMPILE_ABI } from "@therootnetwork/evm";
import { filterTransactionEvents } from "@trne/utils/filterTransactionEvents";
import { getSFTContract } from "@trne/utils/getSFTContract";
import { withEthersProvider } from "@trne/utils/withEthersProvider";
import { ContractReceipt, utils } from "ethers";

/**
 * Use `sft.initializeCollection` to to create a new ERC-721 compatible collection.
 *
 * Assumes the caller has XRP to pay for gas.
 */
withEthersProvider("porcini", async (provider, wallet, logger) => {
	const sft = getSFTContract().connect(wallet);
	const collectionName = utils.hexlify(utils.toUtf8Bytes("MyCollection"));
	const collectionOwner = wallet.address;
	const baseUri = utils.hexlify(utils.toUtf8Bytes("https://example.com/token/"));
	const royaltyAddresses = [wallet.address];
	const royaltyEntitlements = [10_000]; // one percent

	logger.info(
		{
			parameters: {
				collectionOwner,
				collectionName,
				baseUri,
				royaltyAddresses,
				royaltyEntitlements,
			},
		},
		`create "initializeCollection" call`
	);

	logger.info(`dispatch transaction from wallet=${wallet.address}`);
	const tx = await sft.initializeCollection(
		collectionOwner,
		collectionName,
		baseUri,
		royaltyAddresses,
		royaltyEntitlements
	);
	const receipt = (await tx.wait()) as unknown as ContractReceipt;

	const [intializeEvent] = filterTransactionEvents(SFT_PRECOMPILE_ABI, receipt.logs, [
		"InitializeSftCollection",
	]);

	logger.info(
		{
			result: {
				transactionHash: receipt.transactionHash,
				blockNumber: receipt.blockNumber,
				intializeEvent: {
					name: intializeEvent.name,
					args: intializeEvent.args,
				},
			},
		},
		"receive result"
	);
});

src/createToken.ts2.30.2.2 ​

ts
import { ERC1155_PRECOMPILE_ABI } from "@therootnetwork/evm";
import { filterTransactionEvents } from "@trne/utils/filterTransactionEvents";
import { getERC1155Contract } from "@trne/utils/getERC1155Contract";
import { withEthersProvider } from "@trne/utils/withEthersProvider";
import { ContractReceipt, utils } from "ethers";

const COLLECTION_ID = 269412;

/**
 * Use `TRN1155.createToken` call to create a new token for a collection.
 *
 * Assumes the caller has XRP to pay for gas.
 */
withEthersProvider("porcini", async (provider, wallet, logger) => {
	const erc1155 = getERC1155Contract(COLLECTION_ID).connect(wallet);
	const tokenName = utils.hexlify(utils.toUtf8Bytes("MyToken"));
	const initialIssuance = 0;
	const maxIssuance = 0; // no max issuance
	const tokenOwner = wallet.address;

	logger.info(
		{
			parameters: {
				contractAddress: erc1155.address,
				tokenName,
				initialIssuance,
				maxIssuance,
				tokenOwner,
			},
		},
		`create "createToken" call`
	);

	logger.info(`dispatch transaction from wallet=${wallet.address}`);
	const tx = await erc1155.createToken(tokenName, initialIssuance, maxIssuance, tokenOwner);
	const receipt = (await tx.wait()) as unknown as ContractReceipt;

	const [setEvent] = filterTransactionEvents(ERC1155_PRECOMPILE_ABI, receipt.logs, [
		"TokenCreated",
	]);

	logger.info(
		{
			result: {
				transactionHash: receipt.transactionHash,
				blockNumber: receipt.blockNumber,
				setEvent: {
					name: setEvent.name,
					args: setEvent.args,
				},
			},
		},
		"receive result"
	);
});

src/mint.ts2.30.2.3 ​

ts
import { ERC1155_PRECOMPILE_ABI } from "@therootnetwork/evm";
import { filterTransactionEvents } from "@trne/utils/filterTransactionEvents";
import { getERC1155Contract } from "@trne/utils/getERC1155Contract";
import { withEthersProvider } from "@trne/utils/withEthersProvider";
import { ContractReceipt } from "ethers";

const COLLECTION_ID = 269412;
const TOKEN_ID = 1;

/**
 * Use `TRN1155.mint` call to mint new tokens.
 *
 * Assumes the caller has XRP to pay for gas.
 */
withEthersProvider("porcini", async (provider, wallet, logger) => {
	const erc1155 = getERC1155Contract(COLLECTION_ID).connect(wallet);
	const tokenOwner = wallet.address;
	const tokenId = TOKEN_ID;
	const amount = 10;

	logger.info(
		{
			parameters: {
				contractAddress: erc1155.address,
				tokenOwner,
				tokenId,
				amount,
			},
		},
		`create "mint" call`
	);

	logger.info(`dispatch transaction from wallet=${wallet.address}`);
	const tx = await erc1155.mint(tokenOwner, tokenId, amount);
	const receipt = (await tx.wait()) as unknown as ContractReceipt;

	const [transferEvent] = filterTransactionEvents(ERC1155_PRECOMPILE_ABI, receipt.logs, [
		"TransferSingle",
	]);

	logger.info(
		{
			result: {
				transactionHash: receipt.transactionHash,
				blockNumber: receipt.blockNumber,
				transferEvent: {
					name: transferEvent.name,
					args: transferEvent.args,
				},
			},
		},
		"receive result"
	);
});

src/updateCollection.ts2.30.2.4 ​

ts
import { ERC1155_PRECOMPILE_ABI } from "@therootnetwork/evm";
import { filterTransactionEvents } from "@trne/utils/filterTransactionEvents";
import { getERC1155Contract } from "@trne/utils/getERC1155Contract";
import { withEthersProvider } from "@trne/utils/withEthersProvider";
import { ContractReceipt, utils } from "ethers";

const COLLECTION_ID = 269412;

/**
 * Use `TRN1155.setBaseURI` call to update the collection `metadataScheme`.
 *
 * Similar extrinsics are available to update different properties of a collection
 *  - setMaxSupply
 *  Check out the precompile documentation (linked in README) for more details
 *
 * Assumes the caller is the owner of the collection, and has XRP to pay for gas.
 */
withEthersProvider("porcini", async (provider, wallet, logger) => {
	const erc1155 = getERC1155Contract(COLLECTION_ID).connect(wallet);
	const baseUri = utils.hexlify(utils.toUtf8Bytes("https://example.com/token/"));

	logger.info(
		{
			parameters: {
				contractAddress: erc1155.address,
				baseUri,
			},
		},
		`create "setBaseURI" call`
	);

	logger.info(`dispatch transaction from wallet=${wallet.address}`);
	const tx = await erc1155.setBaseURI(baseUri);
	const receipt = (await tx.wait()) as unknown as ContractReceipt;

	const [setEvent] = filterTransactionEvents(ERC1155_PRECOMPILE_ABI, receipt.logs, [
		"BaseURIUpdated",
	]);

	logger.info(
		{
			result: {
				transactionHash: receipt.transactionHash,
				blockNumber: receipt.blockNumber,
				setEvent: {
					name: setEvent.name,
					args: setEvent.args,
				},
			},
		},
		"receive result"
	);
});

package.json2.30.2.5 ​

json
{
  "scripts": {
    "call": "tsx --tsconfig ../../../tsconfig.json",
    "call:createCollection": "pnpm call src/createCollection.ts",
    "call:updateCollection": "pnpm call src/updateCollection.ts",
    "call:createToken": "pnpm call src/createToken.ts",
    "call:mint": "pnpm call src/mint.ts"
  }
}
Source: futureversecom/trn-examples, examples/evm/use-erc1155 (deleted) · commit 44c9e16, 2024-10-31 · Apache-2.0, license · part of Code examples

Associated 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 · A
See also — 609 index terms that start with A, each linked to the pages that define or use it.
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.

Curated independently and source-attributed. Not affiliated with Futureverse or TRN Labs. Sources

Curated independently and source-attributed. Not affiliated with Futureverse or TRN Labs.