A Multi-Purpose Token (MPT) lets you quickly access powerful, built-in tokenization features on the XRP Ledger with minimal code.
This tutorial shows you how to issue an MPT with on-chain metadata such as the token's ticker, name, or description, encoded according to the MPT metadata schema defined in XLS-89.
By the end of this tutorial, you will be able to:
- Issue a new MPT on the XRP Ledger.
- Encode and decode token metadata according to the XLS-89 standard.
To complete this tutorial, you should:
- Have a basic understanding of the XRP Ledger.
- Have an XRP Ledger client library set up in your development environment. This page provides examples for the following:
- JavaScript with the xrpl.js library. See Get Started Using JavaScript for setup steps.
- Python with the xrpl-py library. See Get Started Using Python for setup steps.
You can find the complete source code for this tutorial's example in the code samples section of this website's repository.
The example in this tutorial demonstrates how to issue a sample US Treasury bill (T-bill) as an MPT on the XRP Ledger.
From the code sample folder, use npm to install dependencies:
npm install xrplImport the client library, instantiate a client to connect to the XRPL, and fund a new wallet to act as the token issuer.
import {
MPTokenIssuanceCreateFlags,
Client,
encodeMPTokenMetadata,
decodeMPTokenMetadata
} from 'xrpl'
// Connect to network and get a wallet
const client = new Client('wss://s.devnet.rippletest.net:51233')
await client.connect()
console.log('=== Funding new wallet from faucet...===')
const { wallet: issuer } = await client.fundWallet()
console.log(`Issuer address: ${issuer.address}`)The ledger entry that defines an MPT issuance counts as one object towards the issuer's owner reserve, so the issuer needs to set aside 0.2 XRP per MPT issuance.
The metadata you provide is what distinguishes your token from other MPTs. Define the JSON metadata as shown in the following code snippet:
// Define metadata as JSON
const mptMetadata = {
ticker: 'TBILL',
name: 'T-Bill Yield Token',
desc: 'A yield-bearing stablecoin backed by short-term U.S. Treasuries and money market instruments.',
icon: 'https://example.org/tbill-icon.png',
asset_class: 'rwa',
asset_subclass: 'treasury',
issuer_name: 'Example Yield Co.',
uris: [
{
uri: 'https://exampleyield.co/tbill',
category: 'website',
title: 'Product Page'
},
{
uri: 'https://exampleyield.co/docs',
category: 'docs',
title: 'Yield Token Docs'
}
],
additional_info: {
interest_rate: '5.00%',
interest_type: 'variable',
yield_source: 'U.S. Treasury Bills',
maturity_date: '2045-06-30',
cusip: '912796RX0'
}
}The metadata schema supports both long field names (ticker, name, desc) and compact short keys (t, n, d). To save space on the ledger, it’s recommended to use short key names. This is because the metadata field has a 1024-byte limit, so using compact keys allows you to include more information.
The SDK libraries provide utility functions to encode or decode the metadata for you, so you don't have to. If long field names are provided in the JSON, the encoding utility function automatically shortens them to their compact key equivalents before encoding. Similarly, when decoding, the decoding utility function converts the short keys back to their respective long names.
To encode the metadata:
// Encode the metadata.
// The encodeMPTokenMetadata function shortens standard MPTokenMetadata
// field names to a compact key, then converts the JSON metadata object into a
// hex-encoded string, following the XLS-89 standard.
// https://xls.xrpl.org/xls/XLS-0089-multi-purpose-token-metadata-schema.html
console.log('\n=== Encoding metadata...===')
const mptMetadataHex = encodeMPTokenMetadata(mptMetadata)
console.log('Encoded mptMetadataHex: ', mptMetadataHex)The encoding function raises an error if the input isn't a valid JSON object.
To issue the MPT, create an MPTokenIssuanceCreate transaction object with the following fields:
| Field | Value |
|---|---|
TransactionType | The type of transaction. In this case, MPTokenIssuanceCreate. |
Account | The wallet address of the account that is issuing the MPT. In this case, the issuer. |
AssetScale | Where to put the decimal place when displaying amounts of this MPT. This is set to 4 for this example. |
MaximumAmount | The maximum supply of the token to be issued. |
TransferFee | The transfer fee to charge for transferring the token. In this example it is set to 0. |
Flags | Flags to set token permissions. For this example, the following flags are configured:
|
MPTokenMetadata | The hex-encoded metadata for the token. |
// Define the transaction, including other MPT parameters
const mptIssuanceCreate = {
TransactionType: 'MPTokenIssuanceCreate',
Account: issuer.address,
AssetScale: 4,
MaximumAmount: '50000000',
TransferFee: 0,
Flags:
MPTokenIssuanceCreateFlags.tfMPTCanTransfer |
MPTokenIssuanceCreateFlags.tfMPTCanTrade,
MPTokenMetadata: mptMetadataHex
}Some important considerations about token metadata when you submit the transaction:
If you provide metadata that exceeds the 1024-byte limit, the transaction fails with an error.
If the metadata does not conform to the XLS-89 standards, the transaction still succeeds, but your token may not be compatible with wallets and applications that expect valid MPT metadata. The SDK libraries provide a warning to help you diagnose why your metadata may not be compliant. For example:
MPTokenMetadata is not properly formatted as JSON as per the XLS-89d standard. While adherence to this standard is not mandatory, such non-compliant MPToken's might not be discoverable by Explorers and Indexers in the XRPL ecosystem. - ticker/t: should have uppercase letters (A-Z) and digits (0-9) only. Max 6 characters recommended. - name/n: should be a non-empty string. - icon/i: should be a non-empty string. - asset_class/ac: should be one of rwa, memes, wrapped, gaming, defi, other.
Sign and submit the MPTokenIssuanceCreate transaction to the ledger.
Once created, the MPT cannot be modified. Review all settings carefully before submitting the transaction. Mutable token properties are planned for a future XRPL amendment (XLS-94).
// Sign and submit the transaction
console.log('\n=== Sending MPTokenIssuanceCreate transaction...===')
console.log(JSON.stringify(mptIssuanceCreate, null, 2))
const submitResponse = await client.submitAndWait(mptIssuanceCreate, {
wallet: issuer,
autofill: true
})Verify that the transaction succeeded and retrieve the MPT issuance ID.
// Check transaction results
console.log('\n=== Checking MPTokenIssuanceCreate results... ===')
console.log(JSON.stringify(submitResponse.result, null, 2))
if (submitResponse.result.meta.TransactionResult !== 'tesSUCCESS') {
const resultCode = submitResponse.result.meta.TransactionResult
console.warn(`Transaction failed with result code ${resultCode}.`)
await client.disconnect()
process.exit(1)
}
const issuanceId = submitResponse.result.meta.mpt_issuance_id
console.log(
`\n- MPToken created successfully with issuance ID: ${issuanceId}`
)
// View the MPT issuance on the XRPL Explorer
console.log(`- Explorer URL: https://devnet.xrpl.org/mpt/${issuanceId}`)A tesSUCCESS result indicates that the transaction is successful and the token has been created.
Look up the MPT issuance entry in the validated ledger and decode the metadata to verify it matches your original input.
// Look up MPT Issuance entry in the validated ledger
console.log('\n=== Confirming MPT Issuance metadata in the validated ledger... ===')
const ledgerEntryResponse = await client.request({
command: 'ledger_entry',
mpt_issuance: issuanceId,
ledger_index: 'validated'
})
// Decode the metadata.
// The decodeMPTokenMetadata function takes a hex-encoded string representing MPT metadata,
// decodes it to a JSON object, and expands any compact field names to their full forms.
const metadataBlob = ledgerEntryResponse.result.node.MPTokenMetadata
const decodedMetadata = decodeMPTokenMetadata(metadataBlob)
console.log('Decoded MPT metadata:\n', decodedMetadata)
// Disconnect from the client
await client.disconnect()The decoding utility function converts the metadata back to a JSON object and expands the compact key names back to their respective long names.