Skip to content

Commit 6c16fa1

Browse files
committed
Add sample code for XLS-89d MPT Metadata
1 parent aec8b0f commit 6c16fa1

File tree

8 files changed

+182
-1
lines changed

8 files changed

+182
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Issue an MPT with Metadata
2+
3+
Shows how to issue a Multi-Purpose Token (MPT) with metadata encoded according to the XLS-89d schema.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Issue MPT with Metadata (JavaScript)
2+
3+
Creates a sample MPT issuance with metadata encoded as JSON according to the [XLS-89d standard](https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0089d-multi-purpose-token-metadata-schema).
4+
5+
Quick setup and usage:
6+
7+
```sh
8+
npm i
9+
node issue-mpt-with-metadata.js
10+
```
11+
12+
The script should output a validated transaction and end with a line such as the following:
13+
14+
```text
15+
MPToken created successfully with issuance ID 005073C721E14A7613BAAF5E0B1A253459832FF8D0D81278.
16+
```
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { stringToHex } from '@xrplf/isomorphic/dist/utils/index.js'
2+
import { MPTokenIssuanceCreateFlags, Client } from 'xrpl'
3+
4+
// Connect to network and get a wallet
5+
const client = new Client('wss://s.devnet.rippletest.net:51233')
6+
await client.connect()
7+
8+
console.log('Funding new wallet from faucet...')
9+
const { wallet } = await client.fundWallet()
10+
11+
// Define metadata as JSON
12+
const mpt_metadata = {
13+
ticker: 'TBILL',
14+
name: 'T-Bill Yield Token',
15+
desc: 'A yield-bearing stablecoin backed by short-term U.S. Treasuries and money market instruments.',
16+
icon: 'https://example.org/tbill-icon.png',
17+
asset_class: 'rwa',
18+
asset_subclass: 'treasury',
19+
issuer_name: 'Example Yield Co.',
20+
urls: [
21+
{
22+
url: 'https://exampleyield.co/tbill',
23+
type: 'website',
24+
title: 'Product Page'
25+
},
26+
{
27+
url: 'https://exampleyield.co/docs',
28+
type: 'docs',
29+
title: 'Yield Token Docs'
30+
}
31+
],
32+
additional_info: {
33+
interest_rate: '5.00%',
34+
interest_type: 'variable',
35+
yield_source: 'U.S. Treasury Bills',
36+
maturity_date: '2045-06-30',
37+
cusip: '912796RX0'
38+
}
39+
}
40+
41+
// Convert JSON to a string (without excess whitespace), then string to hex
42+
const mpt_metadata_hex = stringToHex(JSON.stringify(mpt_metadata))
43+
44+
// Define the transaction, including other MPT parameters
45+
const mpt_issuance_create = {
46+
TransactionType: 'MPTokenIssuanceCreate',
47+
Account: wallet.address,
48+
AssetScale: 4,
49+
MaximumAmount: '50000000',
50+
TransferFee: 0,
51+
Flags: MPTokenIssuanceCreateFlags.tfMPTCanTransfer |
52+
MPTokenIssuanceCreateFlags.tfMPTCanTrade,
53+
MPTokenMetadata: mpt_metadata_hex
54+
}
55+
56+
// Prepare, sign, and submit the transaction
57+
console.log('Sending MPTokenIssuanceCreate transaction...')
58+
const result = await client.submitAndWait(mpt_issuance_create, { wallet, autofill: true })
59+
60+
// Check transaction results and disconnect
61+
console.log(JSON.stringify(result, null, 2))
62+
if (result.result.meta.TransactionResult === 'tesSUCCESS') {
63+
const issuance_id = result.result.meta.mpt_issuance_id
64+
console.log(`MPToken created successfully with issuance ID ${issuance_id}.`)
65+
}
66+
67+
client.disconnect()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"xrpl": "^4.4.0"
4+
},
5+
"type": "module"
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Issue MPT with Metadata (Python)
2+
3+
Creates a sample MPT issuance with metadata encoded as JSON according to the [XLS-89d standard](https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0089d-multi-purpose-token-metadata-schema).
4+
5+
Quick setup and usage:
6+
7+
```sh
8+
python -m venv .venv
9+
source .venv/bin/activate
10+
pip install -r requirements.txt
11+
python issue-mpt-with-metadata.py
12+
```
13+
14+
The script should output a validated transaction and end with a line such as the following:
15+
16+
```text
17+
MPToken created successfully with issuance ID 0050773D6B8DF8C6BEA497016C8679728A217DE1C4D50AC5.
18+
```
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import json
2+
from xrpl.utils import str_to_hex
3+
from xrpl.clients import JsonRpcClient
4+
from xrpl.wallet import generate_faucet_wallet
5+
from xrpl.transaction import submit_and_wait
6+
from xrpl.models.transactions import MPTokenIssuanceCreate, MPTokenIssuanceCreateFlag
7+
8+
# Set up client and get a wallet
9+
client = JsonRpcClient("https://s.devnet.rippletest.net:51234")
10+
print("Funding new wallet from faucet...")
11+
wallet = generate_faucet_wallet(client, debug=True)
12+
13+
# Define metadata as JSON
14+
mpt_metadata = {
15+
"ticker": "TBILL",
16+
"name": "T-Bill Yield Token",
17+
"desc": "A yield-bearing stablecoin backed by short-term U.S. Treasuries and money market instruments.",
18+
"icon": "https://example.org/tbill-icon.png",
19+
"asset_class": "rwa",
20+
"asset_subclass": "treasury",
21+
"issuer_name": "Example Yield Co.",
22+
"urls": [
23+
{
24+
"url": "https://exampleyield.co/tbill",
25+
"type": "website",
26+
"title": "Product Page"
27+
},
28+
{
29+
"url": "https://exampleyield.co/docs",
30+
"type": "docs",
31+
"title": "Yield Token Docs"
32+
}
33+
],
34+
"additional_info": {
35+
"interest_rate": "5.00%",
36+
"interest_type": "variable",
37+
"yield_source": "U.S. Treasury Bills",
38+
"maturity_date": "2045-06-30",
39+
"cusip": "912796RX0"
40+
}
41+
}
42+
43+
# Convert JSON to a string (without excess whitespace), then string to hex
44+
mpt_metadata_string = json.dumps(mpt_metadata, separators=(',', ':'))
45+
mpt_metadata_hex = str_to_hex(mpt_metadata_string)
46+
47+
# Define the transaction, including other MPT parameters
48+
mpt_issuance_create = MPTokenIssuanceCreate(
49+
account=wallet.address,
50+
asset_scale=4,
51+
maximum_amount="50000000",
52+
transfer_fee=0,
53+
flags=MPTokenIssuanceCreateFlag.TF_MPT_CAN_TRANSFER |
54+
MPTokenIssuanceCreateFlag.TF_MPT_CAN_TRADE,
55+
mptoken_metadata=mpt_metadata_hex
56+
)
57+
58+
# Prepare, sign, and submit the transaction
59+
print("Sending MPTokenIssuanceCreate transaction...")
60+
response = submit_and_wait(mpt_issuance_create, client, wallet, autofill=True)
61+
print(json.dumps(response.result, indent=2))
62+
63+
# Check transaction results and disconnect
64+
if response.result["meta"]["TransactionResult"] == "tesSUCCESS":
65+
issuance_id = response.result["meta"]["mpt_issuance_id"]
66+
print(f"MPToken successfully created with issuance ID {issuance_id}")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
xrpl-py==4.3.0

