mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2026-04-29 15:37:48 +00:00
Update tutorial nav
This commit is contained in:
committed by
Amarantha Kulkarni
parent
05c0191e5a
commit
f0c5b6141a
@@ -1,13 +0,0 @@
|
||||
---
|
||||
html: modular-tutorials-in-javascript.html
|
||||
parent: javascript.html
|
||||
top_nav_grouping: Article Types
|
||||
metadata:
|
||||
indexPage: true
|
||||
---
|
||||
# Modular Tutorials in JavaScript
|
||||
|
||||
Modular XRPL tutorials in JavaScript.
|
||||
|
||||
|
||||
{% child-pages /%}
|
||||
@@ -48,7 +48,7 @@ To authorize another account to create NFTs for your account:
|
||||
## Mint an NFT for Another Account
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/cXvyu2ZDCBM?si=AFrGzgV4CAF2LoAk" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/3WwDaDcK8C4?si=RYDhuYihibjgXGCD" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
This example uses the Operational account, which was authorized in the previous step, to mint a token on behalf of the Standby account.
|
||||
|
||||
@@ -35,7 +35,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
|
||||
## Batch Mint NFTs
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/tJeDnEMZ7RU?si=mHwKbSRMxQ1cO4Fh" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/LsMMXm7jm1k?si=Lu0-0PIJ2-Uj7dSY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
This example lets you mint multiple NFTs for a single unique item. The NFT might represent "prints" of an original artwork, tickets to an event, or another limited set of unique items.
|
||||
|
||||
@@ -43,7 +43,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
|
||||
## Prepare a Brokered Transaction
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/GemQ-t7g9fo?si=zVTLXFg3v-XX4Rf_" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/Xm-JKplBdSU?si=qOWo7vwhI4GQlErk" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
1. Use the Standby account to create an NFT Sell Offer with the Broker account as the destination.
|
||||
|
||||
@@ -38,7 +38,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
|
||||
## Mint an NFT
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/Qyb_x_GlUDg?si=fow07WIV6DjuHZ3K" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/oGzKbQJCTJ0?si=kCBG_jJkFAS7_mYU" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
To mint a non-fungible token object:
|
||||
|
||||
@@ -42,7 +42,7 @@ You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-port
|
||||
## Create a Sell Offer
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/He5PpO7TQbQ?si=mejmPLh-Z7ocbJVV" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/mZlznG9ZJNY?si=TFTtl_MPb7WPtHHV" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
To create a NFT sell offer:
|
||||
|
||||
@@ -36,7 +36,7 @@ Download and expand the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-p
|
||||
## Usage
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/GX436F-FaV4?si=OyuTUD4zHZ5a0Dgx" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/YnPccLPa0hc?si=U6uQNXzNRp5G_pri" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
To get test accounts:
|
||||
@@ -52,7 +52,7 @@ To get test accounts:
|
||||
You can transfer XRP between your new accounts. Each account has its own fields and buttons.
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/sjYJOcKXZvY?si=IRx_AFMaZarOIOPY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/l2X7Vso5wWc?si=62bRYEd-pTrfhWbJ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
To transfer XRP from the Standby account to the Operational account:
|
||||
|
||||
@@ -62,7 +62,7 @@ To get test accounts:
|
||||
### Create Conditional Escrow:
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/jUQ2nM5JXjc?si=-ajV2EFw8xv4djgG" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/aUMqCFBsPW4?si=nUC4-yBOweti02be" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
When you create a conditional escrow, you need to specify the amount you want to reserve and the `Condition` value you generated above. You can also set a cancel date and time, after which the escrow is no longer available.
|
||||
|
||||
@@ -45,7 +45,7 @@ To get test accounts:
|
||||
## Create Escrow
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/mNPSSZxcq7s?si=ZZewy6EKpxSMfxak" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/L-mSItlK36M?si=bltVKY7AtTnG0ucL" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
You can create a time-based escrow with a minimum time to finish the escrow and a cancel time after which the funds in escrow are no longer available to the recipient. This is a test harness: while a practical scenario might express time in days or weeks, this form lets you set the finish and cancel times in seconds so that you can quickly run through a variety of scenarios. (There are 86,400 seconds in a day, if you want to play with longer term escrows.)
|
||||
|
||||
@@ -42,7 +42,7 @@ Open the Token Test Harness and get accounts:
|
||||
## Create Trust Line
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/HpcyZt1jG3E?si=evreLRsmgF5rrQrW" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/EP_LOy8kK1U?si=Ulx8vUtil_yRcesd" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
To create a trust line between accounts:
|
||||
|
||||
@@ -1,46 +1,13 @@
|
||||
---
|
||||
html: send-payments-using-javascript.html
|
||||
parent: modular-tutorials-in-javascript.html
|
||||
seo:
|
||||
description: Use a JavaScript test harness to send XRP, trade currencies, and mint and trade NFTs.
|
||||
labels:
|
||||
- Accounts
|
||||
- Cross-Currency
|
||||
- Non-fungible Tokens, NFTs
|
||||
- Payments
|
||||
- Quickstart
|
||||
- Tokens
|
||||
- XRP
|
||||
parent: javascript.html
|
||||
top_nav_grouping: Article Types
|
||||
metadata:
|
||||
indexPage: true
|
||||
---
|
||||
# Send Payments Using JavaScript
|
||||
|
||||
The XRP Ledger (XRPL) is a robust, secure, customizable service. You can create your own interface to try out the capabilities and support your specific business needs.
|
||||
Send XRP and issued currency on the XRP Ledger using JavaScript.
|
||||
|
||||
This quickstart describes a test harness interface you can build to try out the XRP Ledger. The test harness displays multiple accounts, so that you can transfer tokens from one account to the other and see the results in real time. The image below shows the Token Test Harness at the completion of step 4.
|
||||
|
||||

