diff --git a/content/_code-samples/quickstart/js/quickstart.zip b/content/_code-samples/quickstart/js/quickstart.zip index 5cf9726500..ff78e91848 100644 Binary files a/content/_code-samples/quickstart/js/quickstart.zip and b/content/_code-samples/quickstart/js/quickstart.zip differ diff --git a/content/tutorials/quickstart/authorize-minter.md b/content/tutorials/quickstart/authorize-minter.md index e34c33372d..d7d7fa5a62 100644 --- a/content/tutorials/quickstart/authorize-minter.md +++ b/content/tutorials/quickstart/authorize-minter.md @@ -102,7 +102,7 @@ This function sets the authorized minter for an account. Each account can have 0 // **************** Set Minter ************************* // ******************************************************* -async function setMinter(type) { +async function setMinter() { ``` Connect to the ledger and get the account. @@ -111,19 +111,18 @@ Connect to the ledger and get the account. let net = getNet() const client = new xrpl.Client(net) results = 'Connecting to ' + getNet() + '....' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results await client.connect() results += '\nConnected, finding wallet.' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results 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. ```javascript tx_json = { - "TransactionType": "AccountSet", + "TransactionType": "AccountSet", "Account": my_wallet.address, ``` @@ -143,30 +142,30 @@ Set the `asfAuthorizedNFTokenMinter` flag (the numeric value is _10_). Report progress. ```javascript - results += '\n Set Minter.' - document.getElementById('standbyResultField').value = results + results += '\nSet Minter.' + standbyResultField.value = results ``` Prepare and send the transaction, then wait for results ```javascript - const prepared = await client.autofill(tx_json) - const signed = my_wallet.sign(prepared) - const result = await client.submitAndWait(signed.tx_json) + const prepared = await client.autofill(tx_json) + const signed = my_wallet.sign(prepared) + const result = await client.submitAndWait(signed.tx_blob) ``` If the transaction succeeds, show the results. If not, report that the transaction failed. ```javascript - if (result.result.meta.TransactionResult == "tesSUCCESS") { - results += '\nAccount setting succeeded.' + if (result.result.meta.TransactionResult == "tesSUCCESS") { + results += '\nAccount setting succeeded.\n' results += JSON.stringify(result,null,2) - document.getElementById('standbyResultField').value = results - } else { + standbyResultField.value = results + } else { throw 'Error sending transaction: ${result}' results += '\nAccount setting failed.' - document.getElementById('standbyResultField').value = results - } + standbyResultField.value = results + } ``` Disconnect from the XRP Ledger. @@ -193,7 +192,7 @@ Connect to the ledger and get the account. ```javascript results = 'Connecting to ' + getNet() + '....' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results let net = getNet() const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const client = new xrpl.Client(net) @@ -203,13 +202,13 @@ Report success ```javascript 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. ```javascript - const transactionBlob = { + const tx_json = { "TransactionType": "NFTokenMint", "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. ```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({ method: "account_nfts", - account: standby_wallet.classicAddress + account: standby_wallet.classicAddress }) ``` @@ -260,10 +259,9 @@ Report the results. ```javascript results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult results += '\n\nnfts: ' + JSON.stringify(nfts, null, 2) - document.getElementById('standbyBalanceField').value = - (await client.getXrpBalance(standby_wallet.address)) - document.getElementById('standbyResultField').value = results - + standbyResultField.value = results + (await + client.getXrpBalance(standby_wallet.address)) + standbyResultField.value = results ``` Disconnect from the XRP Ledger. @@ -279,19 +277,19 @@ These functions duplicate the functions of the standby account for the operation ```javascript // ******************************************************* -// *********** Operational Set Minter ******************* -// ******************************************************* +// **************** Set Operational Minter ************** +// ******************************************************** -async function oPsetMinter(type) { +async function oPsetMinter() { let net = getNet() const client = new xrpl.Client(net) results = 'Connecting to ' + getNet() + '....' - document.getElementById('operationalResultField').value = results + operationalResultField.value = results await client.connect() results += '\nConnected, finding wallet.' - document.getElementById('operationalResultField').value = results + operationalResultField.value = results my_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) - document.getElementById('operationalResultField').value = results + operationalResultField.value = results tx_json = { "TransactionType": "AccountSet", @@ -299,24 +297,25 @@ async function oPsetMinter(type) { "NFTokenMinter": operationalMinterField.value, "SetFlag": xrpl.AccountSetAsfFlags.asfAuthorizedNFTokenMinter } - results += '\n Set Minter.' - document.getElementById('operationalResultField').value = results + results += '\nSet Minter.' + operationalResultField.value = results - const prepared = await client.autofill(tx_json) - const signed = my_wallet.sign(prepared) - const result = await client.submitAndWait(signed.tx_json) - if (result.result.meta.TransactionResult == "tesSUCCESS") { - results += '\nAccount setting succeeded.' + const prepared = await client.autofill(tx_json) + const signed = my_wallet.sign(prepared) + const result = await client.submitAndWait(signed.tx_blob) + if (result.result.meta.TransactionResult == "tesSUCCESS") { + results += '\nAccount setting succeeded.\n' results += JSON.stringify(result,null,2) - document.getElementById('operationalResultField').value = results - } else { + operationalResultField.value = results + } else { throw 'Error sending transaction: ${result}' results += '\nAccount setting failed.' - document.getElementById('operationalResultField').value = results - } + operationalResultField.value = results + } client.disconnect() -} // End of configureAccount() +} // End of oPsetMinter() + // ******************************************************* // ************** Operational Mint Other ***************** @@ -324,17 +323,17 @@ async function oPsetMinter(type) { async function oPmintOther() { results = 'Connecting to ' + getNet() + '....' - document.getElementById('operationalResultField').value = results + operationalResultField.value = results let net = getNet() const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) const client = new xrpl.Client(net) await client.connect() results += '\nConnected. Minting NFToken.' - document.getElementById('operationalResultField').value = results + operationalResultField.value = results // This version adds the "Issuer" field. // ------------------------------------------------------------------------ - const transactionBlob = { + const tx_json = { "TransactionType": 'NFTokenMint', "Account": operational_wallet.classicAddress, "URI": xrpl.convertStringToHex(operationalTokenUrlField.value), @@ -345,7 +344,7 @@ async function oPmintOther() { } // ----------------------------------------------------- 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({ method: "account_nfts", account: operational_wallet.classicAddress @@ -354,10 +353,8 @@ async function oPmintOther() { // ------------------------------------------------------- Report results results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult results += '\n\nnfts: ' + JSON.stringify(nfts, null, 2) - document.getElementById('operationalBalanceField').value = - (await client.getXrpBalance(operational_wallet.address)) - document.getElementById('operationalResultField').value = results - + results += await client.getXrpBalance(operational_wallet.address) + operationalResultField.value = results client.disconnect() } //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;} td{vertical-align: middle;} - + @@ -399,7 +396,7 @@ Update the form with fields and buttons to support the new functions.

Token Test Harness

