Assets (Native API example)
Transfer a fungible asset. Reference: assets 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.
Examples
bash
# change your working directory to this example first
cd examples/substrate/use-assets
# export all required environments
export CALLER_PRIVATE_KEY=
# creates new collection
pnpm call:transferSource files
src/transfer.ts
ts
import { filterExtrinsicEvents } from "@trne/utils/filterExtrinsicEvents";
import { formatEventData } from "@trne/utils/formatEventData";
import { ASTO_ASSET_ID } from "@trne/utils/porcini-assets";
import { sendExtrinsic } from "@trne/utils/sendExtrinsic";
import { withChainApi } from "@trne/utils/withChainApi";
withChainApi("porcini", async (api, caller, logger) => {
const assetId = ASTO_ASSET_ID;
const target = caller.address;
const amount = 0.1 * Math.pow(10, 18); // 0.1 ASTO
logger.info(
{
parameters: {
assetId,
target,
amount,
},
},
`create a "assets.transfer" extrinsic`
);
const extrinsic = api.tx.assets.transfer(assetId, target, amount.toString());
logger.info(`dispatch extrinsic from caller="${caller.address}"`);
const { result, extrinsicId } = await sendExtrinsic(extrinsic, caller, { log: logger });
const [transferEvent] = filterExtrinsicEvents(result.events, ["Assets.Transferred"]);
logger.info(
{
result: {
extrinsicId,
blockNumber: result.blockNumber,
transferEvent: formatEventData(transferEvent.event),
},
},
"receive result"
);
});package.json
json
{
"scripts": {
"call": "tsx --tsconfig ../../../tsconfig.json",
"call:transfer": "pnpm call src/transfer.ts"
}
}Source:
futureversecom/trn-examples, examples/substrate/use-assets (deleted) · commit 44c9e16, 2024-10-31 · Apache-2.0, license · part of Code examples