From 01f835c351b80b435525d55551da46ad2d2ec420 Mon Sep 17 00:00:00 2001 From: mDuo13 Date: Thu, 21 Aug 2025 14:53:24 -0700 Subject: [PATCH] MPT metadata sample code: add lookup/decoding to example --- .../js/issue-mpt-with-metadata.js | 30 +++++++++++++++---- .../py/issue-mpt-with-metadata.py | 28 +++++++++++++---- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/_code-samples/issue-mpt-with-metadata/js/issue-mpt-with-metadata.js b/_code-samples/issue-mpt-with-metadata/js/issue-mpt-with-metadata.js index fadb9ab6e4..0d693b42ce 100644 --- a/_code-samples/issue-mpt-with-metadata/js/issue-mpt-with-metadata.js +++ b/_code-samples/issue-mpt-with-metadata/js/issue-mpt-with-metadata.js @@ -1,4 +1,4 @@ -import { stringToHex } from '@xrplf/isomorphic/dist/utils/index.js' +import { stringToHex, hexToString } from '@xrplf/isomorphic/dist/utils/index.js' import { MPTokenIssuanceCreateFlags, Client } from 'xrpl' // Connect to network and get a wallet @@ -55,13 +55,31 @@ const mpt_issuance_create = { // Prepare, sign, and submit the transaction console.log('Sending MPTokenIssuanceCreate transaction...') -const result = await client.submitAndWait(mpt_issuance_create, { wallet, autofill: true }) +const submit_response = await client.submitAndWait(mpt_issuance_create, { wallet, autofill: true }) // Check transaction results and disconnect -console.log(JSON.stringify(result, null, 2)) -if (result.result.meta.TransactionResult === 'tesSUCCESS') { - const issuance_id = result.result.meta.mpt_issuance_id - console.log(`MPToken created successfully with issuance ID ${issuance_id}.`) +console.log(JSON.stringify(submit_response, null, 2)) +if (submit_response.result.meta.TransactionResult !== 'tesSUCCESS') { + const result_code = response.result.meta.TransactionResult + console.warn(`Transaction failed with result code ${result_code}.`) + process.exit(1) } +const issuance_id = submit_response.result.meta.mpt_issuance_id +console.log(`MPToken created successfully with issuance ID ${issuance_id}.`) + +// Look up MPT Issuance entry in the validated ledger +console.log('Confirming MPT Issuance metadata in the validated ledger.') +const ledger_entry_response = await client.request({ + "command": "ledger_entry", + "mpt_issuance": issuance_id, + "ledger_index": "validated" +}) + +// Decode the metadata +const metadata_blob = ledger_entry_response.result.node.MPTokenMetadata +const decoded_metadata = JSON.parse(hexToString(metadata_blob)) +console.log('Decoded metadata:', decoded_metadata) + + client.disconnect() diff --git a/_code-samples/issue-mpt-with-metadata/py/issue-mpt-with-metadata.py b/_code-samples/issue-mpt-with-metadata/py/issue-mpt-with-metadata.py index df524d5763..52f0d16139 100644 --- a/_code-samples/issue-mpt-with-metadata/py/issue-mpt-with-metadata.py +++ b/_code-samples/issue-mpt-with-metadata/py/issue-mpt-with-metadata.py @@ -1,9 +1,9 @@ import json -from xrpl.utils import str_to_hex +from xrpl.utils import str_to_hex, hex_to_str from xrpl.clients import JsonRpcClient from xrpl.wallet import generate_faucet_wallet from xrpl.transaction import submit_and_wait -from xrpl.models.transactions import MPTokenIssuanceCreate, MPTokenIssuanceCreateFlag +from xrpl.models import LedgerEntry, MPTokenIssuanceCreate, MPTokenIssuanceCreateFlag # Set up client and get a wallet client = JsonRpcClient("https://s.devnet.rippletest.net:51234") @@ -60,7 +60,23 @@ print("Sending MPTokenIssuanceCreate transaction...") response = submit_and_wait(mpt_issuance_create, client, wallet, autofill=True) print(json.dumps(response.result, indent=2)) -# Check transaction results and disconnect -if response.result["meta"]["TransactionResult"] == "tesSUCCESS": - issuance_id = response.result["meta"]["mpt_issuance_id"] - print(f"MPToken successfully created with issuance ID {issuance_id}") +# Check transaction results +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"MPToken successfully created with issuance ID {issuance_id}") + +# Look up MPT Issuance entry in the validated ledger +print("Confirming MPT Issuance metadata in the validated ledger.") +ledger_entry_response = client.request(LedgerEntry( + mpt_issuance=issuance_id, + ledger_index="validated" +)) + +# Decode the metadata +metadata_blob = ledger_entry_response.result["node"]["MPTokenMetadata"] +decoded_metadata = json.loads(hex_to_str(metadata_blob)) +print("Decoded metadata:", decoded_metadata)