docs/references/protocol/transactions/types/mptokenissuancecreate.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ This example assumes that the issuer of the token is the signer of the transacti
3939
| `AssetScale` | Number | UInt8 | No | Where to put the decimal place when displaying amounts of this MPT. More formally, the asset scale is a non-negative integer (0, 1, 2, …) such that one standard unit equals 10^(-scale) of a corresponding fractional unit. For example, if a US Dollar Stablecoin has an asset scale of _2_, then 1 unit of that MPT would equal 0.01 US Dollars. This indicates to how many decimal places the MPT can be subdivided. If omitted, the default is 0, meaning that the MPT cannot be divided into smaller than 1 unit. |
4040
| `TransferFee` | Number | UInt16 | No | The value specifies the fee to charged by the issuer for secondary sales of the Token, if such sales are allowed. Valid values for this field are between 0 and 50,000 inclusive, allowing transfer rates of between 0.000% and 50.000% in increments of 0.001. The field _must not_ be present if the tfMPTCanTransfer flag is not set. If it is, the transaction should fail and a fee should be claimed. |
4141
| `MaximumAmount` | String - Number | UInt64 | No | The maximum asset amount of this token that can ever be issued, as a base-10 number encoded as a string. The current default maximum limit is 9,223,372,036,854,775,807 (2^63-1). _This limit may increase in the future. If an upper limit is required, you must specify this field._ |
42-
| `MPTokenMetadata` | String - Hexadecimal | Blob | No | Arbitrary metadata about this issuance. The limit for this field is 1024 bytes. By convention, the metadata should decode to JSON data describing what the MPT represents. The [XLS-89d specification](https://github.com/XRPLF/XRPL-Standards/pull/293) defines a recommended format for metadata. |
42+
| `MPTokenMetadata` | String - Hexadecimal | Blob | No | Arbitrary metadata about this issuance. The limit for this field is 1024 bytes. By convention, the metadata should decode to JSON data describing what the MPT represents. The [XLS-89d specification](https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0089d-multi-purpose-token-metadata-schema) defines a recommended format for metadata. |
43+
44+
{% admonition type="success" name="Tip" %}
45+
For an example of how to encode metadata for the `MPTokenMetadata` field, see {% repo-link path="_code-samples/issue-mpt-with-metadata/" %}Code Sample: Issue MPT with Metadata{% /repo-link %}.
46+
{% /admonition %}
4347

4448
## MPTokenIssuanceCreate Flags
4549

0 commit comments

Comments
 (0)