Merge pull request #1855 from XRPLF/1788_set_minter

Fix set minter, misc
This commit is contained in:
Dennis Dawson
2023-04-03 10:39:33 -07:00
committed by GitHub
10 changed files with 1096 additions and 1516 deletions

View File

@@ -102,7 +102,7 @@ This function sets the authorized minter for an account. Each account can have 0
// **************** Set Minter ************************* // **************** Set Minter *************************
// ******************************************************* // *******************************************************
async function setMinter(type) { async function setMinter() {
``` ```
Connect to the ledger and get the account. Connect to the ledger and get the account.
@@ -111,19 +111,18 @@ Connect to the ledger and get the account.
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....' results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
await client.connect() await client.connect()
results += '\nConnected, finding wallet.' results += '\nConnected, finding wallet.'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
my_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) my_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
document.getElementById('standbyResultField').value = results standbyResultField.value = results ```
```
Define the AccountSet transaction, setting the `NFTokenMinter` account and the `asfAuthorizedNFTokenMinter` flag. Define the AccountSet transaction, setting the `NFTokenMinter` account and the `asfAuthorizedNFTokenMinter` flag.
```javascript ```javascript
tx_json = { tx_json = {
"TransactionType": "AccountSet", "TransactionType": "AccountSet",
"Account": my_wallet.address, "Account": my_wallet.address,
``` ```
@@ -143,30 +142,30 @@ Set the `asfAuthorizedNFTokenMinter` flag (the numeric value is _10_).
Report progress. Report progress.
```javascript ```javascript
results += '\n Set Minter.' results += '\nSet Minter.'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Prepare and send the transaction, then wait for results Prepare and send the transaction, then wait for results
```javascript ```javascript
const prepared = await client.autofill(tx_json) const prepared = await client.autofill(tx_json)
const signed = my_wallet.sign(prepared) const signed = my_wallet.sign(prepared)
const result = await client.submitAndWait(signed.tx_json) const result = await client.submitAndWait(signed.tx_blob)
``` ```
If the transaction succeeds, show the results. If not, report that the transaction failed. If the transaction succeeds, show the results. If not, report that the transaction failed.
```javascript ```javascript
if (result.result.meta.TransactionResult == "tesSUCCESS") { if (result.result.meta.TransactionResult == "tesSUCCESS") {
results += '\nAccount setting succeeded.' results += '\nAccount setting succeeded.\n'
results += JSON.stringify(result,null,2) results += JSON.stringify(result,null,2)
document.getElementById('standbyResultField').value = results standbyResultField.value = results
} else { } else {
throw 'Error sending transaction: ${result}' throw 'Error sending transaction: ${result}'
results += '\nAccount setting failed.' results += '\nAccount setting failed.'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
} }
``` ```
Disconnect from the XRP Ledger. Disconnect from the XRP Ledger.
@@ -193,7 +192,7 @@ Connect to the ledger and get the account.
```javascript ```javascript
results = 'Connecting to ' + getNet() + '....' results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
let net = getNet() let net = getNet()
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
@@ -203,13 +202,13 @@ Report success
```javascript ```javascript
results += '\nConnected. Minting NFToken.' results += '\nConnected. Minting NFToken.'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
This transaction blob is the same as the one used for the previous [`mintToken()` function](mint-and-burn-nftokens.html#mint-token), with the addition of the `Issuer` field. This transaction blob is the same as the one used for the previous [`mintToken()` function](mint-and-burn-nftokens.html#mint-token), with the addition of the `Issuer` field.
```javascript ```javascript
const transactionBlob = { const tx_json = {
"TransactionType": "NFTokenMint", "TransactionType": "NFTokenMint",
"Account": standby_wallet.classicAddress, "Account": standby_wallet.classicAddress,
``` ```
@@ -248,10 +247,10 @@ The `NFTokenTaxon` is an optional number field the issuer can use for their own
Submit the transaction and wait for the results. Submit the transaction and wait for the results.
```javascript ```javascript
const tx = await client.submitAndWait(transactionBlob, { wallet: standby_wallet} ) const tx = await client.submitAndWait(tx_json, { wallet: standby_wallet} )
const nfts = await client.request({ const nfts = await client.request({
method: "account_nfts", method: "account_nfts",
account: standby_wallet.classicAddress account: standby_wallet.classicAddress
}) })
``` ```
@@ -260,10 +259,9 @@ Report the results.
```javascript ```javascript
results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult
results += '\n\nnfts: ' + JSON.stringify(nfts, null, 2) results += '\n\nnfts: ' + JSON.stringify(nfts, null, 2)
document.getElementById('standbyBalanceField').value = standbyResultField.value = results + (await
(await client.getXrpBalance(standby_wallet.address)) client.getXrpBalance(standby_wallet.address))
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Disconnect from the XRP Ledger. Disconnect from the XRP Ledger.
@@ -279,19 +277,19 @@ These functions duplicate the functions of the standby account for the operation
```javascript ```javascript
// ******************************************************* // *******************************************************
// *********** Operational Set Minter ******************* // **************** Set Operational Minter **************
// ******************************************************* // ********************************************************
async function oPsetMinter(type) { async function oPsetMinter() {
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....' results = 'Connecting to ' + getNet() + '....'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
await client.connect() await client.connect()
results += '\nConnected, finding wallet.' results += '\nConnected, finding wallet.'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
my_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) my_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
document.getElementById('operationalResultField').value = results operationalResultField.value = results
tx_json = { tx_json = {
"TransactionType": "AccountSet", "TransactionType": "AccountSet",
@@ -299,24 +297,25 @@ async function oPsetMinter(type) {
"NFTokenMinter": operationalMinterField.value, "NFTokenMinter": operationalMinterField.value,
"SetFlag": xrpl.AccountSetAsfFlags.asfAuthorizedNFTokenMinter "SetFlag": xrpl.AccountSetAsfFlags.asfAuthorizedNFTokenMinter
} }
results += '\n Set Minter.' results += '\nSet Minter.'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
const prepared = await client.autofill(tx_json) const prepared = await client.autofill(tx_json)
const signed = my_wallet.sign(prepared) const signed = my_wallet.sign(prepared)
const result = await client.submitAndWait(signed.tx_json) const result = await client.submitAndWait(signed.tx_blob)
if (result.result.meta.TransactionResult == "tesSUCCESS") { if (result.result.meta.TransactionResult == "tesSUCCESS") {
results += '\nAccount setting succeeded.' results += '\nAccount setting succeeded.\n'
results += JSON.stringify(result,null,2) results += JSON.stringify(result,null,2)
document.getElementById('operationalResultField').value = results operationalResultField.value = results
} else { } else {
throw 'Error sending transaction: ${result}' throw 'Error sending transaction: ${result}'
results += '\nAccount setting failed.' results += '\nAccount setting failed.'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
} }
client.disconnect() client.disconnect()
} // End of configureAccount() } // End of oPsetMinter()
// ******************************************************* // *******************************************************
// ************** Operational Mint Other ***************** // ************** Operational Mint Other *****************
@@ -324,17 +323,17 @@ async function oPsetMinter(type) {
async function oPmintOther() { async function oPmintOther() {
results = 'Connecting to ' + getNet() + '....' results = 'Connecting to ' + getNet() + '....'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
let net = getNet() let net = getNet()
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
await client.connect() await client.connect()
results += '\nConnected. Minting NFToken.' results += '\nConnected. Minting NFToken.'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
// This version adds the "Issuer" field. // This version adds the "Issuer" field.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
const transactionBlob = { const tx_json = {
"TransactionType": 'NFTokenMint', "TransactionType": 'NFTokenMint',
"Account": operational_wallet.classicAddress, "Account": operational_wallet.classicAddress,
"URI": xrpl.convertStringToHex(operationalTokenUrlField.value), "URI": xrpl.convertStringToHex(operationalTokenUrlField.value),
@@ -345,7 +344,7 @@ async function oPmintOther() {
} }
// ----------------------------------------------------- Submit signed blob // ----------------------------------------------------- Submit signed blob
const tx = await client.submitAndWait(transactionBlob, { wallet: operational_wallet} ) const tx = await client.submitAndWait(tx_json, { wallet: operational_wallet} )
const nfts = await client.request({ const nfts = await client.request({
method: "account_nfts", method: "account_nfts",
account: operational_wallet.classicAddress account: operational_wallet.classicAddress
@@ -354,10 +353,8 @@ async function oPmintOther() {
// ------------------------------------------------------- Report results // ------------------------------------------------------- Report results
results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult
results += '\n\nnfts: ' + JSON.stringify(nfts, null, 2) results += '\n\nnfts: ' + JSON.stringify(nfts, null, 2)
document.getElementById('operationalBalanceField').value = results += await client.getXrpBalance(operational_wallet.address)
(await client.getXrpBalance(operational_wallet.address)) operationalResultField.value = results
document.getElementById('operationalResultField').value = results
client.disconnect() client.disconnect()
} //End of oPmintToken } //End of oPmintToken
``` ```
@@ -378,7 +375,7 @@ Update the form with fields and buttons to support the new functions.
button{font-weight: bold;font-family: "Work Sans", sans-serif;} button{font-weight: bold;font-family: "Work Sans", sans-serif;}
td{vertical-align: middle;} td{vertical-align: middle;}
</style> </style>
<script src='https://unpkg.com/xrpl@2.2.3'></script> <script src='https://unpkg.com/xrpl@2.7.0/build/xrpl-latest-min.js'></script>
<script src='ripplex1-send-xrp.js'></script> <script src='ripplex1-send-xrp.js'></script>
<script src='ripplex2-send-currency.js'></script> <script src='ripplex2-send-currency.js'></script>
<script src='ripplex3-mint-nfts.js'></script> <script src='ripplex3-mint-nfts.js'></script>
@@ -399,7 +396,7 @@ Update the form with fields and buttons to support the new functions.
<body> <body>
<h1>Token Test Harness</h1> <h1>Token Test Harness</h1>
<form id="theForm"> <form id="theForm">
Choose your ledger instance: Choose your ledger instance:
&nbsp;&nbsp; &nbsp;&nbsp;
<input type="radio" id="tn" name="server" <input type="radio" id="tn" name="server"
value="wss://s.altnet.rippletest.net:51233" checked> value="wss://s.altnet.rippletest.net:51233" checked>
@@ -754,8 +751,3 @@ Update the form with fields and buttons to support the new functions.
</body> </body>
</html> </html>
``` ```
| Previous | Next |
| :--- | ---: |
| [← Broker a NFToken Sale >](broker-sale.html) | [Batch Mint NFTokens → >](batch-minting.html) |

View File

@@ -15,6 +15,8 @@ You can create an application that mints multiple NFTokens at one time. You can
A best practice is to use `Tickets` to reserve the transaction sequence numbers. If you create an application that creates NFTokens without using tickets, if any transaction fails for any reason, the application stops with an error. If you use tickets, the application continues to send transactions, and you can look into the reason for the failure afterward. A best practice is to use `Tickets` to reserve the transaction sequence numbers. If you create an application that creates NFTokens without using tickets, if any transaction fails for any reason, the application stops with an error. If you use tickets, the application continues to send transactions, and you can look into the reason for the failure afterward.
[![Batch Mint](img/quickstart33-batch-mint.png)](img/quickstart33-batch-mint.png)
## Usage ## Usage
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try the sample in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try the sample in your own browser.
@@ -66,16 +68,16 @@ async function getAccountFromSeed() {
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....' results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
await client.connect() await client.connect()
results += '\nConnected, finding wallets.\n' results += '\nConnected, finding wallets.\n'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Use the seed to derive the account. Use the seed to derive the account.
```javascript ```javascript
var theSeed = document.getElementById('seeds').value var theSeed = seeds.value
const standby_wallet = xrpl.Wallet.fromSeed(theSeed) const standby_wallet = xrpl.Wallet.fromSeed(theSeed)
``` ```
@@ -88,12 +90,11 @@ Get the current XRP balance.
Populate the fields for Standby account. Populate the fields for Standby account.
```javascript ```javascript
document.getElementById('standbyAccountField').value = standby_wallet.address standbyAccountField.value = standby_wallet.address
document.getElementById('standbyPubKeyField').value = standby_wallet.publicKey standbyPubKeyField.value = standby_wallet.publicKey
document.getElementById('standbyPrivKeyField').value = standby_wallet.privateKey standbyPrivKeyField.value = standby_wallet.privateKey
document.getElementById('standbySeedField').value = standby_wallet.seed standbySeedField.value = standby_wallet.seed
document.getElementById('standbyBalanceField').value = standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
(await client.getXrpBalance(standby_wallet.address))
``` ```
Disconnect from the XRP Ledger. Disconnect from the XRP Ledger.
@@ -108,6 +109,10 @@ Disconnect from the XRP Ledger.
This version of `getTokens()` allows for a larger set of NFTokens by watching for a `marker` at the end of each batch of NFTokens. This version of `getTokens()` allows for a larger set of NFTokens by watching for a `marker` at the end of each batch of NFTokens.
```javascript ```javascript
// *******************************************************
// **************** Get Batch Tokens *********************
// *******************************************************
async function getBatchNFTokens() { async function getBatchNFTokens() {
``` ```
@@ -118,10 +123,10 @@ Connect to the XRP Ledger and get the account.
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...' results = 'Connecting to ' + net + '...'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
await client.connect() await client.connect()
results += '\nConnected. Getting NFTokens...' results += '\nConnected. Getting NFTokens...'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Request the `account_nfts`. Set the `limit` to 400, the maximum amount, to retrieve up to 400 records in one batch. Request the `account_nfts`. Set the `limit` to 400, the maximum amount, to retrieve up to 400 records in one batch.
@@ -142,10 +147,10 @@ If the list of `NFTokens` exceeds your limit, the result includes a `marker` fie
while (nfts.result.marker) while (nfts.result.marker)
{ {
nfts = await client.request({ nfts = await client.request({
method: "account_nfts", method: "account_nfts",
account: standby_wallet.classicAddress, account: standby_wallet.classicAddress,
limit: 400, limit: 400,
marker: nfts.result.marker marker: nfts.result.marker
}) })
results += '\n' + JSON.stringify(nfts,null,2) results += '\n' + JSON.stringify(nfts,null,2)
} }
@@ -154,7 +159,7 @@ If the list of `NFTokens` exceeds your limit, the result includes a `marker` fie
Report the final results. Report the final results.
```javascript ```javascript
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Disconnect from the XRP Ledger. Disconnect from the XRP Ledger.
@@ -169,6 +174,10 @@ Disconnect from the XRP Ledger.
This script mints multiple copies of the same NFToken. This script mints multiple copies of the same NFToken.
```javascript ```javascript
// *******************************************************
// ****************** Batch Mint ***********************
// *******************************************************
async function batchMint() { async function batchMint() {
``` ```
@@ -178,12 +187,12 @@ Connect to the XRP Ledger and get the account.
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....' results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
await client.connect() await client.connect()
results += '\nConnected, finding wallet.' results += '\nConnected, finding wallet.'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Get the account information, particularly the `Sequence` number. Get the account information, particularly the `Sequence` number.
@@ -196,7 +205,7 @@ Get the account information, particularly the `Sequence` number.
my_sequence = account_info.result.account_data.Sequence my_sequence = account_info.result.account_data.Sequence
results += "\n\nSequence Number: " + my_sequence + "\n\n" results += "\n\nSequence Number: " + my_sequence + "\n\n"
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Next, create ticket numbers for the batch. Without tickets, if one transaction fails, all others in the batch fail. With tickets, there can be failures, but the rest can still succeed, and you can investigate any problems afterward. Next, create ticket numbers for the batch. Without tickets, if one transaction fails, all others in the batch fail. With tickets, there can be failures, but the rest can still succeed, and you can investigate any problems afterward.
@@ -249,7 +258,7 @@ Report the function progress.
```javascript ```javascript
results += "Tickets generated, minting NFTokens.\n\n" results += "Tickets generated, minting NFTokens.\n\n"
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Use a `for` loop to create the NFTokens one at a time, up to the number you specified. Use a `for` loop to create the NFTokens one at a time, up to the number you specified.
@@ -292,7 +301,7 @@ Use the same logic as `getBatchNFTokens`, above, to get the list of current NFTo
}) })
results += JSON.stringify(nfts,null,2) results += JSON.stringify(nfts,null,2)
while (nfts.result.marker != null) while (nfts.result.marker)
{ {
nfts = await client.request({ nfts = await client.request({
method: "account_nfts", method: "account_nfts",
@@ -309,9 +318,8 @@ Report the results.
```javascript ```javascript
results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult
results += '\n\nnftokens: ' + JSON.stringify(nfts, null, 2) results += '\n\nnftokens: ' + JSON.stringify(nfts, null, 2)
document.getElementById('standbyBalanceField').value = standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
(await client.getXrpBalance(standby_wallet.address)) standbyResultField.value = results
document.getElementById('standbyResultField').value = results
``` ```
Disconnect from the XRP Ledger. Disconnect from the XRP Ledger.
@@ -340,7 +348,7 @@ For this form:
button{font-weight: bold;font-family: "Work Sans", sans-serif;} button{font-weight: bold;font-family: "Work Sans", sans-serif;}
td{vertical-align: middle;} td{vertical-align: middle;}
</style> </style>
<script src='https://unpkg.com/xrpl@2.2.3'></script> <script src='https://unpkg.com/xrpl@2.7.0/build/xrpl-latest-min.js'></script>
<script src='ripplex1-send-xrp.js'></script> <script src='ripplex1-send-xrp.js'></script>
<script src='ripplex3-mint-nfts.js'></script> <script src='ripplex3-mint-nfts.js'></script>
<script src='ripplex7-batch-minting.js'></script> <script src='ripplex7-batch-minting.js'></script>
@@ -359,7 +367,7 @@ For this form:
<body> <body>
<h1>Token Test Harness</h1> <h1>Token Test Harness</h1>
<form id="theForm"> <form id="theForm">
Choose your ledger instance: Choose your ledger instance:
&nbsp;&nbsp; &nbsp;&nbsp;
<input type="radio" id="tn" name="server" <input type="radio" id="tn" name="server"
value="wss://s.altnet.rippletest.net:51233" checked> value="wss://s.altnet.rippletest.net:51233" checked>
@@ -455,37 +463,35 @@ For this form:
<tr> <tr>
<td align="right"> <td align="right">
NFToken Count NFToken Count
</td> </td>
<td> <td>
<input type="text" id="standbyNFTokenCountField" size="40"></input> <input type="text" id="standbyNFTokenCountField" size="40"></input>
<br> <br>
</td> </td>
</tr> </tr>
<tr> <tr>
<td align="right">Transfer Fee</td> <td align="right">Transfer Fee</td>
<td><input type="text" id="standbyTransferFeeField" value="" size="80"/></td> <td><input type="text" id="standbyTransferFeeField" value="" size="80"/></td>
</tr> </tr>
</td> </td>
</tr>
</table>
</td>
<td align="left" valign="top">
<button type="button" onClick="batchMint()">Batch Mint</button>
<br/>
<button type="button" onClick="getBatchNFTokens()">Get Batch NFTokens</button>
<br/>
<p align="left">
<textarea id="standbyResultField" cols="80" rows="20" maxlength="524288"></textarea>
</p>
</td>
</tr> </tr>
</table> </table>
</td>
<td align="left" valign="top">
<button type="button" onClick="batchMint()">Batch Mint</button>
<br/>
<button type="button" onClick="getBatchNFTokens()">Get Batch NFTokens</button>
<br/>
<p align="left">
<!-- Note the increased maxlength to hold the most possible NFToken info. -->
<textarea id="standbyResultField" cols="80" rows="20" maxlength="524288"></textarea>
</p>
</td>
</tr>
</table>
</form> </form>
</body> </body>
</html> </html>
``` ```
| Previous | Next |
| :--- | ---: |
| [← Authorize Minter >](authorize-minter.html) | |

View File

@@ -21,7 +21,7 @@ This example shows how to:
2. Get a list of offers for the brokered item. 2. Get a list of offers for the brokered item.
3. Broker a sale between two different accounts. 3. Broker a sale between two different accounts.
![Quickstart form with Broker Account](img/quickstart21.png) [![Quickstart form with Broker Account](img/quickstart21.png)](img/quickstart21.png)
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser.
@@ -38,7 +38,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
2. Click **Get New Operational Account**. 2. Click **Get New Operational Account**.
3. Click **Get New Broker Account** 3. Click **Get New Broker Account**
![Quickstart form with Account Information](img/quickstart22.png) [![Quickstart form with Account Information](img/quickstart22.png)](img/quickstart22.png)
## Prepare a Brokered Transaction ## Prepare a Brokered Transaction
@@ -51,7 +51,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
6. Click **Create Sell Offer**. 6. Click **Create Sell Offer**.
![Sell Offer with Destination](img/quickstart23.png) [![Sell Offer with Destination](img/quickstart23.png)](img/quickstart23.png)
2. Use the Operational account to create a NFToken Buy Offer. 2. Use the Operational account to create a NFToken Buy Offer.
1. Enter the **Amount** of your offer. 1. Enter the **Amount** of your offer.
@@ -60,14 +60,14 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
4. Optionally enter the number of days until **Expiration**. 4. Optionally enter the number of days until **Expiration**.
5. Click **Create Buy Offer**. 5. Click **Create Buy Offer**.
![Buy Offer](img/quickstart24.png) [![Buy Offer](img/quickstart24.png)](img/quickstart24.png)
## Get Offers ## Get Offers
1. Enter the **NFToken ID**. 1. Enter the **NFToken ID**.
2. Click **Get Offers**. 2. Click **Get Offers**.
![Get Offers](img/quickstart25.png) [![Get Offers](img/quickstart25.png)](img/quickstart25.png)
## Broker the Sale ## Broker the Sale
@@ -76,7 +76,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
3. Enter a **Broker Fee**, in drops. 3. Enter a **Broker Fee**, in drops.
4. Click **Broker Sale**. 4. Click **Broker Sale**.
![Brokered Sale](img/quickstart26.png) [![Brokered Sale](img/quickstart26.png)](img/quickstart26.png)
## Cancel Offer ## Cancel Offer
@@ -86,7 +86,7 @@ After accepting a buy offer, a best practice for the broker is to cancel all oth
1. Enter the _nft_offer_index_ of the buy offer you want to cancel in the **Buy NFToken Offer Index** field. 1. Enter the _nft_offer_index_ of the buy offer you want to cancel in the **Buy NFToken Offer Index** field.
2. Click **Cancel Offer**. 2. Click **Cancel Offer**.
![Cancel Offer](img/quickstart27.png) [![Cancel Offer](img/quickstart27.png)](img/quickstart27.png)
# Code Walkthrough # Code Walkthrough
@@ -99,26 +99,29 @@ This script has new functions for brokered transactions and revised functions to
## Broker Get Offers ## Broker Get Offers
``` ```javascript
// *******************************************************
// *************** Broker Get Offers *********************
// *******************************************************
async function brGetOffers() { async function brGetOffers() {
``` ```
Connect to the ledger. Connect to the ledger.
``` ```javascript
const standby_wallet = xrpl.Wallet.fromSeed(brokerSeedField.value)
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '...' results = 'Connecting to ' + getNet() + '...'
document.getElementById('brokerResultField').value = results brokerResultField.value = results
await client.connect() await client.connect()
results += '\nConnected. Getting offers...' results += '\nConnected. Getting offers...'
document.getElementById('brokerResultField').value = results brokerResultField.value = results
``` ```
Request the list of sell offers for the token. Request the list of sell offers for the token.
``` ```javascript
results += '\n\n***Sell Offers***\n' results += '\n\n***Sell Offers***\n'
let nftSellOffers let nftSellOffers
try { try {
@@ -130,57 +133,57 @@ Request the list of sell offers for the token.
nftSellOffers = 'No sell offers.' nftSellOffers = 'No sell offers.'
} }
results += JSON.stringify(nftSellOffers,null,2) results += JSON.stringify(nftSellOffers,null,2)
document.getElementById('brokerResultField').value = results brokerResultField.value = results
``` ```
Request the list of buy offers for the token. Request the list of buy offers for the token.
``` ```javascript
results += '\n\n***Buy Offers***\n' results += '\n\n***Buy Offers***\n'
let nftBuyOffers let nftBuyOffers
try { try {
nftBuyOffers = await client.request({ nftBuyOffers = await client.request({
method: "nft_buy_offers", method: "nft_buy_offers",
nft_id: brokerTokenIdField.value }) nft_id: brokerTokenIdField.value
} catch (err) { })
} catch (err) {
nftBuyOffers = 'No buy offers.' nftBuyOffers = 'No buy offers.'
} }
results += JSON.stringify(nftBuyOffers,null,2) results += JSON.stringify(nftBuyOffers,null,2)
brokerResultField.value = results
document.getElementById('brokerResultField').value = results
``` ```
Disconnect from the ledger. Disconnect from the ledger.
``` ```javascript
client.disconnect() client.disconnect()
}// End of brGetOffers() }// End of brGetOffers()
``` ```
## Broker Sale ## Broker Sale
``` ```javascript
async function brokerSale() { async function brokerSale() {
``` ```
Connect to the ledger and get the accounts. Connect to the ledger and get the accounts.
``` ```javascript
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
const broker_wallet = xrpl.Wallet.fromSeed (brokerSeedField.value) const broker_wallet = xrpl.Wallet.fromSeed (brokerSeedField.value)
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '...' results = 'Connecting to ' + getNet() + '...'
document.getElementById('brokerResultField').value = results brokerResultField.value = results
await client.connect() await client.connect()
results += '\nConnected. Brokering sale...' results += '\nConnected. Brokering sale...'
document.getElementById('brokerResultField').value = results brokerResultField.value = results
``` ```
Prepare the transaction. The difference between a brokered sale and a direct sale is that you provide both a sell offer and a buy offer, with an agreed-upon broker's fee. Prepare the transaction. The difference between a brokered sale and a direct sale is that you provide both a sell offer and a buy offer, with an agreed-upon broker's fee.
``` ```javascript
const transactionBlob = { const transactionBlob = {
"TransactionType": "NFTokenAcceptOffer", "TransactionType": "NFTokenAcceptOffer",
"Account": broker_wallet.classicAddress, "Account": broker_wallet.classicAddress,
@@ -192,61 +195,63 @@ Prepare the transaction. The difference between a brokered sale and a direct sal
Submit the transaction and wait for the results. Submit the transaction and wait for the results.
``` ```javascript
const tx = await client.submitAndWait(transactionBlob,{wallet: broker_wallet}) const tx = await client.submitAndWait(transactionBlob,{wallet: broker_wallet})
``` ```
Report the results. Report the results.
``` ```javascript
results += "\n\nTransaction result:\n" + results += "\n\nTransaction result:\n" +
JSON.stringify(tx.result.meta.TransactionResult, null, 2) JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += "\nBalance changes:\n" + results += "\nBalance changes:\n" +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
document.getElementById('operationalBalanceField').value = operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
(await client.getXrpBalance(operational_wallet.address)) standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
document.getElementById('standbyBalanceField').value = brokerBalanceField.value = (await client.getXrpBalance(broker_wallet.address))
(await client.getXrpBalance(standby_wallet.address)) brokerResultField.value = results
document.getElementById('brokerBalanceField').value =
(await client.getXrpBalance(broker_wallet.address))
document.getElementById('brokerResultField').value = results
``` ```
Disconnect from the ledger. Disconnect from the ledger.
``` ```javascript
client.disconnect() client.disconnect()
}// End of brokerSale() }// End of brokerSale()
``` ```
## Broker Cancel Offer ## Broker Cancel Offer
``` ```javascript
// *******************************************************
// ************* Broker Cancel Offer ****************
// *******************************************************
async function brCancelOffer() { async function brCancelOffer() {
``` ```
Get the broker account and connect to the ledger. Get the broker account and connect to the ledger.
``` ```javascript
const wallet = xrpl.Wallet.fromSeed(brokerSeedField.value) const wallet = xrpl.Wallet.fromSeed(brokerSeedField.value)
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...' results = 'Connecting to ' + getNet() + '...'
document.getElementById('brokerResultField').value = results brokerResultField.value = results
await client.connect() await client.connect()
results += "\nConnected. Cancelling offer..." results += "\nConnected. Cancelling offer..."
document.getElementById('brokerResultField').value = results brokerResultField.value = results
``` ```
The Token ID must be converted to an array. The Token ID must be converted to an array.
``` ```javascript
const tokenOfferIDs = [brokerTokenBuyOfferIndexField.value] const tokenOfferIDs = [brokerTokenBuyOfferIndexField.value]
``` ```
Prepare the transaction. Prepare the transaction.
``` ```javascript
const transactionBlob = { const transactionBlob = {
"TransactionType": "NFTokenCancelOffer", "TransactionType": "NFTokenCancelOffer",
"Account": wallet.classicAddress, "Account": wallet.classicAddress,
@@ -256,13 +261,13 @@ Prepare the transaction.
Submit the transaction and wait for the results. Submit the transaction and wait for the results.
``` ```javascript
const tx = await client.submitAndWait(transactionBlob,{wallet}) const tx = await client.submitAndWait(transactionBlob,{wallet})
``` ```
Get the sell offers and report the results. Get the sell offers and report the results.
``` ```javascript
results += "\n\n***Sell Offers***\n" results += "\n\n***Sell Offers***\n"
let nftSellOffers let nftSellOffers
try { try {
@@ -278,7 +283,7 @@ Get the sell offers and report the results.
Get the buy offers and report the results. Get the buy offers and report the results.
``` ```javascript
results += "\n\n***Buy Offers***\n" results += "\n\n***Buy Offers***\n"
let nftBuyOffers let nftBuyOffers
try { try {
@@ -293,7 +298,7 @@ Get the buy offers and report the results.
Report the transaction results. Report the transaction results.
``` ```javascript
results += "\nTransaction result:\n" + results += "\nTransaction result:\n" +
JSON.stringify(tx.result.meta.TransactionResult, null, 2) JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += "\nBalance changes:\n" + results += "\nBalance changes:\n" +
@@ -303,7 +308,7 @@ Report the transaction results.
Disconnect from the ledger. Disconnect from the ledger.
``` ```javascript
client.disconnect() client.disconnect()
}// End of brCancelOffer() }// End of brCancelOffer()
``` ```
@@ -311,13 +316,22 @@ Disconnect from the ledger.
To accommodate the broker account, override the `getAccount(type)` function to watch for the _broker_ type. To accommodate the broker account, override the `getAccount(type)` function to watch for the _broker_ type.
``` ```javascript
// ***************************************************************************
// ************** Revised Functions ******************************************
// ***************************************************************************
// *******************************************************
// ************* Get Account *****************************
// *******************************************************
async function getAccount(type) { async function getAccount(type) {
``` ```
Connect to the ledger. Connect to the ledger.
``` ```javascript
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '....' results = 'Connecting to ' + net + '....'
@@ -325,105 +339,105 @@ Connect to the ledger.
Get the correct network host. Get the correct network host.
``` ```javascript
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '....'
let faucetHost = null let faucetHost = null
if (type == 'standby') { if (type == 'standby') {
document.getElementById('standbyResultField').value = results standbyResultField.value = results
} }
if (type == 'operational') { if (type == 'operational') {
document.getElementById('operationalResultField').value = results operationalResultField.value = results
} }
if (type == 'broker') { if (type == 'broker') {
document.getElementById('brokerResultField').value = results brokerResultField.value = results
} }
``` ```
Connect to the ledger. Connect to the ledger.
``` ```javascript
await client.connect() await client.connect()
results += '\nConnected, funding wallet.' results += '\nConnected, funding wallet.'
if (type == 'standby') { if (type == 'standby') {
document.getElementById('standbyResultField').value = results standbyResultField.value = results
} }
if (type == 'operational') { if (type == 'operational') {
document.getElementById('operationalResultField').value = results operationalResultField.value = results
} }
if (type == 'broker') { if (type == 'broker') {
document.getElementById('brokerResultField').value = results brokerResultField.value = results
} }
``` ```
Create and fund a test account and report progress. Create and fund a test account and report progress.
``` ```javascript
const my_wallet = (await client.fundWallet(null, { faucetHost })).wallet const my_wallet = (await client.fundWallet(null, { faucetHost })).wallet
results += '\nGot a wallet.' results += '\nGot a wallet.'
if (type == 'standby') { if (type == 'standby') {
document.getElementById('standbyResultField').value = results standbyResultField.value = results
} }
if (type == 'operational') { if (type == 'operational') {
document.getElementById('operationalResultField').value = results operationalResultField.value = results
} }
if (type == 'broker') { if (type == 'broker') {
document.getElementById('brokerResultField').value = results brokerResultField.value = results
} }
``` ```
Get the XRP balance for the new account. Get the XRP balance for the new account.
``` ```javascript
const my_balance = (await client.getXrpBalance(my_wallet.address)) const my_balance = (await client.getXrpBalance(my_wallet.address))
``` ```
Populate the form fields for the appropriate account with the new account information. Populate the form fields for the appropriate account with the new account information.
``` ```javascript
if (type == 'standby') { if (type == 'standby') {
document.getElementById('standbyAccountField').value = my_wallet.address standbyAccountField.value = my_wallet.address
document.getElementById('standbyPubKeyField').value = my_wallet.publicKey standbyPubKeyField.value = my_wallet.publicKey
document.getElementById('standbyPrivKeyField').value = my_wallet.privateKey standbyPrivKeyField.value = my_wallet.privateKey
document.getElementById('standbyBalanceField').value = standbyBalanceField.value = (await client.getXrpBalance(my_wallet.address))
(await client.getXrpBalance(my_wallet.address)) standbySeedField.value = my_wallet.seed
document.getElementById('standbySeedField').value = my_wallet.seed
results += '\nStandby account created.' results += '\nStandby account created.'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
} }
if (type == 'operational') { if (type == 'operational') {
document.getElementById('operationalAccountField').value = my_wallet.address operationalAccountField.value = my_wallet.address
document.getElementById('operationalPubKeyField').value = my_wallet.publicKey operationalPubKeyField.value = my_wallet.publicKey
document.getElementById('operationalPrivKeyField').value = my_wallet.privateKey operationalPrivKeyField.value = my_wallet.privateKey
document.getElementById('operationalSeedField').value = my_wallet.seed operationalSeedField.value = my_wallet.seed
document.getElementById('operationalBalanceField').value = operationalBalanceField.value = (await client.getXrpBalance(my_wallet.address))
(await client.getXrpBalance(my_wallet.address))
results += '\nOperational account created.' results += '\nOperational account created.'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
} }
if (type == 'broker') { if (type == 'broker') {
document.getElementById('brokerAccountField').value = my_wallet.address brokerAccountField.value = my_wallet.address
document.getElementById('brokerPubKeyField').value = my_wallet.publicKey brokerPubKeyField.value = my_wallet.publicKey
document.getElementById('brokerPrivKeyField').value = my_wallet.privateKey brokerPrivKeyField.value = my_wallet.privateKey
document.getElementById('brokerSeedField').value = my_wallet.seed brokerSeedField.value = my_wallet.seed
document.getElementById('brokerBalanceField').value = brokerBalanceField.value = (await client.getXrpBalance(my_wallet.address))
(await client.getXrpBalance(my_wallet.address))
results += '\nBroker account created.' results += '\nBroker account created.'
document.getElementById('brokerResultField').value = results brokerResultField.value = results
} }
``` ```
Add the new account seed to corresponding line in the **Account Seeds** field. Add the new account seed to corresponding line in the **Account Seeds** field.
``` ```javascript
document.getElementById('seeds').value = standbySeedField.value + '\n' + operationalSeedField.value + "\n" + brokerSeedField.value seeds.value = standbySeedField.value + '\n' + operationalSeedField.value + "\n" +
brokerSeedField.value
``` ```
Disconnect from the ledger. Disconnect from the ledger.
``` ```javascript
client.disconnect() client.disconnect()
} // End of getAccount() } // End of getAccount()
``` ```
@@ -432,31 +446,31 @@ Disconnect from the ledger.
Override the `getAccountsFromSeeds()` function to include the broker account fields. Override the `getAccountsFromSeeds()` function to include the broker account fields.
``` ```javascript
async function getAccountsFromSeeds() { async function getAccountsFromSeeds() {
``` ```
Connect to the ledger. Connect to the ledger.
``` ```javascript
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....' results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
await client.connect() await client.connect()
results += '\nConnected, finding wallets.\n' results += '\nConnected, finding wallets.\n'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Use the `split` function to parse the values from the **Seeds** field. Use the `split` function to parse the values from the **Seeds** field.
``` ```javascript
var lines = seeds.value.split('\n'); var lines = seeds.value.split('\n');
``` ```
Derive the accounts from the seed values. Derive the accounts from the seed values.
``` ```javascript
const standby_wallet = xrpl.Wallet.fromSeed(lines[0]) const standby_wallet = xrpl.Wallet.fromSeed(lines[0])
const operational_wallet = xrpl.Wallet.fromSeed(lines[1]) const operational_wallet = xrpl.Wallet.fromSeed(lines[1])
const broker_wallet = xrpl.Wallet.fromSeed(lines[2]) const broker_wallet = xrpl.Wallet.fromSeed(lines[2])
@@ -464,7 +478,7 @@ Derive the accounts from the seed values.
Get the XRP balances for the accounts. Get the XRP balances for the accounts.
``` ```javascript
const standby_balance = (await client.getXrpBalance(standby_wallet.address)) const standby_balance = (await client.getXrpBalance(standby_wallet.address))
const operational_balance = (await client.getXrpBalance(operational_wallet.address)) const operational_balance = (await client.getXrpBalance(operational_wallet.address))
const broker_balance = (await client.getXrpBalance(broker_wallet.address)) const broker_balance = (await client.getXrpBalance(broker_wallet.address))
@@ -472,38 +486,35 @@ Get the XRP balances for the accounts.
Populate the form fields based on the account values. Populate the form fields based on the account values.
``` ```javascript
document.getElementById('standbyAccountField').value = standby_wallet.address standbyAccountField.value = standby_wallet.address
document.getElementById('standbyPubKeyField').value = standby_wallet.publicKey standbyPubKeyField.value = standby_wallet.publicKey
document.getElementById('standbyPrivKeyField').value = standby_wallet.privateKey standbyPrivKeyField.value = standby_wallet.privateKey
document.getElementById('standbySeedField').value = standby_wallet.seed standbySeedField.value = standby_wallet.seed
document.getElementById('standbyBalanceField').value = standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
(await client.getXrpBalance(standby_wallet.address))
document.getElementById('operationalAccountField').value = operational_wallet.address operationalAccountField.value = operational_wallet.address
document.getElementById('operationalPubKeyField').value = operational_wallet.publicKey operationalPubKeyField.value = operational_wallet.publicKey
document.getElementById('operationalPrivKeyField').value = operational_wallet.privateKey operationalPrivKeyField.value = operational_wallet.privateKey
document.getElementById('operationalSeedField').value = operational_wallet.seed operationalSeedField.value = operational_wallet.seed
document.getElementById('operationalBalanceField').value = operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
(await client.getXrpBalance(operational_wallet.address))
document.getElementById('brokerAccountField').value = broker_wallet.address brokerAccountField.value = broker_wallet.address
document.getElementById('brokerPubKeyField').value = broker_wallet.publicKey brokerPubKeyField.value = broker_wallet.publicKey
document.getElementById('brokerPrivKeyField').value = broker_wallet.privateKey brokerPrivKeyField.value = broker_wallet.privateKey
document.getElementById('brokerSeedField').value = broker_wallet.seed brokerSeedField.value = broker_wallet.seed
document.getElementById('brokerBalanceField').value = brokerBalanceField.value = (await client.getXrpBalance(broker_wallet.address))
(await client.getXrpBalance(broker_wallet.address))
``` ```
Disconnect from the ledger. Disconnect from the ledger.
``` ```javascript
client.disconnect() client.disconnect()
``` ```
Use the `getBalances()` function to get the current balances of fiat currency. Use the `getBalances()` function to get the current balances of fiat currency.
``` ```javascript
getBalances() getBalances()
} // End of getAccountsFromSeeds() } // End of getAccountsFromSeeds()
@@ -513,13 +524,17 @@ Use the `getBalances()` function to get the current balances of fiat currency.
Override the `getBalances()` function to include the broker balance. Override the `getBalances()` function to include the broker balance.
``` ```javascript
// *******************************************************
// ****************** Get Balances ***********************
// *******************************************************
async function getBalances() { async function getBalances() {
``` ```
Connect with the ledger. Connect with the ledger.
``` ```javascript
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....' results = 'Connecting to ' + getNet() + '....'
@@ -533,7 +548,7 @@ Connect with the ledger.
Derive each of the three accounts. Derive each of the three accounts.
``` ```javascript
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
const broker_wallet = xrpl.Wallet.fromSeed(brokerSeedField.value) const broker_wallet = xrpl.Wallet.fromSeed(brokerSeedField.value)
@@ -541,8 +556,8 @@ Derive each of the three accounts.
Get and report the Standby account balances. Get and report the Standby account balances.
``` ```javascript
results= "\nGetting standby account balances...\n" results = "\nGetting standby account balances...\n"
const standby_balances = await client.request({ const standby_balances = await client.request({
command: "gateway_balances", command: "gateway_balances",
account: standby_wallet.address, account: standby_wallet.address,
@@ -550,12 +565,12 @@ Get and report the Standby account balances.
hotwallet: [operational_wallet.address] hotwallet: [operational_wallet.address]
}) })
results += JSON.stringify(standby_balances.result, null, 2) results += JSON.stringify(standby_balances.result, null, 2)
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Get and report the Operational account balances. Get and report the Operational account balances.
``` ```javascript
results= "\nGetting operational account balances...\n" results= "\nGetting operational account balances...\n"
const operational_balances = await client.request({ const operational_balances = await client.request({
command: "account_lines", command: "account_lines",
@@ -563,12 +578,12 @@ Get and report the Operational account balances.
ledger_index: "validated" ledger_index: "validated"
}) })
results += JSON.stringify(operational_balances.result, null, 2) results += JSON.stringify(operational_balances.result, null, 2)
document.getElementById('operationalResultField').value = results operationalResultField.value = results
``` ```
Get and report the Broker account balances. Get and report the Broker account balances.
``` ```javascript
results= "\nGetting broker account balances...\n" results= "\nGetting broker account balances...\n"
const broker_balances = await client.request({ const broker_balances = await client.request({
command: "account_lines", command: "account_lines",
@@ -576,35 +591,41 @@ Get and report the Broker account balances.
ledger_index: "validated" ledger_index: "validated"
}) })
results += JSON.stringify(broker_balances.result, null, 2) results += JSON.stringify(broker_balances.result, null, 2)
document.getElementById('brokerResultField').value = results brokerResultField.value = results
``` ```
Update the XRP balances for the three accounts. Update the XRP balances for the three accounts.
``` ```javascript
document.getElementById('operationalBalanceField').value = operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
(await client.getXrpBalance(operational_wallet.address)) standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
document.getElementById('standbyBalanceField').value = brokerBalanceField.value = (await client.getXrpBalance(broker_wallet.address))
(await client.getXrpBalance(standby_wallet.address))
document.getElementById('brokerBalanceField').value =
(await client.getXrpBalance(broker_wallet.address))
``` ```
Disconnect from the ledger. Disconnect from the ledger.
``` ```javascript
client.disconnect() client.disconnect()
} // end of getBalances() } // end of getBalances()
``` ```
## 5.broker-nfts.html ## 5.broker-nfts.html
Revise the HTML form to add a new Broker section at the top. Revise the HTML form to add a new Broker section at the top.
``` ```html
<html> <html>
<head> <head>
<title>Token Test Harness</title> <title>Token Test Harness</title>
<script src='https://unpkg.com/xrpl@2.2.3'></script> <link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
<style>
body{font-family: "Work Sans", sans-serif;padding: 20px;background: #fafafa;}
h1{font-weight: bold;}
input, button {padding: 6px;margin-bottom: 8px;}
button{font-weight: bold;font-family: "Work Sans", sans-serif;}
td{vertical-align: middle;}
</style>
<script src='https://unpkg.com/xrpl@2.7.0/build/xrpl-latest-min.js'></script>
<script src='ripplex1-send-xrp.js'></script> <script src='ripplex1-send-xrp.js'></script>
<script src='ripplex2-send-currency.js'></script> <script src='ripplex2-send-currency.js'></script>
<script src='ripplex3-mint-nfts.js'></script> <script src='ripplex3-mint-nfts.js'></script>
@@ -623,7 +644,7 @@ Revise the HTML form to add a new Broker section at the top.
<body> <body>
<h1>Token Test Harness</h1> <h1>Token Test Harness</h1>
<form id="theForm"> <form id="theForm">
Choose your ledger instance: Choose your ledger instance:
&nbsp;&nbsp; &nbsp;&nbsp;
<input type="radio" id="tn" name="server" <input type="radio" id="tn" name="server"
value="wss://s.altnet.rippletest.net:51233" checked> value="wss://s.altnet.rippletest.net:51233" checked>
@@ -1039,10 +1060,5 @@ Revise the HTML form to add a new Broker section at the top.
</table> </table>
</form> </form>
</body> </body>
</html> </html>
``` ```
| Previous | Next |
| :--- | ---: |
| [← 4. Transfer NFTokens >](transfer-nftokens.html) | [Authorize Minter → >](authorize-minter.html)|

View File

@@ -12,26 +12,22 @@ labels:
This example shows how to: This example shows how to:
1. Create accounts on the Testnet, funded with 1000 test XRP with no actual value.
1. Create accounts on the Testnet, funded with 10000 test XRP with no actual value.
2. Retrieve the accounts from seed values. 2. Retrieve the accounts from seed values.
3. Transfer XRP between accounts. 3. Transfer XRP between accounts.
When you create an account, you receive a public/private key pair offline. It does not appear on the ledger until it is funded with XRP. This example shows how to create accounts for Testnet, but not how to create an account that you can use on Mainnet. When you create an account, you receive a public/private key pair offline. Your account does not appear on the ledger until it is funded with XRP. This example shows how to create accounts for Testnet, but not how to create an account that you can use on Mainnet.
![Token Test Harness](img/quickstart2.png)
[![Token Test Harness](img/quickstart2.png)](img/quickstart2.png)
## Prerequisites ## Prerequisites
To get started, create a new folder on your local disk and install the JavaScript library using `npm`. To get started, create a new folder on your local disk and install the JavaScript library using `npm`.
``` ```
npm install xrpl npm install xrpl
``` ```
Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive. Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive.
**Note:** Without the Quickstart Samples, you will not be able to try the examples that follow. **Note:** Without the Quickstart Samples, you will not be able to try the examples that follow.
@@ -40,45 +36,38 @@ Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-p
To get test accounts: To get test accounts:
1. Open `1.get-accounts-send-xrp.html` in a browser 1. Open `1.get-accounts-send-xrp.html` in a browser
2. Choose **Testnet** or **Devnet**. 2. Choose **Testnet** or **Devnet**.
3. Click **Get New Standby Account**. 3. Click **Get New Standby Account**.
4. Click **Get New Operational Account.** 4. Click **Get New Operational Account.**
5. Copy and paste the **Seeds** field in a persistent location, such as a Notepad, so that you can reuse the accounts after reloading the form. 5. Copy and paste the **Seeds** field in a persistent location, such as a Notepad, so that you can reuse the accounts after reloading the form.
[![Standby and Operational Accounts](img/quickstart3.png)](img/quickstart3.png)
![Standby and Operational Accounts](img/quickstart3.png)
You can transfer XRP between your new accounts. Each account has its own fields and buttons. You can transfer XRP between your new accounts. Each account has its own fields and buttons.
To transfer XRP between accounts: To transfer XRP from the Standby account to the Operational account:
1. On the Standby (left) side of the form, enter the **Amount** of XRP to send.
2. Copy and paste the **Operational Account** field to the Standby **Destination** field.
3. Click **Send XRP>** to transfer XRP from the standby account to the operational account
To transfer XRP from the Operational account to the Standby account:
1. Enter the **Amount** of XRP to send. 1. On the Operational (right) side of the form, enter the **Amount** of XRP to send.
2. Enter the **Destination** account (for example, copy and paste the Operational **Account Field** to the Standby **Destination** field). 2. Copy and paste the **Standby Account** field to the Standby **Destination** field.
3. Click **Send XRP>** to transfer XRP from the standby account to the operational account, or **&lt;Send XRP** to transfer XRP from the operational account to the standby account. 3. Click **&lt;Send XRP** to transfer XRP from the Operational account to the Standby account.
![Transferred XRP](img/quickstart4.png)
[![Transferred XRP](img/quickstart4.png)](img/quickstart4.png)
# Code Walkthrough # Code Walkthrough
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} in the source repository for this website. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} in the source repository for this website.
## ripplex-1-send-xrp.js ## ripplex-1-send-xrp.js
This example can be used with any XRP Ledger network, _Testnet_, or _Devnet_. You can update the code to choose different or additional XRP Ledger networks. This example can be used with any XRP Ledger network, _Testnet_, or _Devnet_. You can update the code to choose different or additional XRP Ledger networks.
### getNet() ### getNet()
<!-- SPELLING_IGNORE: getnet --> <!-- SPELLING_IGNORE: getnet -->
@@ -90,433 +79,327 @@ This example can be used with any XRP Ledger network, _Testnet_, or _Devnet_. Yo
function getNet() { function getNet() {
``` ```
This function uses brute force `if` statements to discover the selected network instance and return the URI. This function uses brute force `if` statements to discover the selected network instance and return the URI.
```javascript ```javascript
let net let net
if (document.getElementById("tn").checked) net = "wss://s.altnet.rippletest.net:51233" if (document.getElementById("tn").checked) net = "wss://s.altnet.rippletest.net:51233"
if (document.getElementById("dn").checked) net = "wss://s.devnet.rippletest.net:51233" if (document.getElementById("dn").checked) net = "wss://s.devnet.rippletest.net:51233"
return net return net
} // End of getNet() } // End of getNet()
``` ```
### getAccount(type) ### getAccount(type)
<!-- SPELLING_IGNORE: getaccount --> <!-- SPELLING_IGNORE: getaccount -->
```javascript ```javascript
// ******************************************************* // *******************************************************
// ************* Get Account ***************************** // ************* Get Account *****************************
// ******************************************************* // *******************************************************
async function getAccount(type) {
async function getAccount(type) {
``` ```
Get the selected ledger. Get the selected ledger.
```javascript ```javascript
let net = getNet() let net = getNet()
``` ```
Instantiate a client. Instantiate a client.
```javascript ```javascript
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
``` ```
Use the _results_ variable to capture progress information. Use the _results_ variable to capture progress information.
```javascript ```javascript
results = 'Connecting to ' + net + '....' results = 'Connecting to ' + net + '....'
``` ```
Use the default faucet using a _null_ value. Use the default faucet using a _null_ value.
```javascript ```javascript
let faucetHost = null let faucetHost = null
``` ```
Report progress in the appropriate results field. Report progress in the appropriate results field.
```javascript ```javascript
if (type == 'standby') { if (type == 'standby') {
document.getElementById('standbyResultField').value = results standbyResultField.value = results
} else { } else {
document.getElementById('operationalResultField').value = results operationalResultField.value = results
} }
``` ```
Connect to the server. Connect to the server.
```javascript ```javascript
await client.connect() await client.connect()
results += '\nConnected, funding wallet.'
if (type == 'standby') {
standbyResultField.value = results
} else {
operationalResultField.value = results
}
results += '\nConnected, funding wallet.'
if (type == 'standby') {
document.getElementById('standbyResultField').value = results
} else {
document.getElementById('operationalResultField').value = results
}
``` ```
Create and fund a test account. Create and fund a test account.
```javascript ```javascript
const my_wallet = (await client.fundWallet(null, { faucetHost: walletServer})).wallet const my_wallet = (await client.fundWallet(null, { faucetHost })).wallet
results += '\nGot a wallet.'
if (type == 'standby') {
standbyResultField.value = results
} else {
operationalResultField.value = results
}
``` ```
Get the current XRP balance for the account. Get the current XRP balance for the account.
```javascript ```javascript
const my_balance = (await client.getXrpBalance(my_wallet.address)) const my_balance = (await client.getXrpBalance(my_wallet.address))
``` ```
If this is a standby account, populate the standby account fields. If this is a standby account, populate the standby account fields.
```javascript ```javascript
if (type == 'standby') { if (type == 'standby') {
document.getElementById('standbyAccountField').value = my_wallet.address standbyAccountField.value = my_wallet.address
document.getElementById('standbyPubKeyField').value = my_wallet.publicKey standbyPubKeyField.value = my_wallet.publicKey
document.getElementById('standbyPrivKeyField').value = my_wallet.privateKey standbyPrivKeyField.value = my_wallet.privateKey
document.getElementById('standbyBalanceField').value = standbyBalanceField.value = (await client.getXrpBalance(my_wallet.address))
(await client.getXrpBalance(my_wallet.address)) standbySeedField.value = my_wallet.seed
document.getElementById('standbySeedField').value = my_wallet.seed results += '\nStandby account created.'
results += '\nStandby account created.' standbyResultField.value = results
document.getElementById('standbyResultField').value = results
``` ```
Otherwise, populate the operational account fields. Otherwise, populate the operational account fields.
```javascript ```javascript
} else { } else {
document.getElementById('operationalAccountField').value = my_wallet.address operationalAccountField.value = my_wallet.address
document.getElementById('operationalPubKeyField').value = my_wallet.publicKey operationalPubKeyField.value = my_wallet.publicKey
document.getElementById('operationalPrivKeyField').value = my_wallet.privateKey operationalPrivKeyField.value = my_wallet.privateKey
document.getElementById('operationalSeedField').value = my_wallet.seed operationalSeedField.value = my_wallet.seed
document.getElementById('operationalBalanceField').value = operationalBalanceField.value = (await client.getXrpBalance(my_wallet.address))
(await client.getXrpBalance(my_wallet.address)) results += '\nOperational account created.'
results += '\nOperational account created.' operationalResultField.value = results
document.getElementById('operationalResultField').value = results }
}
``` ```
Insert the seed values for both accounts as they are created to the **Seeds** field as a convenience. You can copy the values and store them offline. When you reload this form or another in this tutorial, copy and paste them into the **Seeds** field to retrieve the accounts with the `getAccountsFromSeeds()` function. Insert the seed values for both accounts as they are created to the **Seeds** field as a convenience. You can copy the values and store them offline. When you reload this form or another in this tutorial, copy and paste them into the **Seeds** field to retrieve the accounts with the `getAccountsFromSeeds()` function.
```javascript ```javascript
document.getElementById('seeds').value = standbySeedField.value + '\n' + operationalSeedField.value seeds.value = standbySeedField.value + '\n' + operationalSeedField.value
``` ```
Disconnect from the XRP ledger. Disconnect from the XRP ledger.
```javascript
client.disconnect()
} // End of getAccount()
``` ```
client.disconnect()
} // End of getAccount()
```
### Get Accounts from Seeds ### Get Accounts from Seeds
```javascript ```javascript
// ******************************************************* // *******************************************************
// ********** Get Accounts from Seeds ******************** // ********** Get Accounts from Seeds ********************
// ******************************************************* // *******************************************************
async function getAccountsFromSeeds() { async function getAccountsFromSeeds() {
``` ```
Connect to the selected network. Connect to the selected network.
```javascript
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
standbyResultField.value = results
await client.connect()
results += '\nConnected, finding wallets.\n'
standbyResultField.value = results
``` ```
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results
await client.connect()
results += '\nConnected, finding wallets.\n'
document.getElementById('standbyResultField').value = results
```
Parse the **Seeds** field. Parse the **Seeds** field.
```javascript
var lines = seeds.value.split('\n')
``` ```
var lines = seeds.value.split('\n');
```
Get the `standby_wallet` based on the seed in the first line. Get the `operational_wallet` based on the seed in the second line. Get the `standby_wallet` based on the seed in the first line. Get the `operational_wallet` based on the seed in the second line.
```javascript
const standby_wallet = xrpl.Wallet.fromSeed(lines[0])
const operational_wallet = xrpl.Wallet.fromSeed(lines[1])
``` ```
const standby_wallet = xrpl.Wallet.fromSeed(lines[0])
const operational_wallet = xrpl.Wallet.fromSeed(lines[1])
```
Get the current XRP balances for the accounts. Get the current XRP balances for the accounts.
```javascript
const standby_balance = (await client.getXrpBalance(standby_wallet.address))
const operational_balance = (await client.getXrpBalance(operational_wallet.address))
``` ```
const standby_balance = (await client.getXrpBalance(standby_wallet.address))
const operational_balance = (await client.getXrpBalance(operational_wallet.address))
```
Populate the fields for the standby and operational accounts. Populate the fields for the standby and operational accounts.
```javascript
standbyAccountField.value = standby_wallet.address
standbyPubKeyField.value = standby_wallet.publicKey
standbyPrivKeyField.value = standby_wallet.privateKey
standbySeedField.value = standby_wallet.seed
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
operationalAccountField.value = operational_wallet.address
operationalPubKeyField.value = operational_wallet.publicKey
operationalPrivKeyField.value = operational_wallet.privateKey
operationalSeedField.value = operational_wallet.seed
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
``` ```
document.getElementById('standbyAccountField').value = standby_wallet.address
document.getElementById('standbyPubKeyField').value = standby_wallet.publicKey
document.getElementById('standbyPrivKeyField').value = standby_wallet.privateKey
document.getElementById('standbySeedField').value = standby_wallet.seed
document.getElementById('standbyBalanceField').value =
(await client.getXrpBalance(standby_wallet.address))
document.getElementById('operationalAccountField').value = operational_wallet.address
document.getElementById('operationalPubKeyField').value = operational_wallet.publicKey
document.getElementById('operationalPrivKeyField').value = operational_wallet.privateKey
document.getElementById('operationalSeedField').value = operational_wallet.seed
document.getElementById('operationalBalanceField').value =
(await client.getXrpBalance(operational_wallet.address))
```
Disconnect from the XRP Ledger. Disconnect from the XRP Ledger.
```javascript
client.disconnect()
} // End of getAccountsFromSeeds()
``` ```
client.disconnect()
} // End of getAccountsFromSeeds()
```
### Send XRP ### Send XRP
```javascript
```
// ******************************************************* // *******************************************************
// ******************** Send XRP ************************* // ******************** Send XRP *************************
// ******************************************************* // *******************************************************
async function sendXRP() { async function sendXRP() {
``` ```
Connect to your selected ledger. Connect to your selected ledger.
```javascript
``` results = "Connecting to the selected ledger.\n"
standbyResultField.value = results
let net = getNet()
results = "Connecting to the selected ledger.\n" results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results const client = new xrpl.Client(net)
let net = getNet() await client.connect()
results = 'Connecting to ' + getNet() + '....'
const client = new xrpl.Client(net) results += "\nConnected. Sending XRP.\n"
await client.connect() standbyResultField.value = results
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
results += "\nConnected. Sending XRP.\n" const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
document.getElementById('standbyResultField').value = results const sendAmount = standbyAmountField.value
results += "\nstandby_wallet.address: = " + standby_wallet.address
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) standbyResultField.value = results
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
const sendAmount = standbyAmountField.value
results += "\nstandby_wallet.address: = " + standby_wallet.address
document.getElementById('standbyResultField').value = results
``` ```
Prepare the transaction. This is a Payment transaction from the standby address to the operational address. Prepare the transaction. This is a Payment transaction from the standby address to the operational address.
The _Payment_ transaction expects the XRP to be expressed in drops, or 1/millionth of an XRP. You can use the `xrpToDrops()` method to convert the send amount for you (which beats having to type an extra 6 zeroes to send 1 XRP). The _Payment_ transaction expects the XRP to be expressed in drops, or 1/millionth of an XRP. You can use the `xrpToDrops()` method to convert the send amount for you (which beats having to type an extra 6 zeroes to send 1 XRP).
```javascript
const prepared = await client.autofill({
"TransactionType": "Payment",
"Account": standby_wallet.address,
"Amount": xrpl.xrpToDrops(sendAmount),
"Destination": standbyDestinationField.value
})
``` ```
const prepared = await client.autofill({
"TransactionType": "Payment",
"Account": standby_wallet.address,
"Amount": xrpl.xrpToDrops(sendAmount),
"Destination": standbyDestinationField.value
})
```
Sign the prepared transaction. Sign the prepared transaction.
``` ```
const signed = standby_wallet.sign(prepared) const signed = standby_wallet.sign(prepared)
``` ```
Submit the transaction and wait for the results. Submit the transaction and wait for the results.
``` ```
const tx = await client.submitAndWait(signed.tx_blob) const tx = await client.submitAndWait(signed.tx_blob)
``` ```
Request the balance changes caused by the transaction and report the results. Request the balance changes caused by the transaction and report the results.
``` ```
results += "\nBalance changes: " +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
standbyResultField.value = results
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
results += "\nBalance changes: " + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) client.disconnect()
document.getElementById('standbyResultField').value = results } // End of sendXRP()
document.getElementById('standbyBalanceField').value =
(await client.getXrpBalance(standby_wallet.address))
document.getElementById('operationalBalanceField').value =
(await client.getXrpBalance(operational_wallet.address))
client.disconnect()
} // End of sendXRP()
``` ```
### Reciprocal Transactions ### Reciprocal Transactions
For each of the transactions, there is an accompanying reciprocal transaction, with the prefix _oP,_ for the operational account. See the corresponding function for the standby account for code commentary. For each of the transactions, there is an accompanying reciprocal transaction, with the prefix _oP,_ for the operational account. See the corresponding function for the standby account for code commentary.
```javascript
```
// ********************************************************************** // **********************************************************************
// ****** Reciprocal Transactions **************************************** // ****** Reciprocal Transactions ***************************************
// ********************************************************************** // **********************************************************************
// ******************************************************* // *******************************************************
// ********* Send XRP from Operational account *********** // ********* Send XRP from Operational account ***********
// ******************************************************* // *******************************************************
async function oPsendXRP() {
results = "Connecting to the selected ledger.\n"
operationalResultField.value = results
let net = getNet()
results = 'Connecting to ' + getNet() + '....'
const client = new xrpl.Client(net)
await client.connect()
results += "\nConnected. Sending XRP.\n"
operationalResultField.value = results
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const sendAmount = operationalAmountField.value
results += "\noperational_wallet.address: = " + operational_wallet.address
operationalResultField.value = results
// ---------------------------------------------------------- Prepare transaction
const prepared = await client.autofill({
"TransactionType": "Payment",
"Account": operational_wallet.address,
"Amount": xrpl.xrpToDrops(operationalAmountField.value),
"Destination": operationalDestinationField.value
})
async function oPsendXRP() { // ---------------------------------------------------- Sign prepared instructions
const signed = operational_wallet.sign(prepared)
// ------------------------------------------------------------ Submit signed blob
results = "Connecting to testnet.\n" const tx = await client.submitAndWait(signed.tx_blob)
document.getElementById('operationalResultField').value = results
let net = getNet() results += "\nBalance changes: " +
results = 'Connecting to ' + getNet() + '....' JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
const client = new xrpl.Client(net) operationalResultField.value = results
await client.connect() standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
results += "\nConnected. Sending XRP.\n" client.disconnect()
document.getElementById('operationalResultField').value = results } // End of oPsendXRP()
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const sendAmount = operationalAmountField.value
results += "\noperational_wallet.address: = " + operational_wallet.address
document.getElementById('operationalResultField').value = results
// ---------------------------------- Prepare transaction
// Note that the destination is hard coded.
const prepared = await client.autofill({
"TransactionType": "Payment",
"Account": operational_wallet.address,
"Amount": xrpl.xrpToDrops(operationalAmountField.value),
"Destination": operationalDestinationField.value
})
// ---------------------------- Sign prepared instructions
const signed = operational_wallet.sign(prepared)
// ------------------------------------ Submit signed blob
const tx = await client.submitAndWait(signed.tx_blob)
results += "\nBalance changes: " +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
document.getElementById('operationalResultField').value = results
document.getElementById('standbyBalanceField').value =
(await client.getXrpBalance(standby_wallet.address))
document.getElementById('operationalBalanceField').value =
(await client.getXrpBalance(operational_wallet.address))
client.disconnect()
} // End of oPsendXRP()
``` ```
## 1.get-accounts-send-xrp.html ## 1.get-accounts-send-xrp.html
Create a standard HTML form to send transactions and requests, then display the results. Create a standard HTML form to send transactions and requests, then display the results.
```html ```html
<html> <html>
<head> <head>
@@ -529,7 +412,7 @@ Create a standard HTML form to send transactions and requests, then display the
button{font-weight: bold;font-family: "Work Sans", sans-serif;} button{font-weight: bold;font-family: "Work Sans", sans-serif;}
td{vertical-align: middle;} td{vertical-align: middle;}
</style> </style>
<script src='https://unpkg.com/xrpl@2.2.3'></script> <script src='https://unpkg.com/xrpl@2.7.0/build/xrpl-latest-min.js'></script>
<script src='ripplex1-send-xrp.js'></script> <script src='ripplex1-send-xrp.js'></script>
<script> <script>
if (typeof module !== "undefined") { if (typeof module !== "undefined") {
@@ -747,7 +630,3 @@ Create a standard HTML form to send transactions and requests, then display the
</body> </body>
</html> </html>
``` ```
| Previous | Next |
| :--- | ---: |
| [← XRPL Quickstart >](xrpl-quickstart.html) | [2. Create Trust Line and Send Currency → >](create-trustline-send-currency.html) |

View File

@@ -14,29 +14,22 @@ labels:
This example shows how to: This example shows how to:
1. Configure accounts to allow transfer of funds to third party accounts. 1. Configure accounts to allow transfer of funds to third party accounts.
2. Set a currency type for transactions. 2. Set a currency type for transactions.
3. Create a trust line between the standby account and the operational account. 3. Create a trust line between the standby account and the operational account.
4. Send issued currency between accounts. 4. Send issued currency between accounts.
5. Display account balances for all currencies. 5. Display account balances for all currencies.
[![Test harness with currency transfer](img/quickstart5.png)](img/quickstart5.png)
![Test harness with currency transfer](img/quickstart5.png)
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser. You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive to try each of the samples in your own browser.
**Note:** Without the Quickstart Samples, you will not be able to try the examples that follow. **Note:** Without the Quickstart Samples, you will not be able to try the examples that follow.
## Usage ## Usage
Open the Token Test Harness and get accounts: Open the Token Test Harness and get accounts:
1. Open `2.create-trustline-send-currency.html` in a browser. 1. Open `2.create-trustline-send-currency.html` in a browser.
2. Get test accounts. 2. Get test accounts.
1. If you have existing account seeds 1. If you have existing account seeds
@@ -46,40 +39,27 @@ Open the Token Test Harness and get accounts:
1. Click **Get New Standby Account**. 1. Click **Get New Standby Account**.
2. Click **Get New Operational Account**. 2. Click **Get New Operational Account**.
## Create Trust Line ## Create Trust Line
To create a trust line between accounts: To create a trust line between accounts:
1. Enter a [currency code](https://www.iban.com/currency-codes) in the **Currency** field.
2. Enter the maximum transfer limit in the **Amount** field.
3. Enter the destination account value in the **Destination** field.
4. Click **Create Trustline**. <!-- SPELLING_IGNORE: trustline --><!--{# TODO: update the test harness to spell trust line as two words #}-->
[![Trust line results](img/quickstart6.png)](img/quickstart6.png)
3. Enter a [currency code](https://www.iban.com/currency-codes) in the **Currency** field.
4. Enter the maximum transfer limit in the **Amount** field.
5. Enter the destination account value in the **Destination** field.
6. Click **Create Trustline**. <!-- SPELLING_IGNORE: trustline --><!--{# TODO: update the test harness to spell trust line as two words #}-->
![Trust line results](img/quickstart6.png)
## Send an Issued Currency Token ## Send an Issued Currency Token
To transfer an issued currency token, once you have created a trust line: To transfer an issued currency token, once you have created a trust line:
1. Enter the **Amount**. 1. Enter the **Amount**.
2. Enter the **Destination**. 2. Enter the **Destination**.
3. Enter the **Currency** type. 3. Enter the **Currency** type.
4. Click **Send Currency**. 4. Click **Send Currency**.
[![Currency transfer](img/quickstart7.png)](img/quickstart7.png)
![Currency transfer](img/quickstart7.png)
# Code Walkthrough # Code Walkthrough
@@ -92,318 +72,275 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
When transferring fiat currency, the actual transfer of funds is not simultaneous, as it is with XRP. If currency is transferred to a third party for a different currency, there can be a devaluation of the currency that impacts the originating account. To avoid this situation, this up and down valuation of currency, known as _rippling_, is not allowed by default. Currency transferred from one account can only be transferred back to the same account. To enable currency transfer to third parties, you need to set the `rippleDefault` value to true. The Token Test Harness provides a checkbox to enable or disable rippling. When transferring fiat currency, the actual transfer of funds is not simultaneous, as it is with XRP. If currency is transferred to a third party for a different currency, there can be a devaluation of the currency that impacts the originating account. To avoid this situation, this up and down valuation of currency, known as _rippling_, is not allowed by default. Currency transferred from one account can only be transferred back to the same account. To enable currency transfer to third parties, you need to set the `rippleDefault` value to true. The Token Test Harness provides a checkbox to enable or disable rippling.
```javascript
```
// ******************************************************* // *******************************************************
// **************** Configure Account ******************** // **************** Configure Account ********************
// ******************************************************* // *******************************************************
async function configureAccount(type, defaultRippleSetting) {
``` ```
Connect to the ledger Connect to the ledger
```javascript
let net = getNet()
let resultField = 'standbyResultField'
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
await client.connect()
results += '\nConnected, finding wallet.'
``` ```
async function configureAccount(type, rippleDefault) {
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results
await client.connect()
results += '\nConnected, finding wallet.'
document.getElementById('standbyResultField').value = results
```
Get the account wallets. Get the account wallets.
``` ```
if (type=='standby') { if (type=='standby') {
my_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) my_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
} else { } else {
my_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) my_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
} resultField = 'operationalResultField'
results += '\Ripple Default Setting: ' + rippleDefault }
document.getElementById('standbyResultField').value = results results += '\nRipple Default Setting: ' + defaultRippleSetting
resultField.value = results
``` ```
Prepare the transaction. If the `rippleDefault` argument is true, set the `asfDefaultRipple` flag. If it is false, clear the `asfDefaultRipple` flag. Prepare the transaction. If the `rippleDefault` argument is true, set the `asfDefaultRipple` flag. If it is false, clear the `asfDefaultRipple` flag.
```javascript
let settings_tx = {}
if (defaultRippleSetting) {
settings_tx = {
"TransactionType": "AccountSet",
"Account": my_wallet.address,
"SetFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple
}
results += '\n Set Default Ripple flag.'
} else {
settings_tx = {
"TransactionType": "AccountSet",
"Account": my_wallet.address,
"ClearFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple
}
results += '\n Clear Default Ripple flag.'
}
results += '\nSending account setting.'
resultField.value = results
``` ```
let settings_tx = {}
if (rippleDefault) {
settings_tx = {
"TransactionType": "AccountSet",
"Account": my_wallet.address,
"SetFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple
}
results += '\n Set Default Ripple flag.'
} else {
settings_tx = {
"TransactionType": "AccountSet",
"Account": my_wallet.address,
"ClearFlag": xrpl.AccountSetAsfFlags.asfDefaultRipple
}
results += '\n Clear Default Ripple flag.'
}
results += '\nSending account setting.'
document.getElementById('standbyResultField').value = results
```
Auto-fill the default values for the transaction. Auto-fill the default values for the transaction.
```javascript
const prepared = await client.autofill(settings_tx)
``` ```
const cst_prepared = await client.autofill(settings_tx)
```
Sign the transaction. Sign the transaction.
```javascript
const signed = my_wallet.sign(prepared)
``` ```
const cst_signed = my_wallet.sign(cst_prepared)
```
Submit the transaction and wait for the result. Submit the transaction and wait for the result.
```javascript
const result = await client.submitAndWait(signed.tx_blob)
``` ```
const cst_result = await client.submitAndWait(cst_signed.tx_blob)
```
Report the result. Report the result.
```javascript
if (result.result.meta.TransactionResult == "tesSUCCESS") {
results += '\nAccount setting succeeded.'
document.getElementById(resultField).value = results
} else {
throw 'Error sending transaction: ${result}'
results += '\nAccount setting failed.'
resultField.value = results
}
client.disconnect()
} // End of configureAccount()
``` ```
if (cst_result.result.meta.TransactionResult == "tesSUCCESS") {
results += '\nAccount setting succeeded.'
document.getElementById('standbyResultField').value = results
} else {
throw 'Error sending transaction: ${cst_result}'
results += '\nAccount setting failed.'
document.getElementById('standbyResultField').value = results
}
client.disconnect()
} // End of configureAccount()
```
### Create Trust Line ### Create Trust Line
A trust line enables two accounts to trade a defined currency up to a set limit. This gives the participants assurance that any exchanges are between known entities at agreed upon maximum amounts. A trust line enables two accounts to trade a defined currency up to a set limit. This gives the participants assurance that any exchanges are between known entities at agreed upon maximum amounts.
```javascript
```
// ******************************************************* // *******************************************************
// ***************** Create TrustLine ******************** // ***************** Create TrustLine ********************
// ******************************************************* // *******************************************************
async function createTrustline() {
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
standbyResultField.value = results
await client.connect()
async function createTrustline(type) { results += '\nConnected.'
let net = getNet() standbyResultField.value = results
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results
await client.connect()
results += '\nConnected.'
document.getElementById('standbyResultField').value = results
``` ```
Get the standby and operational wallets. Get the standby and operational wallets.
```javascript
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
```
```
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
```
Capture the currency code from the standby currency field. Capture the currency code from the standby currency field.
```javascript
const currency_code = standbyCurrencyField.value
``` ```
const currency_code = standbyCurrencyField.value
```
Define the transaction, capturing the currency code and (limit) amount from the form fields. Define the transaction, capturing the currency code and (limit) amount from the form fields.
```javascript
const trustSet_tx = {
"TransactionType": "TrustSet",
"Account": standbyDestinationField.value,
"LimitAmount": {
"currency": standbyCurrencyField.value,
"issuer": standby_wallet.address,
"value": standbyAmountField.value
}
}
``` ```
const trustSet_tx = {
"TransactionType": "TrustSet",
"Account": standbyDestinationField.value,
"LimitAmount": {
"currency": standbyCurrencyField.value,
"issuer": standby_wallet.address,
"value": standbyAmountField.value
}
}
```
Prepare the transaction by automatically filling the default parameters. Prepare the transaction by automatically filling the default parameters.
```javascript
``` const ts_prepared = await client.autofill(trustSet_tx)
const ts_prepared = await client.autofill(trustSet_tx)
``` ```
Sign the transaction. Sign the transaction.
``` ```javascript
const ts_signed = operational_wallet.sign(ts_prepared) const ts_signed = operational_wallet.sign(ts_prepared)
results += '\nCreating trust line from operational account to standby account...' results += '\nCreating trust line from operational account to standby account...'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Submit the transaction and wait for the results. Submit the transaction and wait for the results.
``` ```javascript
const ts_result = await client.submitAndWait(ts_signed.tx_blob) const ts_result = await client.submitAndWait(ts_signed.tx_blob)
``` ```
Report the results. Report the results.
``` ```javascript
if (ts_result.result.meta.TransactionResult == "tesSUCCESS") { if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
results += '\nTrustline established between account \n' + operational_wallet.address + ' \n and account\n' + standby_wallet.address + '.' results += '\nTrustline established between account \n' +
document.getElementById('standbyResultField').value = results standbyDestinationField.value + ' \n and account\n' + standby_wallet.address + '.'
} else { standbyResultField.value = results
results += '\nTrustLine failed. See JavaScript console for details.' } else {
document.getElementById('standbyResultField').value = results results += '\nTrustLine failed. See JavaScript console for details.'
throw 'Error sending transaction: ${ts_result.result.meta.TransactionResult}' document.getElementById('standbyResultField').value = results
} throw 'Error sending transaction: ${ts_result.result.meta.TransactionResult}'
} //End of createTrustline() }
``` } //End of createTrustline()
```
### Send Issued Currency ### Send Issued Currency
Once you have created a trust line from an account to your own, you can send issued currency tokens to that account, up to the established limit. Once you have created a trust line from an account to your own, you can send issued currency tokens to that account, up to the established limit.
```javascript
```
// ******************************************************* // *******************************************************
// *************** Send Issued Currency ****************** // *************** Send Issued Currency ******************
// ******************************************************* // *******************************************************
async function sendCurrency() {
async function sendCurrency() {
``` ```
Connect to the ledger. Connect to the ledger.
```javascript
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results
await client.connect()
results += '\nConnected.'
standbyResultField.value = results
``` ```
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results
await client.connect()
results += '\nConnected.'
document.getElementById('standbyResultField').value = results
```
Get the account wallets. Get the account wallets.
```javascript
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
``` const currency_code = standbyCurrencyField.value
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const issue_quantity = standbyAmountField.value
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
const currency_code = standbyCurrencyField.value const send_token_tx = {
const issue_quantity = standbyAmountField.value "TransactionType": "Payment",
"Account": standby_wallet.address,
"Amount": {
const send_token_tx = { "currency": standbyCurrencyField.value,
"TransactionType": "Payment", "value": standbyAmountField.value,
"Account": standby_wallet.address, "issuer": standby_wallet.address
"Amount": { },
"currency": currency_code, "Destination": standbyDestinationField.value
"value": issue_quantity, }
"issuer": standby_wallet.address
},
"Destination": standbyDestinationField.value
}
``` ```
Prepare the transaction by automatically filling default values. Prepare the transaction by automatically filling default values.
``` ```javascript
const pay_prepared = await client.autofill(send_token_tx) const pay_prepared = await client.autofill(send_token_tx)
``` ```
Sign the transaction. Sign the transaction.
``` ```javascript
const pay_signed = standby_wallet.sign(pay_prepared) const pay_signed = standby_wallet.sign(pay_prepared)
results += 'Sending ${issue_quantity} ${currency_code} to ' + standbyDestinationField.value + '...' results += 'Sending ${issue_quantity} ${currency_code} to ' +
document.getElementById('standbyResultField').value = results standbyDestinationField.value + '...'
standbyResultField.value = results
``` ```
Submit the transaction and wait for the results. Submit the transaction and wait for the results.
``` ```javascript
const pay_result = await client.submitAndWait(pay_signed.tx_blob) const pay_result = await client.submitAndWait(pay_signed.tx_blob)
``` ```
Report the results. Report the results.
``` ```javascript
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") { if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}' results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
} else { } else {
results += 'Transaction failed: See JavaScript console for details.' results += 'Transaction failed: See JavaScript console for details.'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
throw 'Error sending transaction: ${pay_result.result.meta.TransactionResult}' throw 'Error sending transaction: ${pay_result.result.meta.TransactionResult}'
} }
document.getElementById('standbyBalanceField').value = standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
(await client.getXrpBalance(standby_wallet.address)) operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
document.getElementById('operationalBalanceField').value = getBalances()
(await client.getXrpBalance(operational_wallet.address)) client.disconnect()
client.disconnect() } // end of sendCurrency()
getBalances()
} // end of sendCurrency()
``` ```
@@ -411,228 +348,200 @@ Report the results.
### Get Balances ### Get Balances
``` ```javascript
// ******************************************************* // *******************************************************
// ****************** Get Balances *********************** // ****************** Get Balances ***********************
// ******************************************************* // *******************************************************
async function getBalances() {
```
async function getBalances() {
```
Connect to the ledger. Connect to the ledger.
```javascript
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
standbyResultField.value = results
await client.connect()
results += '\nConnected.'
standbyResultField.value = results
``` ```
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results
await client.connect()
results += '\nConnected.'
document.getElementById('standbyResultField').value = results
```
Get the account wallets. Get the account wallets.
```javascript
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
results = "\nGetting standby account balances...\n"
``` ```
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
results= "\nGetting standby account balances...\n"
```
Define and send the request for the standby account, then wait for the results. Define and send the request for the standby account, then wait for the results.
```javascript
const standby_balances = await client.request({
command: "gateway_balances",
account: standby_wallet.address,
ledger_index: "validated",
hotwallet: [operational_wallet.address]
})
``` ```
const standby_balances = await client.request({
command: "gateway_balances",
account: standby_wallet.address,
ledger_index: "validated",
hotwallet: [operational_wallet.address]
})
```
Report the results. Report the results.
```javascript
results += JSON.stringify(standby_balances.result, null, 2)
standbyResultField.value = results
``` ```
results += JSON.stringify(standby_balances.result, null, 2)
document.getElementById('standbyResultField').value = results
```
Define and send the request for the operational account, then wait for the results. Define and send the request for the operational account, then wait for the results.
```javascript
results += "\nGetting operational account balances...\n"
const operational_balances = await client.request({
command: "gateway_balances",
account: operational_wallet.address,
ledger_index: "validated"
})
``` ```
results= "\nGetting operational account balances...\n"
const operational_balances = await client.request({
command: "account_lines",
account: operational_wallet.address,
ledger_index: "validated"
})
```
Report the results. Report the results.
```javascript
results += JSON.stringify(operational_balances.result, null, 2)
operationalResultField.value = results
``` ```
results += JSON.stringify(operational_balances.result, null, 2)
document.getElementById('operationalResultField').value = results
```
Update the form with current XRP balances. Update the form with current XRP balances.
```javascript
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
standbyResultField.value = results
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
``` ```
document.getElementById('operationalBalanceField').value =
(await client.getXrpBalance(operational_wallet.address))
document.getElementById('standbyBalanceField').value =
(await client.getXrpBalance(standby_wallet.address))
```
Disconnect from the ledger. Disconnect from the ledger.
```javascript
client.disconnect()
} // End of getBalances()
``` ```
client.disconnect()
} // End of getBalances()
```
### Reciprocal Transactions ### Reciprocal Transactions
For each of the transactions, there is an accompanying reciprocal transaction, with the prefix _oP,_ for the operational account. See the corresponding function for the standby account for code commentary. The `getBalances()` request does not have a reciprocal transaction, because it reports balances for both accounts. For each of the transactions, there is an accompanying reciprocal transaction, with the prefix _oP,_ for the operational account. See the corresponding function for the standby account for code commentary. The `getBalances()` request does not have a reciprocal transaction, because it reports balances for both accounts.
```javascript
```
// ******************************************************* // *******************************************************
// ************ Create Operational TrustLine ************* // ************ Create Operational TrustLine *************
// ******************************************************* // *******************************************************
async function oPcreateTrustline() {
async function oPcreateTrustline() { let net = getNet()
let net = getNet() const client = new xrpl.Client(net)
const client = new xrpl.Client(net) results = 'Connecting to ' + getNet() + '....'
results = 'Connecting to ' + getNet() + '....' operationalResultField.value = results
document.getElementById('operationalResultField').value = results
await client.connect()
results += '\nConnected.'
await client.connect() operationalResultField.value = results
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
results += '\nConnected.' const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
document.getElementById('operationalResultField').value = results const trustSet_tx = {
"TransactionType": "TrustSet",
"Account": operationalDestinationField.value,
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) "LimitAmount": {
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) "currency": operationalCurrencyField.value,
const trustSet_tx = { "issuer": operational_wallet.address,
"TransactionType": "TrustSet", "value": operationalAmountField.value
"Account": operationalDestinationField.value, }
"LimitAmount": { }
"currency": operationalCurrencyField.value, const ts_prepared = await client.autofill(trustSet_tx)
"issuer": operational_wallet.address, const ts_signed = standby_wallet.sign(ts_prepared)
"value": operationalAmountField.value results += '\nCreating trust line from operational account to ' +
} operationalDestinationField.value + ' account...'
} operationalResultField.value = results
const ts_prepared = await client.autofill(trustSet_tx) const ts_result = await client.submitAndWait(ts_signed.tx_blob)
const ts_signed = standby_wallet.sign(ts_prepared) if (ts_result.result.meta.TransactionResult == "tesSUCCESS") {
results += '\nCreating trust line from operational account to ' + operationalDestinationField.value + ' account...' results += '\nTrustline established between account \n' + operational_wallet.address +
document.getElementById('operationalResultField').value = results ' \n and account\n' + operationalDestinationField.value + '.'
const ts_result = await client.submitAndWait(ts_signed.tx_blob) operationalResultField.value = results
if (ts_result.result.meta.TransactionResult == "tesSUCCESS") { } else {
results += '\nTrustline established between account \n' + standby_wallet.address + ' \n and account\n' + results += '\nTrustLine failed. See JavaScript console for details.'
operationalDestinationField.value + '.' operationalResultField.value = results
document.getElementById('operationalResultField').value = results throw 'Error sending transaction: ${ts_result.result.meta.TransactionResult}'
} else { }
results += '\nTrustLine failed. See JavaScript console for details.' } //End of oPcreateTrustline
document.getElementById('operationalResultField').value = results
throw 'Error sending transaction: ${ts_result.result.meta.TransactionResult}'
}
} //End of oPcreateTrustline
// ******************************************************* // *******************************************************
// ************* Operational Send Issued Currency ******** // ************* Operational Send Issued Currency ********
// ******************************************************* // *******************************************************
async function oPsendCurrency() {
async function oPsendCurrency() { let net = getNet()
let net = getNet() const client = new xrpl.Client(net)
const client = new xrpl.Client(net) results = 'Connecting to ' + getNet() + '....'
results = 'Connecting to ' + getNet() + '....' operationalResultField.value = results
document.getElementById('operationalResultField').value = results
await client.connect()
results += '\nConnected.'
await client.connect() operationalResultField.value = results
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
results += '\nConnected.' const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
document.getElementById('operationalResultField').value = results const currency_code = operationalCurrencyField.value
const issue_quantity = operationalAmountField.value
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const send_token_tx = {
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) "TransactionType": "Payment",
const currency_code = operationalCurrencyField.value "Account": operational_wallet.address,
const issue_quantity = operationalAmountField.value "Amount": {
"currency": currency_code,
"value": issue_quantity,
const send_token_tx = { "issuer": operational_wallet.address
"TransactionType": "Payment", },
"Account": operational_wallet.address, "Destination": operationalDestinationField.value
"Amount": { }
"currency": currency_code,
"value": issue_quantity, const pay_prepared = await client.autofill(send_token_tx)
"issuer": operational_wallet.address const pay_signed = operational_wallet.sign(pay_prepared)
}, results += 'Sending ${issue_quantity} ${currency_code} to ' +
"Destination": operationalDestinationField.value operationalDestinationField.value + '...'
} operationalResultField.value = results
const pay_result = await client.submitAndWait(pay_signed.tx_blob)
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") {
const pay_prepared = await client.autofill(send_token_tx) results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}'
const pay_signed = operational_wallet.sign(pay_prepared) operationalResultField.value = results
results += 'Sending ${issue_quantity} ${currency_code} to ' + operationalDestinationField.value + '...' } else {
document.getElementById('operationalResultField').value = results results += 'Transaction failed: See JavaScript console for details.'
const pay_result = await client.submitAndWait(pay_signed.tx_blob) operationalResultField.value = results
if (pay_result.result.meta.TransactionResult == "tesSUCCESS") { throw 'Error sending transaction: ${pay_result.result.meta.TransactionResult}'
results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${pay_signed.hash}' }
document.getElementById('operationalResultField').value = results standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
} else { operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
results += 'Transaction failed: See JavaScript console for details.' getBalances()
document.getElementById('operationalResultField').value = results client.disconnect()
throw 'Error sending transaction: ${pay_result.result.meta.TransactionResult}' } // end of oPsendCurrency()
}
document.getElementById('standbyBalanceField').value =
(await client.getXrpBalance(standby_wallet.address))
document.getElementById('operationalBalanceField').value =
(await client.getXrpBalance(operational_wallet.address))
getBalances()
client.disconnect()
} // end of oPsendCurrency()
``` ```
## 2.create-trustline-send-currency.html ## 2.create-trustline-send-currency.html
Update the form to support the new functions. Update the form to support the new functions.
```html
```
<html> <html>
<head> <head>
<title>Token Test Harness</title> <title>Token Test Harness</title>
<script src='https://unpkg.com/xrpl@2.2.3'></script> <link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
<style>
body{font-family: "Work Sans", sans-serif;padding: 20px;background: #fafafa;}
h1{font-weight: bold;}
input, button {padding: 6px;margin-bottom: 8px;}
button{font-weight: bold;font-family: "Work Sans", sans-serif;}
td{vertical-align: middle;}
</style>
<script src='https://unpkg.com/xrpl@2.7.0/build/xrpl-latest-min.js'></script>
<script src='ripplex1-send-xrp.js'></script> <script src='ripplex1-send-xrp.js'></script>
<script src='ripplex2-send-currency.js'></script> <script src='ripplex2-send-currency.js'></script>
<script> <script>
@@ -731,7 +640,7 @@ Update the form to support the new functions.
Destination Destination
</td> </td>
<td> <td>
<input type="text" id="standbyDestinationField" size="40"></input> <input type="text" id="standbyDestinationField" size="40"></input>
<br> <br>
</td> </td>
</tr> </tr>
@@ -845,7 +754,7 @@ Update the form to support the new functions.
Amount Amount
</td> </td>
<td> <td>
<input type="text" id="operationalAmountField" size="40"></input> <input type="text" id="operationalAmountField" size="40"></input>
<br> <br>
</td> </td>
</tr> </tr>
@@ -894,11 +803,4 @@ Update the form to support the new functions.
</form> </form>
</body> </body>
</html> </html>
``` ```
---
| Previous | Next |
| :--- | ---: |
| [← 1. Create Accounts and Send XRP >](create-accounts-send-xrp.html) | [3. Mint and Burn NFTokens → >](mint-and-burn-nftokens.html) |

View File

@@ -12,15 +12,11 @@ labels:
This example shows how to: This example shows how to:
1. Mint new Non-fungible Tokens (NFTokens). 1. Mint new Non-fungible Tokens (NFTokens).
2. Get a list of existing NFTokens. 2. Get a list of existing NFTokens.
3. Delete (Burn) a NFToken. 3. Delete (Burn) a NFToken.
[![Test harness with mint NFToken fields](img/quickstart8.png)](img/quickstart8.png)
![Test harness with mint NFToken fields](img/quickstart8.png)
# Usage # Usage
@@ -28,8 +24,6 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
## Get Accounts ## Get Accounts
1. Open `3.mint-nfts.html` in a browser. 1. Open `3.mint-nfts.html` in a browser.
2. Get test accounts. 2. Get test accounts.
1. If you have existing Testnet account seeds: 1. If you have existing Testnet account seeds:
@@ -39,11 +33,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
1. Click **Get New Standby Account**. 1. Click **Get New Standby Account**.
2. Click **Get New Operational Account**. 2. Click **Get New Operational Account**.
[![Get accounts](img/quickstart9.png)](img/quickstart9.png)
![Get accounts](img/quickstart9.png)
## Mint a NFToken ## Mint a NFToken
@@ -52,40 +42,27 @@ To mint a non-fungible token object:
1. Set the **Flags** field. For testing purposes, we recommend setting the value to _8_. This sets the _tsTransferable_ flag, meaning that the NFToken object can be transferred to another account. Otherwise, the NFToken object can only be transferred back to the issuing account. See [NFToken Mint](https://xrpl.org/nftokenmint.html#:~:text=Example%20NFTokenMint%20JSON-,NFTokenMint%20Fields,-NFTokenMint%20Flags) for information about all of the available flags for minting NFTokens. 1. Set the **Flags** field. For testing purposes, we recommend setting the value to _8_. This sets the _tsTransferable_ flag, meaning that the NFToken object can be transferred to another account. Otherwise, the NFToken object can only be transferred back to the issuing account. See [NFToken Mint](https://xrpl.org/nftokenmint.html#:~:text=Example%20NFTokenMint%20JSON-,NFTokenMint%20Fields,-NFTokenMint%20Flags) for information about all of the available flags for minting NFTokens.
2. Enter the **Token URL**. This is a URI that points to the data or metadata associated with the NFToken object. You can use the sample URI provided if you do not have one of your own. 2. Enter the **Token URL**. This is a URI that points to the data or metadata associated with the NFToken object. You can use the sample URI provided if you do not have one of your own.
3. Enter the **Transfer Fee**, a percentage of the proceeds from future sales of the NFToken that will be returned to the original creator. This is a value of 0-50000 inclusive, allowing transfer rates between 0.000% and 50.000% in increments of 0.001%. If you do not set the **Flags** field to allow the NFToken to be transferrable, set this field to 0. 3. Enter the **Transfer Fee**, a percentage of the proceeds from future sales of the NFToken that will be returned to the original creator. This is a value of 0-50000 inclusive, allowing transfer rates between 0.000% and 50.000% in increments of 0.001%. If you do not set the **Flags** field to allow the NFToken to be transferrable, set this field to 0.
4. Click **Mint Token**. 4. Click **Mint NFToken**.
[![Mint NFToken fields](img/quickstart10.png)](img/quickstart10.png)
![Mint NFToken fields](img/quickstart10.png)
## Get Tokens ## Get Tokens
Click **Get Tokens** to get a list of NFTokens owned by the account. Click **Get NFTokens** to get a list of NFTokens owned by the account.
![Get NFTokens](img/quickstart11.png)
[![Get NFTokens](img/quickstart11.png)](img/quickstart11.png)
## Burn a Token ## Burn a Token
The current owner of a NFToken can always destroy (or _burn)_ a NFToken object. The current owner of a NFToken can always destroy (or _burn_) a NFToken object.
To permanently destroy a NFToken: To permanently destroy a NFToken:
1. Enter the **Token ID**. 1. Enter the **Token ID**.
2. Click **Burn Token**. 2. Click **Burn NFToken**.
![Burn NFTokens](img/quickstart12.png)
[![Burn NFTokens](img/quickstart12.png)](img/quickstart12.png)
# Code Walkthrough # Code Walkthrough
@@ -96,123 +73,99 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
### Mint Token ### Mint Token
```javascript
```
// ******************************************************* // *******************************************************
// ********************** Mint Token ********************* // ********************** Mint Token *********************
// ******************************************************* // *******************************************************
async function mintToken() { async function mintToken() {
``` ```
Connect to the ledger and get the account wallets. Connect to the ledger and get the account wallets.
```javascript
```
results = 'Connecting to ' + getNet() + '....' results = 'Connecting to ' + getNet() + '....'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
let net = getNet() let net = getNet()
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
await client.connect() await client.connect()
results += '\nConnected. Minting NFToken.' results += '\nConnected. Minting NFToken.'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Define the transaction. Define the transaction.
```javascript
``` const transactionJson = {
const transactionBlob = {
"TransactionType": "NFTokenMint", "TransactionType": "NFTokenMint",
"Account": standby_wallet.classicAddress, "Account": standby_wallet.classicAddress,
``` ```
Note that the URI field expects a hexadecimal value rather than the literal URI string. You can use the `convertStringToHex` utility to transform the URI in real time. Note that the URI field expects a hexadecimal value rather than the literal URI string. You can use the `convertStringToHex` utility to transform the URI in real time.
```javascript
```
"URI": xrpl.convertStringToHex(standbyTokenUrlField.value), "URI": xrpl.convertStringToHex(standbyTokenUrlField.value),
``` ```
If you want the NFToken to be transferable to third parties, set the **Flags** field to _8_. If you want the NFToken to be transferable to third parties, set the **Flags** field to _8_.
``` ```javascript
"Flags": parseInt(standbyFlagsField.value), "Flags": parseInt(standbyFlagsField.value),
``` ```
The Transfer Fee is a value 0 to 50000, used to set a royalty of 0.000% to 50.000% in increments of 0.001. The Transfer Fee is a value 0 to 50000, used to set a royalty of 0.000% to 50.000% in increments of 0.001.
``` ```javascript
"TransferFee": parseInt(standbyTransferFeeField.value), "TransferFee": parseInt(standbyTransferFeeField.value),
``` ```
The `TokenTaxon` is a required value. It is an arbitrary value defined by the issuer. If you do not have a use for the field, you can set it to _0_. The `TokenTaxon` is a required value. It is an arbitrary value defined by the issuer. If you do not have a use for the field, you can set it to _0_.
``` ```javascript
"NFTokenTaxon": 0 //Required, but if you have no use for it, set to zero. "NFTokenTaxon": 0 //Required, but if you have no use for it, set to zero.
} }
``` ```
Send the transaction and wait for the response. Send the transaction and wait for the response.
```javascript
const tx = await client.submitAndWait(transactionJson, { wallet: standby_wallet} )
``` ```
const tx = await client.submitAndWait(transactionBlob, { wallet: standby_wallet} )
```
Request a list of NFTs owned by the account. Request a list of NFTs owned by the account.
```javascript
```
const nfts = await client.request({ const nfts = await client.request({
method: "account_nfts", method: "account_nfts",
account: standby_wallet.classicAddress account: standby_wallet.classicAddress
}) })
``` ```
Report the results. Report the results.
```javascript
```
results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult
results += '\n\nnfts: ' + JSON.stringify(nfts, null, 2) results += '\n\nnfts: ' + JSON.stringify(nfts, null, 2)
document.getElementById('standbyBalanceField').value = standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
(await client.getXrpBalance(standby_wallet.address)) standbyResultField.value = results
document.getElementById('operationalBalanceField').value = results
``` ```
Disconnect from the ledger. Disconnect from the ledger.
```javascript
```
client.disconnect() client.disconnect()
} //End of mintToken() } //End of mintToken()
``` ```
### Get Tokens ### Get Tokens
```javascript
```
// ******************************************************* // *******************************************************
// ******************* Get Tokens ************************ // ******************* Get Tokens ************************
// ******************************************************* // *******************************************************
@@ -220,29 +173,87 @@ Disconnect from the ledger.
async function getTokens() { async function getTokens() {
``` ```
Connect to the ledger and get the account. Connect to the ledger and get the account.
```javascript
```
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...' results = 'Connecting to ' + net + '...'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
await client.connect() await client.connect()
results += '\nConnected. Getting NFTokens...' results += '\nConnected. Getting NFTokens...'
document.getElementById('standbyResultField').value = results standbyResultField.value = results
``` ```
Request a list of NFTs owned by the account. Request a list of NFTs owned by the account.
```javascript
``` const nfts = await client.request({
const nfts = await client.request({
method: "account_nfts", method: "account_nfts",
account: standby_wallet.classicAddress account: standby_wallet.classicAddress
})
```
Report the results.
```javascript
results += '\nNFTs:\n ' + JSON.stringify(nfts,null,2)
standbyResultField.value = results
```
Disconnect from the ledger.
```javascript
client.disconnect()
} //End of getTokens()
```
### Burn Token
```javascript
// *******************************************************
// ********************* Burn Token **********************
// *******************************************************
async function burnToken() {
```
Connect to the ledger and get the account wallets.
```javascript
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
standbyResultField.value = results
await client.connect()
results += '\nConnected. Burning NFToken...'
standbyResultField.value = results
```
Define the transaction.
```javascript
const transactionBlob = {
"TransactionType": "NFTokenBurn",
"Account": standby_wallet.classicAddress,
"NFTokenID": standbyTokenIdField.value
}
```
Submit the transaction and wait for the results.
```javascript
const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet})
```
Request a list of NFTokens owned by the client.
```javascript
const nfts = await client.request({
method: "account_nfts",
account: standby_wallet.classicAddress
}) })
``` ```
@@ -250,115 +261,36 @@ Request a list of NFTs owned by the account.
Report the results. Report the results.
``` ```javascript
results += '\nNFTs:\n ' + JSON.stringify(nfts,null,2) results += '\nTransaction result: '+ tx.result.meta.TransactionResult
document.getElementById('standbyResultField').value = results results += '\nBalance changes: ' +
``` JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
standbyResultField.value = results
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
Disconnect from the ledger. results += '\nNFTs: \n' + JSON.stringify(nfts,null,2)
standbyResultField.value = results
```
client.disconnect() client.disconnect()
} //End of getTokens() }// End of burnToken()
``` ```
### Burn Token
```
// *******************************************************
// ********************* Burn Token **********************
// *******************************************************
```
Connect to the ledger and get the account wallets.
```
async function burnToken() {
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
let net = getNet()
const client = new xrpl.Client(net)
results = 'Connecting to ' + net + '...'
document.getElementById('standbyResultField').value = results
await client.connect()
results += '\nConnected. Burning NFToken...'
document.getElementById('standbyResultField').value = results
```
Define the transaction.
```
const transactionBlob = {
"TransactionType": "NFTokenBurn",
"Account": standby_wallet.classicAddress,
"TokenID": standbyTokenIdField.value
}
```
Submit the transaction and wait for the results.
```
const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet})
```
Request a list of NFTokens owned by the client.
```
const nfts = await client.request({
method: "account_nfts",
account: standby_wallet.classicAddress
})
```
Report the results.
```
results += '\nTransaction result: '+ tx.result.meta.TransactionResult
results += '\nBalance changes: ' +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
document.getElementById('standbyResultField').value = results
document.getElementById('standbyBalanceField').value =
(await client.getXrpBalance(standby_wallet.address))
results += '\nNFTs: \n' + JSON.stringify(nfts,null,2)
document.getElementById('standbyResultField').value = results
client.disconnect()
}
// End of burnToken()
```
### Reciprocal Transactions ### Reciprocal Transactions
These transactions are the same as the Standby account transactions, but for the Operational account.
``` ```javascript
// ******************************************************* // *******************************************************
// ************** Operational Mint Token ***************** // ************** Operational Mint Token *****************
// ******************************************************* // *******************************************************
async function oPmintToken() { async function oPmintToken() {
results = 'Connecting to ' + getNet() + '....' results = 'Connecting to ' + getNet() + '....'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
let net = getNet() let net = getNet()
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
await client.connect() await client.connect()
results += '\nConnected. Minting NFToken.' results += '\nConnected. Minting NFToken.'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
// Note that you must convert the token URL to a hexadecimal // Note that you must convert the token URL to a hexadecimal
// value for this transaction. // value for this transaction.
@@ -376,40 +308,38 @@ async function oPmintToken() {
const tx = await client.submitAndWait(transactionBlob, { wallet: operational_wallet} ) const tx = await client.submitAndWait(transactionBlob, { wallet: operational_wallet} )
const nfts = await client.request({ const nfts = await client.request({
method: "account_nfts", method: "account_nfts",
account: operational_wallet.classicAddress account: operational_wallet.classicAddress
}) })
// ------------------------------------------------------- Report results // ------------------------------------------------------- Report results
results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult
results += '\n\nnfts: ' + JSON.stringify(nfts, null, 2) results += '\n\nnfts: ' + JSON.stringify(nfts, null, 2)
document.getElementById('operationalBalanceField').value = operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
(await client.getXrpBalance(operational_wallet.address)) operationalResultField.value = results
document.getElementById('operationalResultField').value = results
client.disconnect() client.disconnect()
} //End of oPmintToken } //End of oPmintToken
// ******************************************************* // *******************************************************
// ************** Operational Get Tokens ***************** // ************** Operational Get Tokens *****************
// ******************************************************* // *******************************************************
async function oPgetTokens() { async function oPgetTokens() {
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '...' results = 'Connecting to ' + getNet() + '...'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
await client.connect() await client.connect()
results += '\nConnected. Getting NFTokens...' results += '\nConnected. Getting NFTokens...'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
const nfts = await client.request({ const nfts = await client.request({
method: "account_nfts", method: "account_nfts",
account: operational_wallet.classicAddress account: operational_wallet.classicAddress
}) })
results += '\nNFTs:\n ' + JSON.stringify(nfts,null,2) results += '\nNFTs:\n ' + JSON.stringify(nfts,null,2)
document.getElementById('operationalResultField').value = results operationalResultField.value = results
client.disconnect() client.disconnect()
} //End of oPgetTokens } //End of oPgetTokens
// ******************************************************* // *******************************************************
// ************* Operational Burn Token ****************** // ************* Operational Burn Token ******************
@@ -420,10 +350,10 @@ async function oPburnToken() {
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
results = 'Connecting to ' + getNet() + '...' results = 'Connecting to ' + getNet() + '...'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
await client.connect() await client.connect()
results += '\nConnected. Burning NFToken...' results += '\nConnected. Burning NFToken...'
document.getElementById('operationalResultField').value = results operationalResultField.value = results
// ------------------------------------------------------- Prepare transaction // ------------------------------------------------------- Prepare transaction
const transactionBlob = { const transactionBlob = {
@@ -436,35 +366,36 @@ async function oPburnToken() {
const tx = await client.submitAndWait(transactionBlob,{wallet: operational_wallet}) const tx = await client.submitAndWait(transactionBlob,{wallet: operational_wallet})
const nfts = await client.request({ const nfts = await client.request({
method: "account_nfts", method: "account_nfts",
account: operational_wallet.classicAddress account: operational_wallet.classicAddress
}) })
results += '\nTransaction result: '+ tx.result.meta.TransactionResult results += '\nTransaction result: '+ tx.result.meta.TransactionResult
results += '\nBalance changes: ' + results += '\nBalance changes: ' +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
document.getElementById('operationalResultField').value = results operationalResultField.value = results
document.getElementById('operationalBalanceField').value = operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
(await client.getXrpBalance(operational_wallet.address)) operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
document.getElementById('operationalBalanceField').value =
(await client.getXrpBalance(operational_wallet.address))
results += '\nNFTs: \n' + JSON.stringify(nfts,null,2) results += '\nNFTs: \n' + JSON.stringify(nfts,null,2)
document.getElementById('operationalResultField').value = results operationalResultField.value = results
client.disconnect() client.disconnect()
} }
// End of oPburnToken() // End of oPburnToken()
``` ```
## 3.mint-nfts.html ## 3.mint-nfts.html
Bold text in the following indicates changes to the form that support the new functions. ```html
```
<html> <html>
<head> <head>
<title>Token Test Harness</title> <title>Token Test Harness</title>
<script src='https://unpkg.com/xrpl@2.2.3'></script> <link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
<style>
body{font-family: "Work Sans", sans-serif;padding: 20px;background: #fafafa;}
h1{font-weight: bold;}
input, button {padding: 6px;margin-bottom: 8px;}
button{font-weight: bold;font-family: "Work Sans", sans-serif;}
td{vertical-align: middle;}
</style>
<script src='https://unpkg.com/xrpl@2.7.0/build/xrpl-latest-min.js'></script>
<script src='ripplex1-send-xrp.js'></script> <script src='ripplex1-send-xrp.js'></script>
<script src='ripplex2-send-currency.js'></script> <script src='ripplex2-send-currency.js'></script>
<script src='ripplex3-mint-nfts.js'></script> <script src='ripplex3-mint-nfts.js'></script>
@@ -482,7 +413,8 @@ Bold text in the following indicates changes to the form that support the new fu
<body> <body>
<h1>Token Test Harness</h1> <h1>Token Test Harness</h1>
<form id="theForm"> <form id="theForm">
Choose your ledger instance:&nbsp;&nbsp; Choose your ledger instance:
&nbsp;&nbsp;
<input type="radio" id="tn" name="server" <input type="radio" id="tn" name="server"
value="wss://s.altnet.rippletest.net:51233" checked> value="wss://s.altnet.rippletest.net:51233" checked>
<label for="testnet">Testnet</label> <label for="testnet">Testnet</label>
@@ -772,16 +704,4 @@ Bold text in the following indicates changes to the form that support the new fu
</form> </form>
</body> </body>
</html> </html>
```
```
---
| Previous | Next |
| :--- | ---: |
| [← 2. Create Trust Line and Send Currency >](create-trustline-send-currency.html) | [4. Transfer NFTokens → >](transfer-nftokens.html) |
<!--{# common link defs #}-->
{% include '_snippets/rippled-api-links.md' %}
{% include '_snippets/tx-type-links.md' %}
{% include '_snippets/rippled_versions.md' %}

File diff suppressed because it is too large Load Diff

View File

@@ -54,10 +54,4 @@ To get started, create a new folder on your local disk and install the JavaScrip
Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive. Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/quickstart.zip){.github-code-download} archive.
**Note:** Without the Quickstart Samples, you will not be able to try the examples that follow. **Note:** Without the Quickstart Samples, you will not be able to try the examples that follow.
---
| Previous | Next |
| :--- | ---: |
| | [1. Create Accounts and Send XRP → >](create-accounts-send-xrp.html) |

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB