Skip to content

ERC-1155 (EVM example) ​

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

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

Source files ​

src/createCollection.ts ​

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.ts ​

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.ts ​

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.ts ​

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.json ​

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

Curated independently. Source-attributed reference for The Root Network. Not affiliated with Futureverse / TRN Labs.