|
||||
|
||||
That is a lot of fields and buttons, all working together to perform some significant practical tasks. But getting _started_ with the XRP Ledger is not that complicated. When you eat the elephant a bite at a time, none of the tasks are difficult to consume.
|
||||
|
||||
Typically, the example functions for interacting with the XRP Ledger involve four steps.
|
||||
|
||||
1. Connect to the XRP Ledger and instantiate your wallet.
|
||||
2. Make changes to the XRP Ledger using transactions.
|
||||
3. Get the state of accounts and tokens on the XRP Ledger using requests.
|
||||
4. Disconnect from the XRP Ledger.
|
||||
|
||||
Each lesson shows you how to build the Token Test Harness one section at a time. Each module lets you try out meaningful interactions with the test ledger, with complete JavaScript and HTML code samples and a code walkthrough. There is also a link to the complete source code for each section that can be modified with a text editor and run in a browser. If you cannot wait, you can follow the prerequisites below, then jump to lesson 4, [Create Conditional Escrows](create-conditional-escrows.md), and try out the complete test harness right away.
|
||||
|
||||
This quickstart tutorial introduces you to the API used to implement features and explore the capabilities of XRP Ledger. It does not represent *all* of the capabilities of the API and this example is not intended for production or secure payment use.
|
||||
|
||||
Much of this is “brute force” code that sacrifices conciseness for readability. Each example builds on the previous examples, adding a new JavaScript file and the supporting UI. We anticipate that the applications you build greatly improve upon these examples. Your feedback and contributions are most welcome.
|
||||
|
||||
## 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/_code-samples/quickstart/js/)<!-- {.github-code-download} -->.
|
||||
{% child-pages /%}
|
||||
|
||||
@@ -0,0 +1,902 @@
|
||||
---
|
||||
html: send-and-cash-checks.html
|
||||
parent: send-payments-using-javascript.html
|
||||
blurb: Send checks to facilitate a two-step payment.
|
||||
labels:
|
||||
- Accounts
|
||||
- Quickstart
|
||||
- Transaction Sending
|
||||
- Checks
|
||||
- XRP
|
||||
---
|
||||
# Send and Cash Checks
|
||||
|
||||
This example shows how to:
|
||||
|
||||
1. Send a check to transfer XRP or issued currency to another account.
|
||||
2. Get a list of checks you have sent or received.
|
||||
3. Cash a check received from another account.
|
||||
4. Cancel a check you have sent.
|
||||
|
||||
Checks offer another option for transferring funds between accounts. Checks have two particular advantages.
|
||||
|
||||
1. You can use a check to send funds to another account without first creating a trust line - the trust line is created automatically when the receiver chooses to accept the funds.
|
||||
2. The receiver can choose to accept less than the full amount of the check. This allows you to authorize a maximum amount when the actual cost is not finalized.
|
||||
|
||||
|
||||
[](/docs/img/quickstart-checks1.png)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Clone or download the [Modular Tutorial Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download}.
|
||||
|
||||
**Note:** Without the Quickstart Samples, you will not be able to try the examples that follow.
|
||||
|
||||
## Usage
|
||||
|
||||
To get test accounts:
|
||||
|
||||
1. Open and launch `10check.html`.
|
||||
2. Click **Get Standby Account**.
|
||||
3. Click **Get Operational Account**.
|
||||
|
||||
[](/docs/img/quickstart-checks2.png)
|
||||
|
||||
You can transfer XRP between your new accounts. Each account has its own fields and buttons.
|
||||
|
||||
<div align="center">
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/5zRBC7dGSaM?si=Glf3_uh7w0UUNHU8" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
</div>
|
||||
|
||||
### Send a Check for XRP
|
||||
|
||||
To send a check for 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, in drops.
|
||||
2. Copy and paste the **Operational Account** field to the Standby **Destination** field.
|
||||
3. Set the **Currency** to _XRP_.
|
||||
4. Click **Send Check**.
|
||||
|
||||
[](/docs/img/quickstart-checks3.png)
|
||||
|
||||
### Send a Check for an Issued Currency
|
||||
|
||||
To send a check for an issued currency token from the Standby account to the Operational account:
|
||||
|
||||
1. On the Standby side of the form, enter the **Amount** of currency to send.
|
||||
2. Copy and paste the **Operational Account** field to the Standby **Destination** field.
|
||||
3. Copy the **Standby Account** field and paste the value in the **Issuer** field.
|
||||
4. Enter the **Currency** code for your token.
|
||||
5. Click **Send Check**.
|
||||
|
||||
[](/docs/img/quickstart-checks4.png)
|
||||
|
||||
|
||||
### Get Checks
|
||||
|
||||
Click **Get Checks** to get a list of the current checks you have sent or received. To uniquely identify a check (for existence, when cashing a check), capture the _index_ value for the check.
|
||||
|
||||
[](/docs/img/quickstart-checks5.png)
|
||||
|
||||
### Cash Check
|
||||
|
||||
To cash a check you have received:
|
||||
|
||||
1. Enter the **Check ID** (**index** value).
|
||||
2. Enter the **Amount** you want to collect, up to the full amount of the check.
|
||||
3. Enter the currency code.
|
||||
a. If you cashing a check for XRP, enter _XRP_ in the **Currency** field.
|
||||
b. If you are cashing a check for an issued currency token:
|
||||
1. Enter the **Issuer** of the token.
|
||||
2. Enter the **Currency** code for the token.
|
||||
4. Click **Cash Check**.
|
||||
|
||||
[](/docs/img/quickstart-checks6.png)
|
||||
|
||||
|
||||
### Get Balances
|
||||
|
||||
Click **Get Balances** to get a list of obligations and assets for each account.
|
||||
|
||||
[](/docs/img/quickstart-checks7.png)
|
||||
|
||||
### Cancel Check
|
||||
|
||||
To cancel a check you have previously sent to another account.
|
||||
|
||||
1. Enter the **Check ID** (**index** value).
|
||||
2. Click **Cancel Check**.
|
||||
|
||||
[](/docs/img/quickstart-checks8.png)
|
||||
|
||||
|
||||
# Code Walkthrough
|
||||
|
||||
You can download the [Quickstart Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/quickstart/js/){.github-code-download} in the source repository for this website.
|
||||
|
||||
## ripplex10-check.js
|
||||
|
||||
### sendCheck()
|
||||
|
||||
Connect to the XRP ledger.
|
||||
|
||||
```javascript
|
||||
async function sendCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
results = 'Connecting to ' + getNet() + '....'
|
||||
standbyResultField.value = results
|
||||
await client.connect()
|
||||
results += '\nConnected.'
|
||||
standbyResultField.value = results
|
||||
```
|
||||
|
||||
Instantiate the account wallets.
|
||||
|
||||
```javascript
|
||||
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
|
||||
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
|
||||
```
|
||||
|
||||
Create the `check_amount` variable, based on the standby amount field.
|
||||
|
||||
```javascript
|
||||
var check_amount = standbyAmountField.value
|
||||
```
|
||||
|
||||
If the currency is anything but _XRP_, it's an issued currency. Update the `check_amount` variable to include the `currency` and `issuer` fields.
|
||||
|
||||
```javascript
|
||||
if (standbyCurrencyField.value != "XRP") {
|
||||
check_amount = {
|
||||
"currency": standbyCurrencyField.value,
|
||||
"value": standbyAmountField.value,
|
||||
"issuer": standby_wallet.address
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Define the `CheckCreate` transaction.
|
||||
|
||||
```javascript
|
||||
const send_check_tx = {
|
||||
"TransactionType": "CheckCreate",
|
||||
"Account": standby_wallet.address,
|
||||
"SendMax": check_amount,
|
||||
"Destination": standbyDestinationField.value
|
||||
}
|
||||
```
|
||||
|
||||
Prepare and sign the transaction.
|
||||
|
||||
```javascript
|
||||
const check_prepared = await client.autofill(send_check_tx)
|
||||
const check_signed = standby_wallet.sign(check_prepared)
|
||||
results += 'Sending ' + check_amount + ' ' + standbyCurrencyField + ' to ' +
|
||||
standbyDestinationField.value + '...'
|
||||
standbyResultField.value = results
|
||||
```
|
||||
|
||||
Submit the transaction to the XRP Ledger and wait for the response.
|
||||
|
||||
```
|
||||
const check_result = await client.submitAndWait(check_signed.tx_blob)
|
||||
```
|
||||
|
||||
Report the results
|
||||
|
||||
```javascript
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${check_signed.hash}'
|
||||
standbyResultField.value = JSON.stringify(check_result.result, null, 2)
|
||||
} else {
|
||||
results += 'Transaction failed: See JavaScript console for details.'
|
||||
standbyResultField.value = results
|
||||
throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
|
||||
}
|
||||
```
|
||||
|
||||
Update the XRP balance fields.
|
||||
|
||||
```javascript
|
||||
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
|
||||
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
|
||||
```
|
||||
|
||||
Disconnect from the XRP Ledger.
|
||||
|
||||
```javascript
|
||||
client.disconnect()
|
||||
} // end of sendCheck()
|
||||
```
|
||||
|
||||
### getChecks()
|
||||
|
||||
```javascript
|
||||
async function getChecks() {
|
||||
```
|
||||
|
||||
Connect to the XRP Ledger.
|
||||
|
||||
```javascript
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
results = 'Connecting to ' + getNet() + '....'
|
||||
standbyResultField.value = results
|
||||
await client.connect()
|
||||
results += '\nConnected.'
|
||||
standbyResultField.value = results
|
||||
results= "\nGetting standby account checks...\n"
|
||||
```
|
||||
|
||||
Define and send the `account_objects` request, specifying `check` objects.
|
||||
|
||||
```javascript
|
||||
const check_objects = await client.request({
|
||||
"id": 5,
|
||||
"command": "account_objects",
|
||||
"account": standbyAccountField.value,
|
||||
"ledger_index": "validated",
|
||||
"type": "check"
|
||||
})
|
||||
```
|
||||
|
||||
Report the results.
|
||||
|
||||
```javascript
|
||||
standbyResultField.value = JSON.stringify(check_objects.result, null, 2)
|
||||
```
|
||||
|
||||
Disconnect from the XRP Ledger.
|
||||
|
||||
```javascript
|
||||
client.disconnect()
|
||||
} // End of getChecks()
|
||||
```
|
||||
### cashCheck()
|
||||
|
||||
Connect to the XRP Ledger and instantiate the account wallets.
|
||||
|
||||
```javascript
|
||||
async function cashCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
results = 'Connecting to ' + getNet() + '....'
|
||||
standbyResultField.value = results
|
||||
await client.connect()
|
||||
results += '\nConnected.'
|
||||
standbyResultField.value = results
|
||||
|
||||
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
|
||||
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
|
||||
```
|
||||
|
||||
Set the `check_amount` variable to the value in the **Amount** field.
|
||||
|
||||
```javascript
|
||||
var check_amount = standbyAmountField.value
|
||||
```
|
||||
|
||||
If the **Currency** is anything other than `XRP`, the check is for an issued currency. Redefine the variable to include the `currency` and `issuer` for the token.
|
||||
|
||||
```
|
||||
if (standbyCurrencyField.value != "XRP") {
|
||||
check_amount = {
|
||||
"value": standbyAmountField.value,
|
||||
"currency": standbyCurrencyField.value,
|
||||
"issuer": standbyIssuerField.value
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Define the `CheckCash` transaction.
|
||||
|
||||
```javascript
|
||||
const cash_check_tx = {
|
||||
"TransactionType": "CheckCash",
|
||||
"Account": standby_wallet.address,
|
||||
"Amount": check_amount,
|
||||
"CheckID": standbyCheckID.value
|
||||
}
|
||||
```
|
||||
|
||||
Prepare and sign the transaction.
|
||||
|
||||
```javascript
|
||||
const cash_prepared = await client.autofill(cash_check_tx)
|
||||
const cash_signed = standby_wallet.sign(cash_prepared)
|
||||
results += ' Receiving ' + standbyAmountField.value + ' ' + standbyCurrencyField.value + '.\n'
|
||||
standbyResultField.value = results
|
||||
```
|
||||
|
||||
Submit the transaction and wait for the results.
|
||||
|
||||
```javascript
|
||||
const check_result = await client.submitAndWait(cash_signed.tx_blob)
|
||||
```
|
||||
|
||||
Report the results.
|
||||
|
||||
```javascript
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${cash_signed.hash}'
|
||||
standbyResultField.value = results
|
||||
} else {
|
||||
results += 'Transaction failed: See JavaScript console for details.'
|
||||
standbyResultField.value = results
|
||||
throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
|
||||
}
|
||||
```
|
||||
|
||||
Update the XRP balance fields.
|
||||
|
||||
```javascript
|
||||
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
|
||||
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
|
||||
```
|
||||
|
||||
Disconnect from the XRP Ledger.
|
||||
|
||||
```javascript
|
||||
client.disconnect()
|
||||
} // end of cashCheck()
|
||||
```
|
||||
|
||||
### cancelCheck
|
||||
|
||||
Connect to the XRP Ledger and instantiate the account wallets.
|
||||
|
||||
```javascript
|
||||
async function cancelCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
results = 'Connecting to ' + getNet() + '....'
|
||||
standbyResultField.value = results
|
||||
await client.connect()
|
||||
results += '\nConnected.'
|
||||
standbyResultField.value = results
|
||||
|
||||
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
|
||||
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
|
||||
```
|
||||
|
||||
Define the `CheckCancel` transaction.
|
||||
|
||||
```javascript
|
||||
const cancel_check_tx = {
|
||||
"TransactionType": "CheckCancel",
|
||||
"Account": standby_wallet.address,
|
||||
"CheckID": standbyCheckID.value
|
||||
}
|
||||
```
|
||||
|
||||
Prepare and sign the transaction object.
|
||||
|
||||
```javascript
|
||||
const cancel_prepared = await client.autofill(cancel_check_tx)
|
||||
const cancel_signed = standby_wallet.sign(cancel_prepared)
|
||||
results += ' Cancelling check.\n'
|
||||
standbyResultField.value = results
|
||||
```
|
||||
|
||||
Submit the transaction and wait for the results.
|
||||
|
||||
```javascript
|
||||
const check_result = await client.submitAndWait(cancel_signed.tx_blob)
|
||||
```
|
||||
|
||||
Report the results.
|
||||
|
||||
```javascript
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${cash_signed.hash}'
|
||||
standbyResultField.value = results
|
||||
} else {
|
||||
results += 'Transaction failed: See JavaScript console for details.'
|
||||
standbyResultField.value = results
|
||||
throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
|
||||
}
|
||||
```
|
||||
|
||||
Update the XRP balance fields.
|
||||
|
||||
```javascript
|
||||
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
|
||||
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
|
||||
```
|
||||
|
||||
Disconnect from the XRP Ledger.
|
||||
|
||||
```javascript
|
||||
client.disconnect()
|
||||
} // end of cancelCheck()
|
||||
```
|
||||
|
||||
### Reciprocal functions for the Operational account.
|
||||
|
||||
```javascript
|
||||
// *******************************************************
|
||||
// ************ Operational Send Check *******************
|
||||
// *******************************************************
|
||||
async function opSendCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
results = 'Connecting to ' + getNet() + '....'
|
||||
operationalResultField.value = results
|
||||
await client.connect()
|
||||
results += '\nConnected.'
|
||||
operationalResultField.value = results
|
||||
|
||||
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
|
||||
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
|
||||
|
||||
const issue_quantity = operationalAmountField.value
|
||||
var check_amount = operationalAmountField.value
|
||||
|
||||
if (operationalCurrencyField.value != "XRP") {
|
||||
check_amount = {
|
||||
"currency": operationalCurrencyField.value,
|
||||
"value": operationalAmountField.value,
|
||||
"issuer": operational_wallet.address
|
||||
}
|
||||
}
|
||||
const send_check_tx = {
|
||||
"TransactionType": "CheckCreate",
|
||||
"Account": operational_wallet.address,
|
||||
"SendMax": check_amount,
|
||||
"Destination": operationalDestinationField.value
|
||||
}
|
||||
const check_prepared = await client.autofill(send_check_tx)
|
||||
const check_signed = operational_wallet.sign(check_prepared)
|
||||
results += '\nSending check to ' +
|
||||
operationalDestinationField.value + '...'
|
||||
operationalResultField.value = results
|
||||
const check_result = await client.submitAndWait(check_signed.tx_blob)
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${check_signed.hash}'
|
||||
operationalResultField.value = JSON.stringify(check_result.result, null, 2)
|
||||
} else {
|
||||
results += 'Transaction failed: See JavaScript console for details.'
|
||||
operationalResultField.value = results
|
||||
throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
|
||||
}
|
||||
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
|
||||
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
|
||||
client.disconnect()
|
||||
} // end of opSendCheck()
|
||||
|
||||
// *******************************************************
|
||||
// ************ Operational Get Checks *******************
|
||||
// *******************************************************
|
||||
|
||||
async function opGetChecks() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
results = 'Connecting to ' + getNet() + '....'
|
||||
operationalResultField.value = results
|
||||
await client.connect()
|
||||
results += '\nConnected.'
|
||||
operationalResultField.value = results
|
||||
|
||||
results= "\nGetting standby account checks...\n"
|
||||
const check_objects = await client.request({
|
||||
"id": 5,
|
||||
"command": "account_objects",
|
||||
"account": operationalAccountField.value,
|
||||
"ledger_index": "validated",
|
||||
"type": "check"
|
||||
})
|
||||
operationalResultField.value = JSON.stringify(check_objects.result, null, 2)
|
||||
client.disconnect()
|
||||
} // End of opGetChecks()
|
||||
|
||||
|
||||
// *******************************************************
|
||||
// ************* Operational Cash Check ******************
|
||||
// *******************************************************
|
||||
|
||||
async function opCashCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
results = 'Connecting to ' + getNet() + '....'
|
||||
operationalResultField.value = results
|
||||
await client.connect()
|
||||
results += '\nConnected.'
|
||||
operationalResultField.value = results
|
||||
|
||||
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
|
||||
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
|
||||
|
||||
var check_amount = operationalAmountField.value
|
||||
|
||||
if (operationalCurrencyField.value != "XRP") {
|
||||
check_amount = {
|
||||
"value": operationalAmountField.value,
|
||||
"currency": operationalCurrencyField.value,
|
||||
"issuer": operationalIssuerField.value
|
||||
}
|
||||
}
|
||||
const cash_check_tx = {
|
||||
"TransactionType": "CheckCash",
|
||||
"Account": operational_wallet.address,
|
||||
"Amount": check_amount,
|
||||
"CheckID": operationalCheckIDField.value
|
||||
}
|
||||
const cash_prepared = await client.autofill(cash_check_tx)
|
||||
const cash_signed = operational_wallet.sign(cash_prepared)
|
||||
results += ' Receiving ' + operationalAmountField.value + ' ' + operationalCurrencyField.value + '.\n'
|
||||
operationalResultField.value = results
|
||||
const check_result = await client.submitAndWait(cash_signed.tx_blob)
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${cash_signed.hash}'
|
||||
operationalResultField.value = results
|
||||
} else {
|
||||
results += 'Transaction failed: See JavaScript console for details.'
|
||||
operationalResultField.value = results
|
||||
throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
|
||||
}
|
||||
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
|
||||
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
|
||||
client.disconnect()
|
||||
}
|
||||
// end of opCashCheck()
|
||||
|
||||
// *******************************************************
|
||||
// ************* Operational Cancel Check ****************
|
||||
// *******************************************************
|
||||
|
||||
async function opCancelCheck() {
|
||||
let net = getNet()
|
||||
const client = new xrpl.Client(net)
|
||||
results = 'Connecting to ' + getNet() + '....'
|
||||
operationalResultField.value = results
|
||||
await client.connect()
|
||||
results += '\nConnected.'
|
||||
operationalResultField.value = results
|
||||
|
||||
const standby_wallet = xrpl.Wallet.fromSeed(standbySeedField.value)
|
||||
const operational_wallet = xrpl.Wallet.fromSeed(operationalSeedField.value)
|
||||
|
||||
const cancel_check_tx = {
|
||||
"TransactionType": "CheckCancel",
|
||||
"Account": operational_wallet.address,
|
||||
"CheckID": operationalCheckIDField.value
|
||||
}
|
||||
|
||||
const cancel_prepared = await client.autofill(cancel_check_tx)
|
||||
const cancel_signed = operational_wallet.sign(cancel_prepared)
|
||||
results += ' Cancelling check.\n'
|
||||
operationalResultField.value = results
|
||||
const check_result = await client.submitAndWait(cancel_signed.tx_blob)
|
||||
if (check_result.result.meta.TransactionResult == "tesSUCCESS") {
|
||||
results += 'Transaction succeeded: https://testnet.xrpl.org/transactions/${cash_signed.hash}'
|
||||
operationalResultField.value = results
|
||||
} else {
|
||||
results += 'Transaction failed: See JavaScript console for details.'
|
||||
operationalResultField.value = results
|
||||
throw 'Error sending transaction: ${check_result.result.meta.TransactionResult}'
|
||||
}
|
||||
standbyBalanceField.value = (await client.getXrpBalance(standby_wallet.address))
|
||||
operationalBalanceField.value = (await client.getXrpBalance(operational_wallet.address))
|
||||
client.disconnect()
|
||||
} // end of cancelCheck()
|
||||
```
|
||||
|
||||
## 10.check.html
|
||||
|
||||
```html
|
||||
<html>
|
||||
<head>
|
||||
<title>Token Test Harness</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Work Sans' rel='stylesheet'>
|
||||
<style>
|
||||
body{font-family: "Work Sans", sans-serif;padding: 20px;background: #fafafa;}
|
||||
h1{font-weight: bold;}
|
||||
input, button {padding: 6px;margin-bottom: 8px;}
|
||||
button{font-weight: bold;font-family: "Work Sans", sans-serif;}
|
||||
td{vertical-align: middle;}
|
||||
</style>
|
||||
<script src='https://unpkg.com/xrpl@2.7.0/build/xrpl-latest-min.js'></script>
|
||||
<script src='ripplex1-send-xrp.js'></script>
|
||||
<script src='ripplex2-send-currency.js'></script>
|
||||
<script src='ripplex10-check.js'></script>
|
||||
|
||||
</head>
|
||||
|
||||
<!-- ************************************************************** -->
|
||||
<!-- ********************** The Form ****************************** -->
|
||||
<!-- ************************************************************** -->
|
||||
|
||||
<body>
|
||||
<h1>Token Test Harness</h1>
|
||||
<form id="theForm">
|
||||
Choose your ledger instance:
|
||||
|
||||
<input type="radio" id="tn" name="server"
|
||||
value="wss://s.altnet.rippletest.net:51233" checked>
|
||||
<label for="testnet">Testnet</label>
|
||||
|
||||
<input type="radio" id="dn" name="server"
|
||||
value="wss://s.devnet.rippletest.net:51233">
|
||||
<label for="devnet">Devnet</label>
|
||||
<br/><br/>
|
||||
<button type="button" onClick="getAccountsFromSeeds()">Get Accounts From Seeds</button>
|
||||
<br/>
|
||||
<textarea id="seeds" cols="40" rows= "2"></textarea>
|
||||
<br/><br/>
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<td>
|
||||
<button type="button" onClick="getAccount('standby')">Get New Standby Account</button>
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
Standby Account
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="standbyAccountField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Public Key
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="standbyPubKeyField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Private Key
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="standbyPrivKeyField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Seed
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="standbySeedField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
XRP Balance
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="standbyBalanceField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Amount
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="standbyAmountField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Destination
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="standbyDestinationField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Issuer
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="standbyIssuerField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Check ID
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="standbyCheckID" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td><button type="button" onClick="configureAccount('standby',document.querySelector('#standbyDefault').checked)">Configure Account</button></td>
|
||||
<td>
|
||||
<input type="checkbox" id="standbyDefault" checked="true"/>
|
||||
<label for="standbyDefault">Allow Rippling</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Currency
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="standbyCurrencyField" size="40" value="USD"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p align="left">
|
||||
<textarea id="standbyResultField" cols="80" rows="20" ></textarea>
|
||||
</p>
|
||||
</td>
|
||||
</td>
|
||||
<td>
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="center" valign="top">
|
||||
<button type="button" onClick="sendXRP()">Send XRP></button>
|
||||
<br/><br/>
|
||||
<button type="button" onClick="sendCheck()">Send Check</button>
|
||||
<br/>
|
||||
<button type="button" onClick="getChecks()">Get Checks</button>
|
||||
<br/>
|
||||
<button type="button" onClick="cashCheck()">Cash Check</button>
|
||||
<br/>
|
||||
<button type="button" onClick="cancelCheck()">Cancel Check</button>
|
||||
<br/>
|
||||
<button type="button" onClick="getBalances()">Get Balances</button>
|
||||
</td>
|
||||
</tr>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center" valign="top">
|
||||
<button type="button" onClick="oPsendXRP()">< Send XRP</button>
|
||||
<br/><br/>
|
||||
<button type="button" onClick="opSendCheck()">Send Check</button>
|
||||
<br/>
|
||||
<button type="button" onClick="opGetChecks()">Get Checks</button>
|
||||
<br/>
|
||||
<button type="button" onClick="opCashCheck()">Cash Check</button>
|
||||
<br/>
|
||||
<button type="button" onClick="opCancelCheck()">Cancel Check</button>
|
||||
<br/>
|
||||
<button type="button" onClick="getBalances()">Get Balances</button>
|
||||
</td>
|
||||
<td valign="top" align="right">
|
||||
<button type="button" onClick="getAccount('operational')">Get New Operational Account</button>
|
||||
<table>
|
||||
<tr valign="top">
|
||||
<td align="right">
|
||||
Operational Account
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="operationalAccountField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Public Key
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="operationalPubKeyField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Private Key
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="operationalPrivKeyField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Seed
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="operationalSeedField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
XRP Balance
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="operationalBalanceField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Amount
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="operationalAmountField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Destination
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="operationalDestinationField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Issuer
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="operationalIssuerField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Check ID
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="operationalCheckIDField" size="40"></input>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
</td>
|
||||
<td align="right">
|
||||
<input type="checkbox" id="operationalDefault" checked="true"/>
|
||||
<label for="operationalDefault">Allow Rippling</label>
|
||||
<button type="button" onClick="configureAccount('operational',document.querySelector('#operationalDefault').checked)">Configure Account</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">
|
||||
Currency
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="operationalCurrencyField" size="40" value="USD"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p align="right">
|
||||
<textarea id="operationalResultField" cols="80" rows="20" ></textarea>
|
||||
</p>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
Reference in New Issue
Block a user