# Issue a Multi-Purpose Token (MPT) A [Multi-Purpose Token (MPT)](/docs/concepts/tokens/fungible-tokens/multi-purpose-tokens) 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](/docs/concepts/tokens/fungible-tokens/multi-purpose-tokens#metadata-schema) defined in [XLS-89](https://xls.xrpl.org/xls/XLS-0089-multi-purpose-token-metadata-schema.html). ## Goals 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. ## Prerequisites 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](https://github.com/XRPLF/xrpl.js). See [Get Started Using JavaScript](/docs/tutorials/javascript/build-apps/get-started) for setup steps. - **Python** with the [xrpl-py library](https://github.com/XRPLF/xrpl-py). See [Get Started Using Python](/docs/tutorials/python/build-apps/get-started) for setup steps. ## Source Code You can find the complete source code for this tutorial's example in the [code samples section of this website's repository](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/issue-mpt-with-metadata). ## Steps The example in this tutorial demonstrates how to issue a sample [US Treasury bill (T-bill)](https://www.treasurydirect.gov/research-center/history-of-marketable-securities/bills/t-bills-indepth/) as an MPT on the XRP Ledger. ### 1. Install dependencies JavaScript From the code sample folder, use npm to install dependencies: ```bash npm install xrpl ``` Python From the code sample folder, install dependencies using pip: ```bash python -m venv .venv source .venv/bin/activate pip install -r requirements.txt ``` ### 2. Set up client and account Import the client library, instantiate a client to connect to the XRPL, and fund a new wallet to act as the token issuer. JavaScript 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}`) Python import json from xrpl.utils import encode_mptoken_metadata, decode_mptoken_metadata from xrpl.clients import JsonRpcClient from xrpl.wallet import generate_faucet_wallet from xrpl.transaction import submit_and_wait from xrpl.models import LedgerEntry, MPTokenIssuanceCreate, MPTokenIssuanceCreateFlag # Set up client and get a wallet client = JsonRpcClient("https://s.devnet.rippletest.net:51234") print("=== Funding new wallet from faucet... ===") issuer = generate_faucet_wallet(client, debug=True) Note The ledger entry that defines an MPT issuance counts as one object towards the issuer's [owner reserve](/docs/concepts/accounts/reserves#owner-reserves), so the issuer needs to set aside **0.2 XRP** per MPT issuance. ### 3. Define and encode MPT metadata The metadata you provide is what distinguishes your token from other MPTs. Define the JSON metadata as shown in the following code snippet: JavaScript // 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' } } Python # Define metadata as JSON mpt_metadata = { "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: JavaScript // 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) Python # Encode the metadata. # The encode_mptoken_metadata 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 print("\n=== Encoding metadata...===") mpt_metadata_hex = encode_mptoken_metadata(mpt_metadata) print("Encoded mpt_metadata_hex:", mpt_metadata_hex) Warning The encoding function raises an error if the input isn't a valid JSON object. ### 4. Prepare the MPTokenIssuanceCreate transaction 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: **Can Transfer**: A holder can transfer the T-bill MPT to another account.**Can Trade**: A holder can trade the T-bill MPT with another account.See [MPTokenIssuanceCreate Flags](/docs/references/protocol/transactions/types/mptokenissuancecreate#mptokenissuancecreate-flags) for all available flags. | | `MPTokenMetadata` | The hex-encoded metadata for the token. | JavaScript // 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 } Python # Define the transaction, including other MPT parameters mpt_issuance_create = MPTokenIssuanceCreate( account=issuer.address, asset_scale=4, maximum_amount="50000000", transfer_fee=0, flags=MPTokenIssuanceCreateFlag.TF_MPT_CAN_TRANSFER | MPTokenIssuanceCreateFlag.TF_MPT_CAN_TRADE, mptoken_metadata=mpt_metadata_hex ) ### 5. Submit MPTokenIssuanceCreate transaction 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: ```sh 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. Warning 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](https://xls.xrpl.org/xls/XLS-0094-dynamic-MPT.html)). JavaScript // 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 }) Python # Sign and submit the transaction print("\n=== Sending MPTokenIssuanceCreate transaction...===") print(json.dumps(mpt_issuance_create.to_xrpl(), indent=2)) response = submit_and_wait(mpt_issuance_create, client, issuer, autofill=True) ### 6. Check transaction result Verify that the transaction succeeded and retrieve the MPT issuance ID. JavaScript // 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}`) Python # Check transaction results print("\n=== Checking MPTokenIssuanceCreate results... ===") print(json.dumps(response.result, indent=2)) result_code = response.result["meta"]["TransactionResult"] if result_code != "tesSUCCESS": print(f"Transaction failed with result code {result_code}.") exit(1) issuance_id = response.result["meta"]["mpt_issuance_id"] print(f"\n- MPToken created successfully with issuance ID: {issuance_id}") print(f"- Explorer URL: https://devnet.xrpl.org/mpt/{issuance_id}") A `tesSUCCESS` result indicates that the transaction is successful and the token has been created. ### 7. Confirm MPT issuance and decode metadata Look up the MPT issuance entry in the validated ledger and decode the metadata to verify it matches your original input. JavaScript // 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() Python # Look up MPT Issuance entry in the validated ledger print("\n=== Confirming MPT Issuance metadata in the validated ledger... ===") ledger_entry_response = client.request(LedgerEntry( mpt_issuance=issuance_id, ledger_index="validated" )) # Decode the metadata. # The decode_mptoken_metadata 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. metadata_blob = ledger_entry_response.result["node"]["MPTokenMetadata"] decoded_metadata = decode_mptoken_metadata(metadata_blob) print("Decoded MPT metadata:\n", json.dumps(decoded_metadata, indent=2)) The decoding utility function converts the metadata back to a JSON object and expands the compact key names back to their respective long names. ## See Also - **Concepts**: - [Multi-Purpose Tokens (MPT)](/docs/concepts/tokens/fungible-tokens/multi-purpose-tokens) - **References**: - [MPTokenIssuance entry](/docs/references/protocol/ledger-data/ledger-entry-types/mptokenissuance) - [MPTokenIssuanceCreate transaction](/docs/references/protocol/transactions/types/mptokenissuancecreate) - [MPTokenIssuanceDestroy transaction](/docs/references/protocol/transactions/types/mptokenissuancedestroy) - [MPTokenIssuanceSet transaction](/docs/references/protocol/transactions/types/mptokenissuanceset)