|
1 | | -import { stringToHex } from '@xrplf/isomorphic/dist/utils/index.js' |
| 1 | +import { stringToHex, hexToString } from '@xrplf/isomorphic/dist/utils/index.js' |
2 | 2 | import { MPTokenIssuanceCreateFlags, Client } from 'xrpl' |
3 | 3 |
|
4 | 4 | // Connect to network and get a wallet |
@@ -55,13 +55,31 @@ const mpt_issuance_create = { |
55 | 55 |
|
56 | 56 | // Prepare, sign, and submit the transaction |
57 | 57 | console.log('Sending MPTokenIssuanceCreate transaction...') |
58 | | -const result = await client.submitAndWait(mpt_issuance_create, { wallet, autofill: true }) |
| 58 | +const submit_response = await client.submitAndWait(mpt_issuance_create, { wallet, autofill: true }) |
59 | 59 |
|
60 | 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}.`) |
| 61 | +console.log(JSON.stringify(submit_response, null, 2)) |
| 62 | +if (submit_response.result.meta.TransactionResult !== 'tesSUCCESS') { |
| 63 | + const result_code = response.result.meta.TransactionResult |
| 64 | + console.warn(`Transaction failed with result code ${result_code}.`) |
| 65 | + process.exit(1) |
65 | 66 | } |
66 | 67 |
|
| 68 | +const issuance_id = submit_response.result.meta.mpt_issuance_id |
| 69 | +console.log(`MPToken created successfully with issuance ID ${issuance_id}.`) |
| 70 | + |
| 71 | +// Look up MPT Issuance entry in the validated ledger |
| 72 | +console.log('Confirming MPT Issuance metadata in the validated ledger.') |
| 73 | +const ledger_entry_response = await client.request({ |
| 74 | + "command": "ledger_entry", |
| 75 | + "mpt_issuance": issuance_id, |
| 76 | + "ledger_index": "validated" |
| 77 | +}) |
| 78 | + |
| 79 | +// Decode the metadata |
| 80 | +const metadata_blob = ledger_entry_response.result.node.MPTokenMetadata |
| 81 | +const decoded_metadata = JSON.parse(hexToString(metadata_blob)) |
| 82 | +console.log('Decoded metadata:', decoded_metadata) |
| 83 | + |
| 84 | + |
67 | 85 | client.disconnect() |
0 commit comments