- Choose your ledger instance: + Choose your ledger instance:    @@ -754,8 +751,3 @@ Update the form with fields and buttons to support the new functions. ``` - -| Previous | Next | -| :--- | ---: | -| [← Broker a NFToken Sale >](broker-sale.html) | [Batch Mint NFTokens → >](batch-minting.html) | - diff --git a/content/tutorials/quickstart/batch-minting.md b/content/tutorials/quickstart/batch-minting.md index 7d70a9e42e..aa6b63fee6 100644 --- a/content/tutorials/quickstart/batch-minting.md +++ b/content/tutorials/quickstart/batch-minting.md @@ -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. +[![Batch Mint](img/quickstart33-batch-mint.png)](img/quickstart33-batch-mint.png) + ## 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. @@ -66,16 +68,16 @@ async function getAccountFromSeed() { let net = getNet() const client = new xrpl.Client(net) results = 'Connecting to ' + getNet() + '....' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results await client.connect() results += '\nConnected, finding wallets.\n' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` Use the seed to derive the account. ```javascript - var theSeed = document.getElementById('seeds').value + var theSeed = seeds.value const standby_wallet = xrpl.Wallet.fromSeed(theSeed) ``` @@ -88,12 +90,11 @@ Get the current XRP balance. Populate the fields for Standby account. ```javascript - 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)) + 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)) ``` 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. ```javascript +// ******************************************************* +// **************** Get Batch Tokens ********************* +// ******************************************************* + async function getBatchNFTokens() { ``` @@ -118,10 +123,10 @@ Connect to the XRP Ledger and get the account. let net = getNet() const client = new xrpl.Client(net) results = 'Connecting to ' + net + '...' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results await client.connect() 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. @@ -142,10 +147,10 @@ If the list of `NFTokens` exceeds your limit, the result includes a `marker` fie while (nfts.result.marker) { nfts = await client.request({ - method: "account_nfts", - account: standby_wallet.classicAddress, - limit: 400, - marker: nfts.result.marker + method: "account_nfts", + account: standby_wallet.classicAddress, + limit: 400, + marker: nfts.result.marker }) 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. ```javascript - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` Disconnect from the XRP Ledger. @@ -169,6 +174,10 @@ Disconnect from the XRP Ledger. This script mints multiple copies of the same NFToken. ```javascript +// ******************************************************* +// ****************** Batch Mint *********************** +// ******************************************************* + async function batchMint() { ``` @@ -178,12 +187,12 @@ Connect to the XRP Ledger and get the account. let net = getNet() const client = new xrpl.Client(net) results = 'Connecting to ' + getNet() + '....' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results await client.connect() results += '\nConnected, finding wallet.' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` 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 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. @@ -249,7 +258,7 @@ Report the function progress. ```javascript 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. @@ -292,7 +301,7 @@ Use the same logic as `getBatchNFTokens`, above, to get the list of current NFTo }) results += JSON.stringify(nfts,null,2) - while (nfts.result.marker != null) + while (nfts.result.marker) { nfts = await client.request({ method: "account_nfts", @@ -309,9 +318,8 @@ Report the results. ```javascript results += '\n\nTransaction result: '+ tx.result.meta.TransactionResult results += '\n\nnftokens: ' + JSON.stringify(nfts, null, 2) - document.getElementById('standbyBalanceField').value = - (await client.getXrpBalance(standby_wallet.address)) - document.getElementById('standbyResultField').value = results + standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) + standbyResultField.value = results ``` Disconnect from the XRP Ledger. @@ -340,7 +348,7 @@ For this form: button{font-weight: bold;font-family: "Work Sans", sans-serif;} td{vertical-align: middle;} - + @@ -359,7 +367,7 @@ For this form:

Token Test Harness

- Choose your ledger instance: + Choose your ledger instance:    @@ -455,37 +463,35 @@ For this form: NFToken Count - - - -
- - - - Transfer Fee - - - - - - - - -
- -
-

- -

- + + + +
+ + + + Transfer Fee + + + + + + +
+ +
+

+ + + + +

+ + +
``` - -| Previous | Next | -| :--- | ---: | -| [← Authorize Minter >](authorize-minter.html) | | - diff --git a/content/tutorials/quickstart/broker-sale.md b/content/tutorials/quickstart/broker-sale.md index ec7b8f0b6c..a5816ca174 100644 --- a/content/tutorials/quickstart/broker-sale.md +++ b/content/tutorials/quickstart/broker-sale.md @@ -21,7 +21,7 @@ This example shows how to: 2. Get a list of offers for the brokered item. 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. @@ -38,7 +38,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port 2. Click **Get New Operational 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 @@ -51,7 +51,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port 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. 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**. 5. Click **Create Buy Offer**. -![Buy Offer](img/quickstart24.png) +[![Buy Offer](img/quickstart24.png)](img/quickstart24.png) ## Get Offers 1. Enter the **NFToken ID**. 2. Click **Get Offers**. -![Get Offers](img/quickstart25.png) +[![Get Offers](img/quickstart25.png)](img/quickstart25.png) ## 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. 4. Click **Broker Sale**. -![Brokered Sale](img/quickstart26.png) +[![Brokered Sale](img/quickstart26.png)](img/quickstart26.png) ## 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. 2. Click **Cancel Offer**. -![Cancel Offer](img/quickstart27.png) +[![Cancel Offer](img/quickstart27.png)](img/quickstart27.png) # Code Walkthrough @@ -99,26 +99,29 @@ This script has new functions for brokered transactions and revised functions to ## Broker Get Offers -``` +```javascript +// ******************************************************* +// *************** Broker Get Offers ********************* +// ******************************************************* + async function brGetOffers() { ``` Connect to the ledger. -``` - const standby_wallet = xrpl.Wallet.fromSeed(brokerSeedField.value) +```javascript let net = getNet() const client = new xrpl.Client(net) results = 'Connecting to ' + getNet() + '...' - document.getElementById('brokerResultField').value = results + brokerResultField.value = results await client.connect() results += '\nConnected. Getting offers...' - document.getElementById('brokerResultField').value = results + brokerResultField.value = results ``` Request the list of sell offers for the token. -``` +```javascript results += '\n\n***Sell Offers***\n' let nftSellOffers try { @@ -130,57 +133,57 @@ Request the list of sell offers for the token. nftSellOffers = 'No sell offers.' } results += JSON.stringify(nftSellOffers,null,2) - document.getElementById('brokerResultField').value = results + brokerResultField.value = results ``` Request the list of buy offers for the token. -``` +```javascript results += '\n\n***Buy Offers***\n' let nftBuyOffers try { nftBuyOffers = await client.request({ method: "nft_buy_offers", - nft_id: brokerTokenIdField.value }) - } catch (err) { + nft_id: brokerTokenIdField.value + }) + } catch (err) { nftBuyOffers = 'No buy offers.' } results += JSON.stringify(nftBuyOffers,null,2) - - document.getElementById('brokerResultField').value = results + brokerResultField.value = results ``` Disconnect from the ledger. -``` +```javascript client.disconnect() }// End of brGetOffers() ``` ## Broker Sale -``` +```javascript async function brokerSale() { ``` Connect to the ledger and get the accounts. -``` - const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) - const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) - const broker_wallet = xrpl.Wallet.fromSeed (brokerSeedField.value) - let net = getNet() - const client = new xrpl.Client(net) - results = 'Connecting to ' + getNet() + '...' - document.getElementById('brokerResultField').value = results - await client.connect() - results += '\nConnected. Brokering sale...' - document.getElementById('brokerResultField').value = results +```javascript + const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) + const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) + const broker_wallet = xrpl.Wallet.fromSeed (brokerSeedField.value) + let net = getNet() + const client = new xrpl.Client(net) + results = 'Connecting to ' + getNet() + '...' + brokerResultField.value = results + await client.connect() + results += '\nConnected. Brokering sale...' + 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. -``` +```javascript const transactionBlob = { "TransactionType": "NFTokenAcceptOffer", "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. -``` +```javascript const tx = await client.submitAndWait(transactionBlob,{wallet: broker_wallet}) ``` Report the results. -``` - results += "\n\nTransaction result:\n" + - JSON.stringify(tx.result.meta.TransactionResult, null, 2) - results += "\nBalance changes:\n" + - JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) - document.getElementById('operationalBalanceField').value = - (await client.getXrpBalance(operational_wallet.address)) - document.getElementById('standbyBalanceField').value = - (await client.getXrpBalance(standby_wallet.address)) - document.getElementById('brokerBalanceField').value = - (await client.getXrpBalance(broker_wallet.address)) - document.getElementById('brokerResultField').value = results +```javascript + results += "\n\nTransaction result:\n" + + JSON.stringify(tx.result.meta.TransactionResult, null, 2) + results += "\nBalance changes:\n" + + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address)) + standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) + brokerBalanceField.value = (await client.getXrpBalance(broker_wallet.address)) + brokerResultField.value = results ``` Disconnect from the ledger. -``` +```javascript client.disconnect() }// End of brokerSale() ``` ## Broker Cancel Offer -``` +```javascript +// ******************************************************* +// ************* Broker Cancel Offer **************** +// ******************************************************* + + async function brCancelOffer() { ``` Get the broker account and connect to the ledger. -``` +```javascript const wallet = xrpl.Wallet.fromSeed(brokerSeedField.value) - let net = getNet() - const client = new xrpl.Client(net) - results = 'Connecting to ' + net + '...' - document.getElementById('brokerResultField').value = results + let net = getNet() + const client = new xrpl.Client(net) + results = 'Connecting to ' + getNet() + '...' + brokerResultField.value = results await client.connect() results += "\nConnected. Cancelling offer..." - document.getElementById('brokerResultField').value = results + brokerResultField.value = results ``` The Token ID must be converted to an array. -``` +```javascript const tokenOfferIDs = [brokerTokenBuyOfferIndexField.value] ``` Prepare the transaction. -``` +```javascript const transactionBlob = { "TransactionType": "NFTokenCancelOffer", "Account": wallet.classicAddress, @@ -256,13 +261,13 @@ Prepare the transaction. Submit the transaction and wait for the results. -``` +```javascript const tx = await client.submitAndWait(transactionBlob,{wallet}) ``` Get the sell offers and report the results. -``` +```javascript results += "\n\n***Sell Offers***\n" let nftSellOffers try { @@ -278,7 +283,7 @@ Get the sell offers and report the results. Get the buy offers and report the results. -``` +```javascript results += "\n\n***Buy Offers***\n" let nftBuyOffers try { @@ -293,7 +298,7 @@ Get the buy offers and report the results. Report the transaction results. -``` +```javascript results += "\nTransaction result:\n" + JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += "\nBalance changes:\n" + @@ -303,7 +308,7 @@ Report the transaction results. Disconnect from the ledger. -``` +```javascript client.disconnect() }// 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. -``` +```javascript +// *************************************************************************** +// ************** Revised Functions ****************************************** +// *************************************************************************** + +// ******************************************************* +// ************* Get Account ***************************** +// ******************************************************* + + async function getAccount(type) { ``` Connect to the ledger. -``` +```javascript let net = getNet() const client = new xrpl.Client(net) results = 'Connecting to ' + net + '....' @@ -325,105 +339,105 @@ Connect to the ledger. Get the correct network host. -``` +```javascript + let net = getNet() + const client = new xrpl.Client(net) + results = 'Connecting to ' + net + '....' + let faucetHost = null - if (type == 'standby') { - document.getElementById('standbyResultField').value = results + standbyResultField.value = results } if (type == 'operational') { - document.getElementById('operationalResultField').value = results + operationalResultField.value = results } if (type == 'broker') { - document.getElementById('brokerResultField').value = results + brokerResultField.value = results } ``` Connect to the ledger. -``` - +```javascript await client.connect() results += '\nConnected, funding wallet.' if (type == 'standby') { - document.getElementById('standbyResultField').value = results + standbyResultField.value = results } if (type == 'operational') { - document.getElementById('operationalResultField').value = results + operationalResultField.value = results } if (type == 'broker') { - document.getElementById('brokerResultField').value = results + brokerResultField.value = results } ``` Create and fund a test account and report progress. -``` -const my_wallet = (await client.fundWallet(null, { faucetHost })).wallet +```javascript + const my_wallet = (await client.fundWallet(null, { faucetHost })).wallet results += '\nGot a wallet.' if (type == 'standby') { - document.getElementById('standbyResultField').value = results + standbyResultField.value = results } if (type == 'operational') { - document.getElementById('operationalResultField').value = results + operationalResultField.value = results } if (type == 'broker') { - document.getElementById('brokerResultField').value = results + brokerResultField.value = results } ``` Get the XRP balance for the new account. -``` - const my_balance = (await client.getXrpBalance(my_wallet.address)) +```javascript + const my_balance = (await client.getXrpBalance(my_wallet.address)) ``` Populate the form fields for the appropriate account with the new account information. -``` +```javascript if (type == 'standby') { - document.getElementById('standbyAccountField').value = my_wallet.address - document.getElementById('standbyPubKeyField').value = my_wallet.publicKey - document.getElementById('standbyPrivKeyField').value = my_wallet.privateKey - document.getElementById('standbyBalanceField').value = - (await client.getXrpBalance(my_wallet.address)) - document.getElementById('standbySeedField').value = my_wallet.seed + standbyAccountField.value = my_wallet.address + standbyPubKeyField.value = my_wallet.publicKey + standbyPrivKeyField.value = my_wallet.privateKey + standbyBalanceField.value = (await client.getXrpBalance(my_wallet.address)) + standbySeedField.value = my_wallet.seed results += '\nStandby account created.' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results } if (type == 'operational') { - document.getElementById('operationalAccountField').value = my_wallet.address - document.getElementById('operationalPubKeyField').value = my_wallet.publicKey - document.getElementById('operationalPrivKeyField').value = my_wallet.privateKey - document.getElementById('operationalSeedField').value = my_wallet.seed - document.getElementById('operationalBalanceField').value = - (await client.getXrpBalance(my_wallet.address)) + operationalAccountField.value = my_wallet.address + operationalPubKeyField.value = my_wallet.publicKey + operationalPrivKeyField.value = my_wallet.privateKey + operationalSeedField.value = my_wallet.seed + operationalBalanceField.value = (await client.getXrpBalance(my_wallet.address)) results += '\nOperational account created.' - document.getElementById('operationalResultField').value = results + operationalResultField.value = results } if (type == 'broker') { - document.getElementById('brokerAccountField').value = my_wallet.address - document.getElementById('brokerPubKeyField').value = my_wallet.publicKey - document.getElementById('brokerPrivKeyField').value = my_wallet.privateKey - document.getElementById('brokerSeedField').value = my_wallet.seed - document.getElementById('brokerBalanceField').value = - (await client.getXrpBalance(my_wallet.address)) + brokerAccountField.value = my_wallet.address + brokerPubKeyField.value = my_wallet.publicKey + brokerPrivKeyField.value = my_wallet.privateKey + brokerSeedField.value = my_wallet.seed + brokerBalanceField.value = (await client.getXrpBalance(my_wallet.address)) 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. -``` -document.getElementById('seeds').value = standbySeedField.value + '\n' + operationalSeedField.value + "\n" + brokerSeedField.value +```javascript + seeds.value = standbySeedField.value + '\n' + operationalSeedField.value + "\n" + + brokerSeedField.value ``` Disconnect from the ledger. -``` +```javascript client.disconnect() } // End of getAccount() ``` @@ -432,31 +446,31 @@ Disconnect from the ledger. Override the `getAccountsFromSeeds()` function to include the broker account fields. -``` +```javascript async function getAccountsFromSeeds() { ``` Connect to the ledger. -``` - 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 +```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 ``` Use the `split` function to parse the values from the **Seeds** field. -``` +```javascript var lines = seeds.value.split('\n'); ``` Derive the accounts from the seed values. -``` +```javascript const standby_wallet = xrpl.Wallet.fromSeed(lines[0]) const operational_wallet = xrpl.Wallet.fromSeed(lines[1]) 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. -``` +```javascript const standby_balance = (await client.getXrpBalance(standby_wallet.address)) const operational_balance = (await client.getXrpBalance(operational_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. -``` - 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)) +```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)) - 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)) + 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('brokerAccountField').value = broker_wallet.address - document.getElementById('brokerPubKeyField').value = broker_wallet.publicKey - document.getElementById('brokerPrivKeyField').value = broker_wallet.privateKey - document.getElementById('brokerSeedField').value = broker_wallet.seed - document.getElementById('brokerBalanceField').value = - (await client.getXrpBalance(broker_wallet.address)) + brokerAccountField.value = broker_wallet.address + brokerPubKeyField.value = broker_wallet.publicKey + brokerPrivKeyField.value = broker_wallet.privateKey + brokerSeedField.value = broker_wallet.seed + brokerBalanceField.value = (await client.getXrpBalance(broker_wallet.address)) ``` Disconnect from the ledger. -``` +```javascript client.disconnect() ``` Use the `getBalances()` function to get the current balances of fiat currency. -``` +```javascript getBalances() } // 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. -``` +```javascript +// ******************************************************* +// ****************** Get Balances *********************** +// ******************************************************* + async function getBalances() { ``` Connect with the ledger. -``` +```javascript let net = getNet() const client = new xrpl.Client(net) results = 'Connecting to ' + getNet() + '....' @@ -533,7 +548,7 @@ Connect with the ledger. Derive each of the three accounts. -``` +```javascript const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.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. -``` - results= "\nGetting standby account balances...\n" +```javascript + results = "\nGetting standby account balances...\n" const standby_balances = await client.request({ command: "gateway_balances", account: standby_wallet.address, @@ -550,12 +565,12 @@ Get and report the Standby account balances. hotwallet: [operational_wallet.address] }) results += JSON.stringify(standby_balances.result, null, 2) - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` Get and report the Operational account balances. -``` +```javascript results= "\nGetting operational account balances...\n" const operational_balances = await client.request({ command: "account_lines", @@ -563,12 +578,12 @@ Get and report the Operational account balances. ledger_index: "validated" }) results += JSON.stringify(operational_balances.result, null, 2) - document.getElementById('operationalResultField').value = results + operationalResultField.value = results ``` Get and report the Broker account balances. -``` +```javascript results= "\nGetting broker account balances...\n" const broker_balances = await client.request({ command: "account_lines", @@ -576,35 +591,41 @@ Get and report the Broker account balances. ledger_index: "validated" }) results += JSON.stringify(broker_balances.result, null, 2) - document.getElementById('brokerResultField').value = results + brokerResultField.value = results ``` Update the XRP balances for the three accounts. -``` - document.getElementById('operationalBalanceField').value = - (await client.getXrpBalance(operational_wallet.address)) - document.getElementById('standbyBalanceField').value = - (await client.getXrpBalance(standby_wallet.address)) - document.getElementById('brokerBalanceField').value = - (await client.getXrpBalance(broker_wallet.address)) +```javascript + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address)) + standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) + brokerBalanceField.value = (await client.getXrpBalance(broker_wallet.address)) ``` Disconnect from the ledger. -``` +```javascript client.disconnect() } // end of getBalances() ``` + ## 5.broker-nfts.html Revise the HTML form to add a new Broker section at the top. -``` +```html Token Test Harness - + + + @@ -623,7 +644,7 @@ Revise the HTML form to add a new Broker section at the top.

Token Test Harness

- Choose your ledger instance: + Choose your ledger instance:    @@ -1039,10 +1060,5 @@ Revise the HTML form to add a new Broker section at the top.
- + ``` - - -| Previous | Next | -| :--- | ---: | -| [← 4. Transfer NFTokens >](transfer-nftokens.html) | [Authorize Minter → >](authorize-minter.html)| diff --git a/content/tutorials/quickstart/create-accounts-send-xrp.md b/content/tutorials/quickstart/create-accounts-send-xrp.md index dd83370c93..288088d858 100644 --- a/content/tutorials/quickstart/create-accounts-send-xrp.md +++ b/content/tutorials/quickstart/create-accounts-send-xrp.md @@ -12,26 +12,22 @@ labels: This example shows how to: - -1. Create accounts on the Testnet, funded with 10000 test XRP with no actual value. +1. Create accounts on the Testnet, funded with 1000 test XRP with no actual value. 2. Retrieve the accounts from seed values. 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. - -![Token Test Harness](img/quickstart2.png) +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)](img/quickstart2.png) ## Prerequisites To get started, create a new folder on your local disk and install the JavaScript library using `npm`. - ``` 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. **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: - - 1. Open `1.get-accounts-send-xrp.html` in a browser 2. Choose **Testnet** or **Devnet**. 3. Click **Get New Standby 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. - - -![Standby and Operational Accounts](img/quickstart3.png) +[![Standby and Operational Accounts](img/quickstart3.png)](img/quickstart3.png) 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. -2. Enter the **Destination** account (for example, 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, or **<Send XRP** to transfer XRP from the operational account to the standby account. - - - -![Transferred XRP](img/quickstart4.png) - +1. On the Operational (right) side of the form, enter the **Amount** of XRP to send. +2. Copy and paste the **Standby Account** field to the Standby **Destination** field. +3. Click **<Send XRP** to transfer XRP from the Operational account to the Standby account. +[![Transferred XRP](img/quickstart4.png)](img/quickstart4.png) # 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. - - ## 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. - ### getNet() @@ -90,433 +79,327 @@ This example can be used with any XRP Ledger network, _Testnet_, or _Devnet_. Yo function getNet() { ``` - This function uses brute force `if` statements to discover the selected network instance and return the URI. - ```javascript - let net - if (document.getElementById("tn").checked) net = "wss://s.altnet.rippletest.net:51233" - if (document.getElementById("dn").checked) net = "wss://s.devnet.rippletest.net:51233" - return net - } // End of getNet() + let net + if (document.getElementById("tn").checked) net = "wss://s.altnet.rippletest.net:51233" + if (document.getElementById("dn").checked) net = "wss://s.devnet.rippletest.net:51233" + return net +} // End of getNet() ``` - - ### getAccount(type) - ```javascript // ******************************************************* // ************* Get Account ***************************** // ******************************************************* - - async function getAccount(type) { +async function getAccount(type) { ``` - Get the selected ledger. - ```javascript - let net = getNet() + let net = getNet() ``` - Instantiate a client. - ```javascript - const client = new xrpl.Client(net) + const client = new xrpl.Client(net) ``` - Use the _results_ variable to capture progress information. - ```javascript - results = 'Connecting to ' + net + '....' + results = 'Connecting to ' + net + '....' ``` - Use the default faucet using a _null_ value. ```javascript - let faucetHost = null + let faucetHost = null ``` - Report progress in the appropriate results field. - ```javascript - if (type == 'standby') { - document.getElementById('standbyResultField').value = results - } else { - document.getElementById('operationalResultField').value = results - } + if (type == 'standby') { + standbyResultField.value = results + } else { + operationalResultField.value = results + } ``` - Connect to the server. - ```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. - ```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. - ```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. - ```javascript - if (type == 'standby') { - document.getElementById('standbyAccountField').value = my_wallet.address - document.getElementById('standbyPubKeyField').value = my_wallet.publicKey - document.getElementById('standbyPrivKeyField').value = my_wallet.privateKey - document.getElementById('standbyBalanceField').value = - (await client.getXrpBalance(my_wallet.address)) - document.getElementById('standbySeedField').value = my_wallet.seed - results += '\nStandby account created.' - document.getElementById('standbyResultField').value = results + if (type == 'standby') { + standbyAccountField.value = my_wallet.address + standbyPubKeyField.value = my_wallet.publicKey + standbyPrivKeyField.value = my_wallet.privateKey + standbyBalanceField.value = (await client.getXrpBalance(my_wallet.address)) + standbySeedField.value = my_wallet.seed + results += '\nStandby account created.' + standbyResultField.value = results ``` - Otherwise, populate the operational account fields. - ```javascript - } else { - document.getElementById('operationalAccountField').value = my_wallet.address - document.getElementById('operationalPubKeyField').value = my_wallet.publicKey - document.getElementById('operationalPrivKeyField').value = my_wallet.privateKey - document.getElementById('operationalSeedField').value = my_wallet.seed - document.getElementById('operationalBalanceField').value = - (await client.getXrpBalance(my_wallet.address)) - results += '\nOperational account created.' - document.getElementById('operationalResultField').value = results - } + } else { + operationalAccountField.value = my_wallet.address + operationalPubKeyField.value = my_wallet.publicKey + operationalPrivKeyField.value = my_wallet.privateKey + operationalSeedField.value = my_wallet.seed + operationalBalanceField.value = (await client.getXrpBalance(my_wallet.address)) + results += '\nOperational account created.' + 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. - ```javascript - document.getElementById('seeds').value = standbySeedField.value + '\n' + operationalSeedField.value + seeds.value = standbySeedField.value + '\n' + operationalSeedField.value ``` - Disconnect from the XRP ledger. - +```javascript + client.disconnect() +} // End of getAccount() ``` - client.disconnect() - } // End of getAccount() -``` - - ### Get Accounts from Seeds - ```javascript // ******************************************************* // ********** Get Accounts from Seeds ******************** // ******************************************************* - async function getAccountsFromSeeds() { +async function getAccountsFromSeeds() { ``` - 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. - +```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. - +```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. - +```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. - +```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. - +```javascript + client.disconnect() +} // End of getAccountsFromSeeds() ``` - client.disconnect() - - - } // End of getAccountsFromSeeds() -``` - - ### Send XRP - -``` +```javascript // ******************************************************* // ******************** Send XRP ************************* // ******************************************************* - async function sendXRP() { +async function sendXRP() { ``` - Connect to your selected ledger. - -``` - - - results = "Connecting to the selected ledger.\n" - document.getElementById('standbyResultField').value = results - let net = getNet() - results = 'Connecting to ' + getNet() + '....' - const client = new xrpl.Client(net) - await client.connect() - - - results += "\nConnected. Sending XRP.\n" - document.getElementById('standbyResultField').value = results - - - const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) - const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) - const sendAmount = standbyAmountField.value - - - results += "\nstandby_wallet.address: = " + standby_wallet.address - document.getElementById('standbyResultField').value = results - - +```javascript + results = "Connecting to the selected ledger.\n" + standbyResultField.value = results + let net = getNet() + results = 'Connecting to ' + getNet() + '....' + const client = new xrpl.Client(net) + await client.connect() + + results += "\nConnected. Sending XRP.\n" + standbyResultField.value = results + + const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) + const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) + const sendAmount = standbyAmountField.value + + results += "\nstandby_wallet.address: = " + standby_wallet.address + standbyResultField.value = results ``` 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). - +```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. - ``` - const signed = standby_wallet.sign(prepared) - - + const signed = standby_wallet.sign(prepared) ``` - 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. - ``` + results += "\nBalance changes: " + + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) + standbyResultField.value = results - - 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)) - document.getElementById('operationalBalanceField').value = - (await client.getXrpBalance(operational_wallet.address)) - client.disconnect() - - - } // End of sendXRP() + standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address)) + client.disconnect() +} // End of sendXRP() ``` - - ### 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. - -``` +```javascript // ********************************************************************** -// ****** Reciprocal Transactions **************************************** +// ****** Reciprocal Transactions *************************************** // ********************************************************************** - - + // ******************************************************* // ********* 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) - - results = "Connecting to testnet.\n" - document.getElementById('operationalResultField').value = results - let net = getNet() - results = 'Connecting to ' + getNet() + '....' - const client = new xrpl.Client(net) - await client.connect() - - - results += "\nConnected. Sending XRP.\n" - document.getElementById('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 - 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() +// ------------------------------------------------------------ Submit signed blob + const tx = await client.submitAndWait(signed.tx_blob) + + results += "\nBalance changes: " + + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) + operationalResultField.value = results + standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address)) + + client.disconnect() +} // End of oPsendXRP() ``` - - ## 1.get-accounts-send-xrp.html Create a standard HTML form to send transactions and requests, then display the results. - ```html @@ -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;} td{vertical-align: middle;} - + + + + + + + @@ -482,7 +413,8 @@ Bold text in the following indicates changes to the form that support the new fu

Token Test Harness

- Choose your ledger instance:   + Choose your ledger instance: +    @@ -772,16 +704,4 @@ Bold text in the following indicates changes to the form that support the new fu
- -``` - ---- - -| Previous | Next | -| :--- | ---: | -| [← 2. Create Trust Line and Send Currency >](create-trustline-send-currency.html) | [4. Transfer NFTokens → >](transfer-nftokens.html) | - - -{% include '_snippets/rippled-api-links.md' %} -{% include '_snippets/tx-type-links.md' %} -{% include '_snippets/rippled_versions.md' %} +``` \ No newline at end of file diff --git a/content/tutorials/quickstart/transfer-nftokens.md b/content/tutorials/quickstart/transfer-nftokens.md index 1f3ae3b5f7..1d1b223751 100644 --- a/content/tutorials/quickstart/transfer-nftokens.md +++ b/content/tutorials/quickstart/transfer-nftokens.md @@ -19,14 +19,12 @@ This example shows how to: 5. Get a list of offers for a particular NFToken. 6. Cancel an offer. -![Quickstart form with NFToken transfer fields](img/quickstart13.png) +[![Quickstart form with NFToken transfer fields](img/quickstart13.png)](img/quickstart13.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. - # Usage - ## Get Accounts 1. Open `4.transfer-nftokens.html` in a browser. @@ -39,9 +37,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port 1. Click **Get New Standby Account**. 2. Click **Get New Operational Account**. -![Form with account information](img/quickstart14.png) - - +[![Form with account information](img/quickstart14.png)](img/quickstart14.png) ## Create a Sell Offer @@ -55,9 +51,7 @@ To create a NFToken sell offer: The important piece of information in the response is the NFToken Offer Index, labeled as `nft_offer_index`, which you use to accept the sell offer. -![NFToken Sell Offer](img/quickstart15.png) - - +[![NFToken Sell Offer](img/quickstart15.png)](img/quickstart15.png) ## Accept Sell Offer @@ -68,9 +62,7 @@ To accept an available sell offer: 1. Enter the **NFToken Offer Index** (labeled as `nft_offer_index` in the token offer results. This is different from the `NFTokenID`.) 2. Click **Accept Sell Offer**. -![Accept Sell Offer](img/quickstart16.png) - - +[![Accept Sell Offer](img/quickstart16.png)](img/quickstart16.png) ## Create a Buy Offer @@ -84,9 +76,7 @@ To create an offer to buy a NFToken: 4. Optionally enter the number of days until **Expiration**. 5. Click **Create Buy Offer**. -![NFToken Buy Offer](img/quickstart17.png) - - +[![NFToken Buy Offer](img/quickstart17.png)](img/quickstart17.png) ## Accept a Buy Offer @@ -95,9 +85,7 @@ To accept an offer to buy a NFToken: 1. Enter the **NFToken Offer Index** (the `nft_offer_index` of the NFToken buy offer). 3. Click **Accept Buy Offer**. -![Accept Buy Offer](img/quickstart18.png) - - +[![Accept Buy Offer](img/quickstart18.png)](img/quickstart18.png) ## Get Offers @@ -105,9 +93,7 @@ To list the buy and sell offers associated with a NFToken: 1. Enter the **NFToken ID**. 2. Click **Get Offers**. -![Get offers](img/quickstart19.png) - - +[![Get offers](img/quickstart19.png)](img/quickstart19.png) ## Cancel Offer @@ -116,48 +102,42 @@ To cancel a buy or sell offer that you have created: 1. Enter the **NFToken Offer Index**. 2. Click **Cancel Offer**. -![Cancel offer](img/quickstart20.png) - - +[![Cancel offer](img/quickstart20.png)](img/quickstart20.png) # 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} archive to try each of the samples in your own browser. - ## Create Sell Offer - -``` +```javascript // ******************************************************* // ****************** Create Sell Offer ****************** // ******************************************************* + +async function createSellOffer() { ``` - Connect to the ledger and get the accounts. - -``` -async function createSellOffer() { +```javascript const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) let net = getNet() const client = new xrpl.Client(net) - results = 'Connecting to ' + getNet() + '...' - document.getElementById('standbyResultField').value = results + results = 'Connecting to ' + net + '...' + standbyResultField.value = results await client.connect() results += '\nConnected. Creating sell offer...' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` Compute the Expiration Date, if present. The expiration date represents the number of seconds after the Ripple Epoch that the offer should expire. Start with the current date, add the number of days till expiration, then set the `expirationDate` variable to the converted date in Ripple time. -``` - //------------------------------------- Prepare Expiration Date +```javascript var expirationDate = null if (standbyExpirationField.value !="") { - var days = document.getElementById('standbyExpirationField').value + var days = standbyExpirationField.value let d = new Date() d.setDate(d.getDate() + parseInt(days)) var expirationDate = xrpl.isoTimeToRippleTime(d) @@ -166,7 +146,7 @@ Compute the Expiration Date, if present. The expiration date represents the numb Define the transaction. A _Flags_ value of 1 indicates that this transaction is a sell offer. -``` +```javascript let transactionBlob = { "TransactionType": "NFTokenCreateOffer", "Account": standby_wallet.classicAddress, @@ -178,7 +158,7 @@ Define the transaction. A _Flags_ value of 1 indicates that this transaction is If the Expiration Date is present, append it to the transaction. -``` +```javascript if (expirationDate != null) { transactionBlob.Expiration = expirationDate } @@ -187,36 +167,24 @@ If the Expiration Date is present, append it to the transaction. If the Destination field is not empty, append it to the transaction. When the destination is set, only the destination account can buy the NFToken. -``` +```javascript if(standbyDestinationField.value !== '') { transactionBlob.Destination = standbyDestinationField.value } ``` - Submit the transaction and wait for the results. - - -``` +```javascript const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet}) -``` - - - - - -``` results += '\n\n***Sell Offers***\n' ``` - Request the list of sell offers for the token. - -``` - let nftSellOffers +```javascript + let nftSellOffers try { nftSellOffers = await client.request({ method: "nft_sell_offers", @@ -227,91 +195,74 @@ Request the list of sell offers for the token. results += JSON.stringify(nftSellOffers,null,2) ``` - Request the list of buy offers for the token. - -``` +```javascript results += '\n\n***Buy Offers***\n' let nftBuyOffers try { nftBuyOffers = await client.request({ method: "nft_buy_offers", nft_id: standbyTokenIdField.value }) + results += JSON.stringify(nftBuyOffers,null,2) } catch (err) { results += 'No buy offers.' } - results += JSON.stringify(nftBuyOffers,null,2) ``` - Report the results of the transaction. - -``` +```javascript results += '\n\nTransaction result:\n' + JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += '\n\nBalance changes:\n' + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) ``` - Get the current XRP balances for the operational and standby accounts. - +```javascript + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address)) + standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) + standbyResultField.value = results ``` - document.getElementById('operationalBalanceField').value = - (await client.getXrpBalance(operational_wallet.address)) - document.getElementById('standbyBalanceField').value = - (await client.getXrpBalance(standby_wallet.address)) - document.getElementById('standbyResultField').value = results -``` - Disconnect from the ledger. - -``` +```javascript client.disconnect() }// End of createSellOffer() ``` - - ## Create Buy Offer - -``` +```javascript // ******************************************************* // ***************** Create Buy Offer ******************** // ******************************************************* - async function createBuyOffer() { ``` - Get the account and connect to the ledger. - -``` +```javascript const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) let net = getNet() const client = new xrpl.Client(net) - let results = 'Connecting to ' + getNet() + '...' - document.getElementById('standbyResultField').value = results + let results = 'Connecting to ' + net + '...' + standbyResultField.value = results await client.connect() results = '\nConnected. Creating buy offer...' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` Prepare the expiration date, if present. -``` - //------------------------------------- Prepare Expiration Date +```javascript var expirationDate = null if (standbyExpirationField.value !="") { - var days = document.getElementById('standbyExpirationField').value + var days = standbyExpirationField.value let d = new Date() d.setDate(d.getDate() + parseInt(days)) var expirationDate = xrpl.isoTimeToRippleTime(d) @@ -321,7 +272,7 @@ Prepare the expiration date, if present. Define the transaction. Setting the _Flags_ value to _null_ indicates that this is a buy offer. -``` +```javascript const transactionBlob = { "TransactionType": "NFTokenCreateOffer", "Account": standby_wallet.classicAddress, @@ -333,25 +284,21 @@ Define the transaction. Setting the _Flags_ value to _null_ indicates that this ``` If the expiration date is present, append that to the transaction. -``` +```javascript if (expirationDate != null) { transactionBlob.Expiration = expirationDate } - ``` Submit the transaction and wait for the results. - -``` +```javascript const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet}) ``` - Request the list of sell offers for the token. - -``` +```javascript results += "\n\n***Sell Offers***\n" let nftSellOffers try { @@ -364,51 +311,47 @@ Request the list of sell offers for the token. results += JSON.stringify(nftSellOffers,null,2) ``` - Request the list of buy offers for the token. - -``` +```javascript results += "\n\n***Buy Offers***\n" let nftBuyOffers try { nftBuyOffers = await client.request({ method: "nft_buy_offers", nft_id: standbyTokenIdField.value }) + results += JSON.stringify(nftBuyOffers,null,2) } catch (err) { results += "No buy offers." } - results += JSON.stringify(nftBuyOffers,null,2) ``` - Report the results of the transaction. - - -``` +```javascript results += "\n\nTransaction result:\n" + JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += "\n\nBalance changes:\n" + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) - document.getElementById('standbyResultField').value = results -``` - + standbyResultField.value = results``` Disconnect from the ledger. - -``` +```javascript client.disconnect() }// End of createBuyOffer() ``` - - ## Cancel Offer -``` + +// START HERE + + + + +```javascript // ******************************************************* // ******************** Cancel Offer ********************* // ******************************************************* @@ -416,36 +359,28 @@ Disconnect from the ledger. async function cancelOffer() { ``` - Get the standby address and connect to the ledger. - -``` +```javascript const wallet = xrpl.Wallet.fromSeed(standbySeedField.value) let net = getNet() const client = new xrpl.Client(net) - results = 'Connecting to ' + net + '...' - document.getElementById('standbyResultField').value = results + results = 'Connecting to ' + net + '...' + standbyResultField.value = results await client.connect() results += "\nConnected. Cancelling offer..." - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` Insert the token offer index as a new array. This example destroys one offer at a time. In practice you could implement the function to accept multiple token offer index values and destroy all of the token offers in one operation. - -``` +```javascript const tokenOfferIDs = [standbyTokenOfferIndexField.value] - - ``` - Define the transaction. - -``` +```javascript const transactionBlob = { "TransactionType": "NFTokenCancelOffer", "Account": wallet.classicAddress, @@ -453,19 +388,15 @@ Define the transaction. } ``` - Submit the transaction and wait for the results. - -``` +```javascript const tx = await client.submitAndWait(transactionBlob,{wallet}) ``` - Request the list of sell offers for the token. - -``` +```javascript results += "\n\n***Sell Offers***\n" let nftSellOffers try { @@ -479,50 +410,42 @@ Request the list of sell offers for the token. results += JSON.stringify(nftSellOffers,null,2) ``` - Request the list of buy offers for the token. - -``` +```javascript results += "\n\n***Buy Offers***\n" let nftBuyOffers try { nftBuyOffers = await client.request({ method: "nft_buy_offers", - nft_id: standbyTokenIdField.value }) + nft_id: standbyTokenIdField.value + }) + results += JSON.stringify(nftBuyOffers,null,2) } catch (err) { nftBuyOffers = "No buy offers." } - results += JSON.stringify(nftBuyOffers,null,2) ``` - Report the transaction results. - -``` +```javascript results += "\nTransaction result:\n" + JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += "\nBalance changes:\n" + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` - Disconnect from the ledger. - -``` +```javascript client.disconnect() // End of cancelOffer() } ``` - - ## Get Offers - -``` +```javascript // ******************************************************* // ******************** Get Offers *********************** // ******************************************************* @@ -533,68 +456,61 @@ async function getOffers() { Connect to the ledger. - -``` +```javascript + const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) let net = getNet() const client = new xrpl.Client(net) - results = 'Connecting to ' + getNet() + '...' - document.getElementById('standbyResultField').value = results + results = 'Connecting to ' + net + '...' + standbyResultField.value = results await client.connect() results += '\nConnected. Getting offers...' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` - Request the list of sell offers for the token. - -``` +```javascript results += '\n\n***Sell Offers***\n' let nftSellOffers try { nftSellOffers = await client.request({ method: "nft_sell_offers", - nft_id: standbyTokenIdField.value }) - } catch (err) { + nft_id: standbyTokenIdField.value + }) + } catch (err) { nftSellOffers = 'No sell offers.' } results += JSON.stringify(nftSellOffers,null,2) - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` - Request the list of buy offers for the token. - -``` +```javascript results += '\n\n***Buy Offers***\n' let nftBuyOffers try { nftBuyOffers = await client.request({ method: "nft_buy_offers", - nft_id: standbyTokenIdField.value }) + nft_id: standbyTokenIdField.value + }) } catch (err) { nftBuyOffers = 'No buy offers.' } results += JSON.stringify(nftBuyOffers,null,2) - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` - Disconnect from the ledger. - -``` +```javascript client.disconnect() }// End of getOffers() ``` - - ## Accept Sell Offer - -``` +```javascript // ******************************************************* // ****************** Accept Sell Offer ****************** // ******************************************************* @@ -603,27 +519,23 @@ Disconnect from the ledger. async function acceptSellOffer() { ``` - Get the accounts and connect to the ledger. - -``` +```javascript const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) let net = getNet() const client = new xrpl.Client(net) - results = 'Connecting to ' + getNet() + '...' - document.getElementById('standbyResultField').value = results + results = 'Connecting to ' + net + '...' + standbyResultField.value = results await client.connect() results += '\nConnected. Accepting sell offer...\n\n' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` - Define the transaction. - -``` +```javascript const transactionBlob = { "TransactionType": "NFTokenAcceptOffer", "Account": standby_wallet.classicAddress, @@ -631,63 +543,49 @@ Define the transaction. } ``` - Submit the transaction and wait for the results. - -``` +```javascript const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet}) ``` - Request the list of NFTs for the standby account. - -``` +```javascript const nfts = await client.request({ method: "account_nfts", - account: standby_wallet.classicAddress }) + account: standby_wallet.classicAddress + }) ``` - Get the balances for both accounts. - +```javascript + standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address)) ``` - document.getElementById('standbyBalanceField').value = - (await client.getXrpBalance(standby_wallet.address)) - document.getElementById('operationalBalanceField').value = - (await client.getXrpBalance(operational_wallet.address)) -``` - Report the transaction results. - -``` +```javascript results += 'Transaction result:\n' results += JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += '\nBalance changes:' results += JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) results += JSON.stringify(nfts,null,2) - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` - Disconnect from the ledger. - -``` +```javascript client.disconnect() }// End of acceptSellOffer() ``` - - ## Accept Buy Offer - -``` +```javascript // ******************************************************* // ******************* Accept Buy Offer ****************** // ******************************************************* @@ -696,38 +594,33 @@ Disconnect from the ledger. async function acceptBuyOffer() { ``` - Get the accounts and connect to the ledger. - -``` +```javascript const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value) const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) let net = getNet() const client = new xrpl.Client(net) - results = 'Connecting to ' + getNet() + '...' - document.getElementById('standbyResultField').value = results + results = 'Connecting to ' + net + '...' + standbyResultField.value = results await client.connect() results += '\nConnected. Accepting buy offer...' - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` - Prepare the transaction. - -``` +```javascript + const transactionBlob = { "TransactionType": "NFTokenAcceptOffer", "Account": standby_wallet.classicAddress, "NFTokenBuyOffer": standbyTokenOfferIndexField.value } ``` - Submit the transaction and wait for the results. - -``` +```javascript const tx = await client.submitAndWait(transactionBlob,{wallet: standby_wallet}) ``` @@ -735,20 +628,18 @@ Submit the transaction and wait for the results. Request the current list of NFTs for the standby account. -``` +```javascript const nfts = await client.request({ method: "account_nfts", account: standby_wallet.classicAddress }) results += JSON.stringify(nfts,null,2) - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` - Report the transaction result. - -``` +```javascript results += "\n\nTransaction result:\n" + JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += "\nBalance changes:\n" + @@ -759,30 +650,26 @@ Report the transaction result. Request the XRP balance for both accounts. -``` - document.getElementById('operationalBalanceField').value = +```javascript + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address)) - document.getElementById('standbyBalanceField').value = + standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) - document.getElementById('standbyResultField').value = results + standbyResultField.value = results ``` - Disconnect from the ledger. - -``` +```javascript client.disconnect() }// End of acceptBuyOffer() ``` - - ## Reciprocal Transactions These functions duplicate the functions of the standby account for the operational account. See the corresponding standby account function for walkthrough information. -``` +```javascript // ******************************************************* // *********** Operational Create Sell Offer ************* // ******************************************************* @@ -792,23 +679,21 @@ async function oPcreateSellOffer() { const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) let net = getNet() const client = new xrpl.Client(net) - results = 'Connecting to ' + getNet() + '...' - document.getElementById('operationalResultField').value = results + results = 'Connecting to ' + net + '...' + operationalResultField.value = results await client.connect() results += '\nConnected. Creating sell offer...' - document.getElementById('operationalResultField').value = results + operationalResultField.value = results //------------------------------------- Prepare Expiration Date - var expirationDate = null if (operationalExpirationField.value !="") { - var days = document.getElementById('operationalExpirationField').value + var days = operationalExpirationField.value let d = new Date() d.setDate(d.getDate() + parseInt(days)) var expirationDate = xrpl.isoTimeToRippleTime(d) } - - // Prepare transaction ------------------------------------------------------- + // Prepare transaction ------------------------------------------------------- let transactionBlob = { "TransactionType": "NFTokenCreateOffer", "Account": operational_wallet.classicAddress, @@ -844,27 +729,27 @@ async function oPcreateSellOffer() { try { nftBuyOffers = await client.request({ method: "nft_buy_offers", - nft_id: operationalTokenIdField.value }) + nft_id: operationalTokenIdField.value + }) + results += JSON.stringify(nftBuyOffers,null,2) } catch (err) { results += 'No buy offers.' } - results += JSON.stringify(nftBuyOffers,null,2) // Check transaction results ------------------------------------------------- results += '\n\nTransaction result:\n' + JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += '\n\nBalance changes:\n' + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) - document.getElementById('operationalBalanceField').value = + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address)) - document.getElementById('standbyBalanceField').value = + standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) - document.getElementById('operationalResultField').value = results + operationalResultField.value = results client.disconnect() } // End of oPcreateSellOffer() - // ******************************************************* // ************** Operational Create Buy Offer *********** // ******************************************************* @@ -875,16 +760,16 @@ async function oPcreateBuyOffer() { const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) let net = getNet() const client = new xrpl.Client(net) - let results = 'Connecting to ' + getNet() + '...' - document.getElementById('operationalResultField').value = results + let results = 'Connecting to ' + net + '...' + operationalResultField.value = results await client.connect() results = '\nConnected. Creating buy offer...' - document.getElementById('operationalResultField').value = results + operationalResultField.value = results //------------------------------------- Prepare Expiration Date var expirationDate = null if (operationalExpirationField.value !="") { - var days = document.getElementById('operationalExpirationField').value + var days = operationalExpirationField.value let d = new Date() d.setDate(d.getDate() + parseInt(days)) var expirationDate = xrpl.isoTimeToRippleTime(d) @@ -933,12 +818,11 @@ async function oPcreateBuyOffer() { JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += "\n\nBalance changes:\n" + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) - document.getElementById('operationalResultField').value = results + operationalResultField.value = results client.disconnect() }// End of oPcreateBuyOffer() - // ******************************************************* // ************* Operational Cancel Offer **************** // ******************************************************* @@ -949,10 +833,10 @@ async function oPcancelOffer() { let net = getNet() const client = new xrpl.Client(net) results = 'Connecting to ' + net + '...' - document.getElementById('operationalResultField').value = results + operationalResultField.value = results await client.connect() results += "\nConnected. Cancelling offer..." - document.getElementById('operationalResultField').value = results + operationalResultField.value = results const tokenOfferIDs = [operationalTokenOfferIndexField.value] @@ -981,7 +865,8 @@ async function oPcancelOffer() { try { nftBuyOffers = await client.request({ method: "nft_buy_offers", - nft_id: operationalTokenIdField.value }) + nft_id: operationalTokenIdField.value + }) } catch (err) { nftBuyOffers = "No buy offers." } @@ -993,7 +878,7 @@ async function oPcancelOffer() { JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += "\nBalance changes:\n" + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) - document.getElementById('operationalResultField').value = results + operationalResultField.value = results client.disconnect() }// End of oPcancelOffer() @@ -1003,11 +888,11 @@ async function oPcancelOffer() { // ******************************************************* async function oPgetOffers() { - const standby_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) +// const standby_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) let net = getNet() const client = new xrpl.Client(net) - results = 'Connecting to ' + getNet() + '...' - document.getElementById('operationalResultField').value = results + results = 'Connecting to ' + net + '...' + operationalResultField.value = results await client.connect() results += '\nConnected. Getting offers...' @@ -1017,25 +902,25 @@ async function oPgetOffers() { try { nftSellOffers = await client.request({ method: "nft_sell_offers", - nft_id: operationalTokenIdField.value}) + nft_id: operationalTokenIdField.value + }) } catch (err) { nftSellOffers = 'No sell offers.' } results += JSON.stringify(nftSellOffers,null,2) - document.getElementById('standbyResultField').value = results - results += '\n\n***Buy Offers***\n' let nftBuyOffers try { nftBuyOffers = await client.request({ method: "nft_buy_offers", - nft_id: operationalTokenIdField.value }) + nft_id: operationalTokenIdField.value + }) } catch (err) { nftBuyOffers = 'No buy offers.' } results += JSON.stringify(nftBuyOffers,null,2) - document.getElementById('operationalResultField').value = results + operationalResultField.value = results client.disconnect() }// End of oPgetOffers() @@ -1049,11 +934,11 @@ async function oPacceptSellOffer() { const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) let net = getNet() const client = new xrpl.Client(net) - results = 'Connecting to ' + getNet() + '...' - document.getElementById('operationalResultField').value = results + results = 'Connecting to ' + net + '...' + operationalResultField.value = results await client.connect() results += '\nConnected. Accepting sell offer...\n\n' - document.getElementById('operationalResultField').value = results + operationalResultField.value = results // Prepare transaction ------------------------------------------------------- const transactionBlob = { @@ -1065,25 +950,23 @@ async function oPacceptSellOffer() { const tx = await client.submitAndWait(transactionBlob,{wallet: operational_wallet}) const nfts = await client.request({ method: "account_nfts", - account: operational_wallet.classicAddress }) + account: operational_wallet.classicAddress + }) // Check transaction results ------------------------------------------------- - document.getElementById('standbyBalanceField').value = - (await client.getXrpBalance(standby_wallet.address)) - document.getElementById('operationalBalanceField').value = - (await client.getXrpBalance(operational_wallet.address)) + standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address)) results += 'Transaction result:\n' results += JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += '\nBalance changes:' results += JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) results += JSON.stringify(nfts,null,2) - document.getElementById('operationalResultField').value = results + operationalResultField.value = results client.disconnect() }// End of acceptSellOffer() - // ******************************************************* // ********* Operational Accept Buy Offer **************** // ******************************************************* @@ -1093,11 +976,11 @@ async function oPacceptBuyOffer() { const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value) let net = getNet() const client = new xrpl.Client(net) - results = 'Connecting to ' + getNet() + '...' - document.getElementById('operationalResultField').value = results + results = 'Connecting to ' + net + '...' + operationalResultField.value = results await client.connect() results += '\nConnected. Accepting buy offer...' - document.getElementById('operationalResultField').value = results + operationalResultField.value = results // Prepare transaction ------------------------------------------------------- const transactionBlob = { @@ -1109,41 +992,42 @@ async function oPacceptBuyOffer() { const tx = await client.submitAndWait(transactionBlob,{wallet: operational_wallet}) const nfts = await client.request({ method: "account_nfts", - account: operational_wallet.classicAddress }) + account: operational_wallet.classicAddress + }) results += JSON.stringify(nfts,null,2) - document.getElementById('operationalResultField').value = results + operationalResultField.value = results // Check transaction results ------------------------------------------------- results += "\n\nTransaction result:\n" + JSON.stringify(tx.result.meta.TransactionResult, null, 2) results += "\nBalance changes:\n" + JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) - document.getElementById('operationalBalanceField').value = + operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address)) - document.getElementById('operationalBalanceField').value = + operationalBalanceField.value = (await client.getXrpBalance(standby_wallet.address)) - document.getElementById('operationalResultField').value = results + operationalResultField.value = results client.disconnect() }// End of acceptBuyOffer() - ``` - - ## 4.transfer-nfts.html Update the form with fields and buttons to support the new functions. - -``` - - - - +```html Token Test Harness - + + + @@ -1163,7 +1047,7 @@ Update the form with fields and buttons to support the new functions.

Token Test Harness

- Choose your ledger instance: + Choose your ledger instance:    @@ -1493,17 +1377,4 @@ Update the form with fields and buttons to support the new functions.
- -``` - ---- - - -| Previous | Next | -| :--- | ---: | -| [← 3. Mint and Burn NFTokens >](mint-and-burn-nftokens.html) | [Broker a NFToken Sale → >](broker-sale.html) | - - -{% include '_snippets/rippled-api-links.md' %} -{% include '_snippets/tx-type-links.md' %} -{% include '_snippets/rippled_versions.md' %} +``` \ No newline at end of file diff --git a/content/tutorials/quickstart/xrpl-quickstart.md b/content/tutorials/quickstart/xrpl-quickstart.md index 79f8a0fa6e..6c421ea5c1 100644 --- a/content/tutorials/quickstart/xrpl-quickstart.md +++ b/content/tutorials/quickstart/xrpl-quickstart.md @@ -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. -**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) | +**Note:** Without the Quickstart Samples, you will not be able to try the examples that follow. \ No newline at end of file diff --git a/img/quickstart33-batch-mint.png b/img/quickstart33-batch-mint.png new file mode 100644 index 0000000000..ff15568eca Binary files /dev/null and b/img/quickstart33-batch-mint.png differ