mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 03:35:51 +00:00
xrpl.js 2: update many mentions, more code
This commit is contained in:
2
assets/js/xrpl-2.0.0b2.min.js
vendored
2
assets/js/xrpl-2.0.0b2.min.js
vendored
File diff suppressed because one or more lines are too long
2
assets/js/xrpl-2.0.0b5.min.js
vendored
Normal file
2
assets/js/xrpl-2.0.0b5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
14
content/_code-samples/get-started/js/base.js
Normal file
14
content/_code-samples/get-started/js/base.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Wrap code in an async function so we can use await
|
||||||
|
async function main() {
|
||||||
|
|
||||||
|
// Define the network client
|
||||||
|
const client = new xrpl.Client("https://s.altnet.rippletest.net:51234/")
|
||||||
|
await client.connect()
|
||||||
|
|
||||||
|
// ... custom code goes here
|
||||||
|
|
||||||
|
// Disconnect when done so Node.js can end the process
|
||||||
|
client.disconnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
@@ -4,8 +4,7 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<!-- TODO: re-add CDN version instead of local version
|
<!-- TODO: re-add CDN version instead of local version
|
||||||
<script src="https://unpkg.com/ripple-lib@1.10.0/build/ripple-latest-min.js"></script> -->
|
<script src="https://unpkg.com/ripple-lib@1.10.0/build/ripple-latest-min.js"></script> -->
|
||||||
<script type="application/javascript" src="../../../assets/js/xrpl-2.0.0b2.min.js"></script>
|
<script type="application/javascript" src="../../../assets/js/xrpl-2.0.0b5.min.js"></script>
|
||||||
<script type="application/javascript" src="../submit-and-verify/submit-and-verify.js"></script>
|
|
||||||
<script type="application/javascript" src="require-destination-tags.js"></script>
|
<script type="application/javascript" src="require-destination-tags.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>Open your browser's console (F12) to see the logs.</body>
|
<body>Open your browser's console (F12) to see the logs.</body>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ripple-lib": "^1.10.0"
|
"ripple-lib": "^1.10.0",
|
||||||
|
"xrpl": "^2.0.0-beta.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,79 +5,50 @@
|
|||||||
// In browsers, use <script> tags as in the example demo.html.
|
// In browsers, use <script> tags as in the example demo.html.
|
||||||
if (typeof module !== "undefined") {
|
if (typeof module !== "undefined") {
|
||||||
// gotta use var here because const/let are block-scoped to the if statement.
|
// gotta use var here because const/let are block-scoped to the if statement.
|
||||||
var ripple = require('ripple-lib')
|
var xrpl = require('xrpl')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect -------------------------------------------------------------------
|
// Connect -------------------------------------------------------------------
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log("Connecting to Testnet...")
|
console.log("Connecting to Testnet...")
|
||||||
const api = new ripple.RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
|
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
|
||||||
await api.connect()
|
await client.connect()
|
||||||
|
|
||||||
// Get credentials from the Testnet Faucet -----------------------------------
|
// Get credentials from the Testnet Faucet -----------------------------------
|
||||||
console.log("Requesting addresses from the Testnet faucet...")
|
console.log("Requesting addresses from the Testnet faucet...")
|
||||||
const data = await api.generateFaucetWallet()
|
const { wallet, balance } = await client.fundWallet()
|
||||||
const address = data.account.address
|
|
||||||
const secret = data.account.secret
|
|
||||||
|
|
||||||
console.log("Waiting until we have a validated starting sequence number...")
|
|
||||||
// If you go too soon, the funding transaction might slip back a ledger and
|
|
||||||
// then your starting Sequence number will be off. This is mostly relevant
|
|
||||||
// when you want to use a Testnet account right after getting a reply from
|
|
||||||
// the faucet.
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
await api.request("account_info", {account: address, ledger_index: "validated"})
|
|
||||||
break
|
|
||||||
} catch(e) {
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Send AccountSet transaction -----------------------------------------------
|
// Send AccountSet transaction -----------------------------------------------
|
||||||
const prepared = await api.prepareTransaction({
|
const prepared = await client.autofill({
|
||||||
"TransactionType": "AccountSet",
|
"TransactionType": "AccountSet",
|
||||||
"Account": address,
|
"Account": wallet.address,
|
||||||
"SetFlag": 1 // RequireDest
|
"SetFlag": xrpl.AccountSetAsfFlags.asfRequireDest
|
||||||
})
|
})
|
||||||
console.log("Prepared transaction:", prepared.txJSON)
|
console.log("Prepared transaction:", prepared)
|
||||||
const max_ledger = prepared.instructions.maxLedgerVersion
|
const max_ledger = prepared.LastLedgerSequence
|
||||||
|
|
||||||
const signed = api.sign(prepared.txJSON, secret)
|
const signed = wallet.sign(prepared)
|
||||||
console.log("Transaction hash:", signed.id)
|
console.log("Transaction hash:", signed.hash)
|
||||||
const tx_id = signed.id
|
|
||||||
const tx_blob = signed.signedTransaction
|
|
||||||
|
|
||||||
const prelim_result = await api.request("submit", {"tx_blob": tx_blob})
|
const submit_result = await client.submitSignedReliable(signed.tx_blob)
|
||||||
console.log("Preliminary result:", prelim_result)
|
console.log("Submit result:", submit_result)
|
||||||
const min_ledger = prelim_result.validated_ledger_index
|
|
||||||
|
|
||||||
// (Semi-)reliable Transaction Submission ------------------------------------
|
|
||||||
console.log(`Begin final outcome lookup.
|
|
||||||
tx_id: ${tx_id}
|
|
||||||
max_ledger: ${max_ledger}
|
|
||||||
min_ledger: ${min_ledger}`)
|
|
||||||
let tx_status
|
|
||||||
try {
|
|
||||||
tx_status = await lookup_tx_final(api, tx_id, max_ledger, min_ledger)
|
|
||||||
} catch(err) {
|
|
||||||
tx_status = err
|
|
||||||
}
|
|
||||||
console.log("Final transaction status:", tx_status)
|
|
||||||
|
|
||||||
// Confirm Account Settings --------------------------------------------------
|
// Confirm Account Settings --------------------------------------------------
|
||||||
let account_info = await api.request("account_info", {
|
let account_info = await client.request({
|
||||||
"account": address,
|
"command": "account_info",
|
||||||
"ledger_index": "validated"
|
"account": address,
|
||||||
|
"ledger_index": "validated"
|
||||||
})
|
})
|
||||||
const flags = api.parseAccountFlags(account_info.account_data.Flags)
|
const flags = xrpl.parseAccountFlags(account_info.result.account_data.Flags)
|
||||||
console.log(JSON.stringify(flags, null, 2))
|
console.log(JSON.stringify(flags, null, 2))
|
||||||
if (flags.requireDestinationTag) {
|
if (flags.lsfRequireDestTag) {
|
||||||
console.log("Require Destination Tag is enabled.")
|
console.log("Require Destination Tag is enabled.")
|
||||||
} else {
|
} else {
|
||||||
console.log("Require Destination Tag is DISABLED.")
|
console.log("Require Destination Tag is DISABLED.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// End main()
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
17
content/_code-samples/require-destination-tags/setflagbug.js
Normal file
17
content/_code-samples/require-destination-tags/setflagbug.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const xrpl = require('xrpl')
|
||||||
|
|
||||||
|
// Connect -------------------------------------------------------------------
|
||||||
|
async function main() {
|
||||||
|
const api = new xrpl.Client('wss://s.altnet.rippletest.net:51233')
|
||||||
|
await api.connect()
|
||||||
|
const { wallet, balance } = await api.fundWallet()
|
||||||
|
const prepared = await api.autofill({
|
||||||
|
"TransactionType": "AccountSet",
|
||||||
|
"Account": wallet.address,
|
||||||
|
"SetFlag": "foo"
|
||||||
|
})
|
||||||
|
console.log("Prepared transaction:", prepared)
|
||||||
|
api.disconnect()
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
@@ -4,11 +4,11 @@ Accounts in the XRP Ledger are identified by an address in the XRP Ledger's [bas
|
|||||||
* Starts with the character `r`
|
* Starts with the character `r`
|
||||||
* Uses alphanumeric characters, excluding the number "`0`" capital letter "`O`", capital letter "`I`", and lowercase letter "`l`"
|
* Uses alphanumeric characters, excluding the number "`0`" capital letter "`O`", capital letter "`I`", and lowercase letter "`l`"
|
||||||
* Case-sensitive
|
* Case-sensitive
|
||||||
* Includes a 4-byte checksum so that the probability of generating a valid address from random characters is approximately 1 in 2^32
|
* Includes a 4-byte checksum so that the probability of generating a valid address from random characters is approximately 1 in 2<sup>32</sup>
|
||||||
|
|
||||||
> **Note:** The XRP community has [proposed](https://github.com/XRPLF/XRPL-Standards/issues/6) an **X**-address format that "packs" a [destination tag](source-and-destination-tags.html) into the address. These addresses start with an `X` (for the mainnet) or a `T` (for the [testnet](parallel-networks.html)). Exchanges and wallets can use X-addresses to represent all the data a customer needs to know in one value. For more information, see the [X-address format site](https://xrpaddress.info/) and [codec](https://github.com/xrp-community/xrpl-tagged-address-codec).
|
> **Note:** The XRP community has [proposed](https://github.com/XRPLF/XRPL-Standards/issues/6) an **X**-address format that "packs" a [destination tag](source-and-destination-tags.html) into the address. These addresses start with an `X` (for the mainnet) or a `T` (for the [testnet](parallel-networks.html)). Exchanges and wallets can use X-addresses to represent all the data a customer needs to know in one value. For more information, see the [X-address format site](https://xrpaddress.info/) and [codec](https://github.com/xrp-community/xrpl-tagged-address-codec).
|
||||||
>
|
>
|
||||||
> The XRP Ledger protocol only supports "classic" addresses natively, but [ripple-lib](rippleapi-reference.html), [`xrpl-py`](https://github.com/XRPLF/xrpl-py), and many other tools support X-addresses too.
|
> The XRP Ledger protocol only supports "classic" addresses natively, but many [client libraries](client-libraries.html) support X-addresses too.
|
||||||
|
|
||||||
{% if currentpage.md != "concept-accounts.md" %}
|
{% if currentpage.md != "concept-accounts.md" %}
|
||||||
For more information, see [Accounts](accounts.html) and [base58 Encodings](base58-encodings.html).
|
For more information, see [Accounts](accounts.html) and [base58 Encodings](base58-encodings.html).
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
| Language | Library Name | Get Started | API Reference | Source Code |
|
|
||||||
|----------|--------------|-------------|---------------|-------------|
|
|
||||||
| **Python** | `xrpl-py` | [Get Started](get-started-using-python.html) | [API Reference](https://xrpl-py.readthedocs.io/) | [Repo](https://github.com/XRPLF/xrpl-py) |
|
|
||||||
| **JavaScript** / **TypeScript** | `ripple-lib` | [Get Started](get-started-with-rippleapi-for-javascript.html) | [API Reference](rippleapi-reference.html) | [Repo](https://github.com/XRPLF/xrpl.js) |
|
|
||||||
| **Java** | `xrpl4j` | [README](https://github.com/XRPLF/xrpl4j#readme) | [API Reference](https://github.com/XRPLF/xrpl4j/tree/main/xrpl4j-integration-tests) | [Repo](https://github.com/XRPLF/xrpl4j) |
|
|
||||||
@@ -82,7 +82,7 @@ To support interest-bearing and demurraging currencies, client applications must
|
|||||||
|
|
||||||
### ripple-lib Support
|
### ripple-lib Support
|
||||||
|
|
||||||
Demurrage was supported in ripple-lib versions **0.7.37** through **0.12.9**. Demurrage is ***not supported*** in [RippleAPI](rippleapi-reference.html).
|
Demurrage was supported in ripple-lib versions **0.7.37** through **0.12.9**. Demurrage is ***not supported*** in most modern libraries.
|
||||||
|
|
||||||
The following code samples demonstrate how to use compatible versions of ripple-lib to convert between ledger values and display values. Also see the [Ripple Demurrage Calculator](https://ripple.github.io/ripple-demurrage-tool/).
|
The following code samples demonstrate how to use compatible versions of ripple-lib to convert between ledger values and display values. Also see the [Ripple Demurrage Calculator](https://ripple.github.io/ripple-demurrage-tool/).
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,7 @@ To make a digital signature, you use a cryptographic key pair associated with th
|
|||||||
|
|
||||||
## Generating Keys
|
## Generating Keys
|
||||||
|
|
||||||
There are several ways to create a key pair:
|
Many [client libraries](client-libraries.html) and applications can generate a key pair suitable for use with the XRP Ledger. However, you should only use keypairs that were generated with devices and software you trust. Compromised applications can expose your secret to malicious users who can then send transactions from your account later.
|
||||||
|
|
||||||
- The [wallet_propose method][] in [the `rippled` server](the-rippled-server.html).
|
|
||||||
- The [`generateAddress()` method of ripple-lib](rippleapi-reference.html#generateaddress).
|
|
||||||
- Other [tools or wallet applications](software-ecosystem.html). <!-- STYLE_OVERRIDE: wallet -->
|
|
||||||
|
|
||||||
|
|
||||||
## Key Components
|
## Key Components
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ For other programming languages, you can access the XRP Ledger through the [HTTP
|
|||||||
| Language | Library Name | Get Started | API Reference | Source Code |
|
| Language | Library Name | Get Started | API Reference | Source Code |
|
||||||
|----------|--------------|-------------|---------------|-------------|
|
|----------|--------------|-------------|---------------|-------------|
|
||||||
| **Python** | `xrpl-py` | [Get Started Using Python](get-started-using-python.html) | [API Reference](https://xrpl-py.readthedocs.io/) | [Repo](https://github.com/XRPLF/xrpl-py) |
|
| **Python** | `xrpl-py` | [Get Started Using Python](get-started-using-python.html) | [API Reference](https://xrpl-py.readthedocs.io/) | [Repo](https://github.com/XRPLF/xrpl-py) |
|
||||||
| **JavaScript** / **TypeScript** | `ripple-lib` | [Get Started](get-started-using-node-js.html) | [API Reference](rippleapi-reference.html) | [Repo](https://github.com/XRPLF/xrpl.js) |
|
| **JavaScript** / **TypeScript** | `xrpl.js` | [Get Started](get-started-using-javascript.html) | [API Reference](https://xrplf.github.io/xrpl.js/) | [Repo](https://github.com/XRPLF/xrpl.js) |
|
||||||
| **C++** | `rippled` Signing Library | [Get Started](https://github.com/ripple/rippled/tree/develop/Builds/linux#signing-library) | | (Part of [`rippled`](https://github.com/ripple/rippled/)) |
|
| **C++** | `rippled` Signing Library | [Get Started](https://github.com/ripple/rippled/tree/develop/Builds/linux#signing-library) | | (Part of [`rippled`](https://github.com/ripple/rippled/)) |
|
||||||
| **Java** | `xrpl4j` | [Get Started Using Java](get-started-using-java.html) | [API Reference](https://javadoc.io/doc/org.xrpl/) | [Repo](https://github.com/XRPLF/xrpl4j) |
|
| **Java** | `xrpl4j` | [Get Started Using Java](get-started-using-java.html) | [API Reference](https://javadoc.io/doc/org.xrpl/) | [Repo](https://github.com/XRPLF/xrpl4j) |
|
||||||
| **Ruby** | `xrbp` | | [API Reference](https://www.rubydoc.info/gems/xrbp) | [Repo](https://github.com/DevNullProd/xrbp) |
|
| **Ruby** | `xrbp` | | [API Reference](https://www.rubydoc.info/gems/xrbp) | [Repo](https://github.com/DevNullProd/xrbp) |
|
||||||
|
|||||||
@@ -62,11 +62,7 @@ The serialization processes described here are implemented in multiple places an
|
|||||||
- In JavaScript in the [`ripple-binary-codec`](https://github.com/ripple/ripple-binary-codec/) package.
|
- In JavaScript in the [`ripple-binary-codec`](https://github.com/ripple/ripple-binary-codec/) package.
|
||||||
- In Python 3 in [this repository's code samples section]({{target.github_forkurl}}/blob/{{target.github_branch}}/content/_code-samples/tx-serialization/serialize.py).
|
- In Python 3 in [this repository's code samples section]({{target.github_forkurl}}/blob/{{target.github_branch}}/content/_code-samples/tx-serialization/serialize.py).
|
||||||
|
|
||||||
Additionally, the following libraries also provide serialization support:
|
Additionally, many [client libraries](client-libraries) provide serialization support under permissive open-source licenses, so you can import, use, or adapt the code for your needs.
|
||||||
|
|
||||||
{% include '_snippets/libs-snippet.md' %}
|
|
||||||
|
|
||||||
These implementations are all provided with permissive open-source licenses, so you can import, use, or adapt the code for your needs.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ The `AccountTxnID` field cannot be used on transactions that use [Tickets](ticke
|
|||||||
|
|
||||||
## Auto-fillable Fields
|
## Auto-fillable Fields
|
||||||
|
|
||||||
Some fields can be automatically filled in before a transaction is signed, either by a `rippled` server or by a library used for signing such as [ripple-lib][]. Auto-filling values requires an active connection to the XRP Ledger to get the latest state, so it cannot be done offline. Both [ripple-lib][] and `rippled` can automatically provide the following values:
|
Some fields can be automatically filled in before a transaction is signed, either by a `rippled` server or by a [client library](client-libraries.html). Auto-filling values requires an active connection to the XRP Ledger to get the latest state, so it cannot be done offline. The details can vary by library, but auto-filling always provides suitable values for at least the following fields:
|
||||||
|
|
||||||
* `Fee` - Automatically fill in the [Transaction Cost][] based on the network.
|
* `Fee` - Automatically fill in the [Transaction Cost][] based on the network.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
html: get-started-using-node-js.html
|
html: get-started-using-javascript.html
|
||||||
parent: get-started.html
|
parent: get-started.html
|
||||||
blurb: XRP Ledgerに照会するエントリーレベルのJavaScriptアプリケーションを構築します。
|
blurb: XRP Ledgerに照会するエントリーレベルのJavaScriptアプリケーションを構築します。
|
||||||
top_nav_name: JavaScript
|
top_nav_name: JavaScript
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
---
|
---
|
||||||
html: get-started-using-node-js.html
|
html: get-started-using-javascript.html
|
||||||
parent: get-started.html
|
parent: get-started.html
|
||||||
blurb: Build an entry-level JavaScript application for querying the XRP Ledger in Node.js.
|
blurb: Build an entry-level JavaScript application for querying the XRP Ledger.
|
||||||
top_nav_name: JavaScript
|
top_nav_name: JavaScript
|
||||||
top_nav_grouping: Get Started
|
top_nav_grouping: Get Started
|
||||||
|
filters:
|
||||||
|
- include_code
|
||||||
labels:
|
labels:
|
||||||
- Development
|
- Development
|
||||||
showcase_icon: assets/img/logos/javascript.svg
|
showcase_icon: assets/img/logos/javascript.svg
|
||||||
---
|
---
|
||||||
# Get Started Using JavaScript
|
# Get Started Using JavaScript
|
||||||
|
|
||||||
This tutorial guides you through the basics of building an XRP Ledger-connected application in JavaScript or TypeScript using the [xrpl.js](https://github.com/XRPLF/xrpl.js/) client library in Node.js.
|
This tutorial guides you through the basics of building an XRP Ledger-connected application in JavaScript or TypeScript using the [`xrpl.js`](https://github.com/XRPLF/xrpl.js/) client library in either Node.js or web browsers.
|
||||||
|
|
||||||
The scripts and config files used in this guide are [available in this website's GitHub Repository](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/rippleapi_quickstart).
|
The scripts and config files used in this guide are [available in this website's GitHub Repository](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/rippleapi_quickstart).
|
||||||
|
|
||||||
@@ -22,29 +24,18 @@ In this tutorial, you'll learn:
|
|||||||
* The basic building blocks of XRP Ledger-based applications.
|
* The basic building blocks of XRP Ledger-based applications.
|
||||||
* How to connect to the XRP Ledger using xrpl.js.
|
* How to connect to the XRP Ledger using xrpl.js.
|
||||||
* How to generate a wallet on the [Testnet](xrp-testnet-faucet.html) using xrpl.js.
|
* How to generate a wallet on the [Testnet](xrp-testnet-faucet.html) using xrpl.js.
|
||||||
* How to use the xrpl.js library to look up information about an account on the XRP Ledger.
|
* How to use the `xrpl.js` library to look up information about an account on the XRP Ledger.
|
||||||
* How to put these steps together to create a simple JavaScript app or web-app.
|
* How to put these steps together to create a simple JavaScript app or web-app.
|
||||||
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
The xrpl.js library is intended for use with Node.js version 14. It may work with other versions, but they aren't regularly tested. If you have Node.js installed, you can check the version of the `node` binary from a command line:
|
To follow this tutorial, you should have some familiarity with writing code in JavaScript and managing small JavaScript projects. In browsers, any modern web browser with JavaScript support should work fine. In Node.js, **version 14** is recommended. It may work with other versions, but they aren't regularly tested.
|
||||||
|
|
||||||
```sh
|
|
||||||
node --version
|
|
||||||
```
|
|
||||||
|
|
||||||
On some platforms, the binary is named `nodejs` instead:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
nodejs --version
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Install with npm
|
## Install with npm
|
||||||
|
|
||||||
Start a new project by creating an empty folder, then change into that folder and use NPM to install the latest version of xrpl.js:
|
Start a new project by creating an empty folder, then change into that folder and use [NPM](https://www.npmjs.com/) to install the latest version of xrpl.js:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm install xrpl
|
npm install xrpl
|
||||||
@@ -55,40 +46,55 @@ npm install xrpl
|
|||||||
|
|
||||||
When you're working with the XRP Ledger, there are a few things you'll need to manage, whether you're adding XRP into your [wallet](wallets.html), integrating with the [decentralized exchange](decentralized-exchange.html), or [issuing tokens](issued-currencies.html). This tutorial walks you through basic patterns common to getting started with all of these use cases and provides sample code for implementing them.
|
When you're working with the XRP Ledger, there are a few things you'll need to manage, whether you're adding XRP into your [wallet](wallets.html), integrating with the [decentralized exchange](decentralized-exchange.html), or [issuing tokens](issued-currencies.html). This tutorial walks you through basic patterns common to getting started with all of these use cases and provides sample code for implementing them.
|
||||||
|
|
||||||
Here are the basic steps you'll need to cover for almost any XRP Ledger project:
|
Here are some steps you use in many XRP Ledger projects:
|
||||||
|
|
||||||
1. [Connect to the XRP Ledger.](#1-connect-to-the-xrp-ledger)
|
1. [Import the library](#1-import-the-library)
|
||||||
1. [Generate a wallet.](#2-generate-wallet)
|
1. [Connect to the XRP Ledger.](#2-connect-to-the-xrp-ledger)
|
||||||
1. [Query the XRP Ledger.](#3-query-the-xrp-ledger)
|
1. [Generate a wallet.](#3-generate-wallet)
|
||||||
|
1. [Query the XRP Ledger.](#4-query-the-xrp-ledger)
|
||||||
|
1. [Listen for Events.](#5-listen-for-events)
|
||||||
|
|
||||||
|
### 1. Import the Library
|
||||||
|
|
||||||
### 1. Connect to the XRP Ledger
|
How you load `xrpl.js` into your project depends on your development environment:
|
||||||
|
|
||||||
To make queries and submit transactions, you need to establish a connection to the XRP Ledger. To do this with xrpl.js, you create an instance of the `Client` class and use the `connect()` method.
|
#### Web Browsers
|
||||||
|
|
||||||
**Tip:** Many network functions in xrpl.js use [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to return values asynchronously. The code samples here use the [`async/await` pattern](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await) to wait for the actual result of the Promises.
|
Add a `<script>` tag such as the following to your HTML:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src="https://unpkg.com/xrpl@2.0.0/build/xrpl-latest-min.js"></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
You can load the library from a CDN as in the above example, or download a release and host it on your own website.
|
||||||
|
|
||||||
|
***TODO: get a working CDN URL when released***
|
||||||
|
|
||||||
|
This loads the module into the top level as `xrpl`.
|
||||||
|
|
||||||
|
#### Node.js
|
||||||
|
|
||||||
|
Add the library using [npm](https://www.npmjs.com/). This updates your `package.json` file, or creates a new one if it didn't already exist:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install xrpl
|
||||||
|
```
|
||||||
|
|
||||||
|
Then import the library:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Import the library
|
|
||||||
const xrpl = require("xrpl")
|
const xrpl = require("xrpl")
|
||||||
|
|
||||||
// Wrap code in an async function so we can use await
|
|
||||||
async function main() {
|
|
||||||
|
|
||||||
// Define the network client
|
|
||||||
const SERVER_URL = "https://s.altnet.rippletest.net:51234/"
|
|
||||||
const client = new xrpl.Client(SERVER_URL)
|
|
||||||
await client.connect()
|
|
||||||
|
|
||||||
// ... custom code goes here
|
|
||||||
|
|
||||||
// Disconnect when done so Node.js can end the process
|
|
||||||
client.disconnect()
|
|
||||||
}
|
|
||||||
|
|
||||||
main()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 2. Connect to the XRP Ledger
|
||||||
|
|
||||||
|
To make queries and submit transactions, you need to establish a connection to the XRP Ledger. To do this with `xrpl.js`, you create an instance of the `Client` class and use the `connect()` method.
|
||||||
|
|
||||||
|
**Tip:** Many network functions in `xrpl.js` use [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to return values asynchronously. The code samples here use the [`async/await` pattern](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await) to wait for the actual result of the Promises.
|
||||||
|
|
||||||
|
{{ include_code("_code-samples/get-started/js/base.js", language="js") }}
|
||||||
|
|
||||||
#### Connect to the production XRP Ledger
|
#### Connect to the production XRP Ledger
|
||||||
|
|
||||||
The sample code in the previous section shows you how to connect to the Testnet, which is one of the available [parallel networks](parallel-networks.html). When you're ready to integrate with the production XRP Ledger, you'll need to connect to the Mainnet. You can do that in two ways:
|
The sample code in the previous section shows you how to connect to the Testnet, which is one of the available [parallel networks](parallel-networks.html). When you're ready to integrate with the production XRP Ledger, you'll need to connect to the Mainnet. You can do that in two ways:
|
||||||
@@ -108,9 +114,9 @@ The sample code in the previous section shows you how to connect to the Testnet,
|
|||||||
await client.connect()
|
await client.connect()
|
||||||
|
|
||||||
|
|
||||||
### 2. Generate Wallet
|
### 3. Generate Wallet
|
||||||
|
|
||||||
The xrpl.js library has a Wallet class for handling the keys and address of an XRP Ledger account. On Testnet, you can fund a new wallet like this:
|
The `xrpl.js` library has a `Wallet` class for handling the keys and address of an XRP Ledger account. On Testnet, you can fund a new wallet like this:
|
||||||
|
|
||||||
{{ include_code("_code-samples/get-started/js/get-acct-info.js", start_with="// Create a wallet", end_before="// Get info", language="js") }}
|
{{ include_code("_code-samples/get-started/js/get-acct-info.js", start_with="// Create a wallet", end_before="// Get info", language="js") }}
|
||||||
|
|
||||||
@@ -126,23 +132,23 @@ Or, if you already have a seed encoded in [base58][], you can instantiate a Wall
|
|||||||
const test_wallet = xrpl.Wallet.fromSeed("sn3nxiW7v8KXzPzAqzyHXbSSKNuN9") // Test secret; don't use for real
|
const test_wallet = xrpl.Wallet.fromSeed("sn3nxiW7v8KXzPzAqzyHXbSSKNuN9") // Test secret; don't use for real
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. Query the XRP Ledger
|
### 4. Query the XRP Ledger
|
||||||
|
|
||||||
Use the Client's `request()` method to access the XRP Ledger's [WebSocket API](https://xrpl.org/request-formatting.html). For example:
|
Use the Client's `request()` method to access the XRP Ledger's [WebSocket API](https://xrpl.org/request-formatting.html). For example:
|
||||||
|
|
||||||
{{ include_code("_code-samples/get-started/js/get-acct-info.js", start_with="// Get info", end_before="// Listen to ledger close events", language="js") }}
|
{{ include_code("_code-samples/get-started/js/get-acct-info.js", start_with="// Get info", end_before="// Listen to ledger close events", language="js") }}
|
||||||
|
|
||||||
|
|
||||||
### 4. Listen for Events
|
### 5. Listen for Events
|
||||||
|
|
||||||
You can set up handlers for various types of events in xrpl.js, such as whenever the XRP Ledger's [consensus process](intro-to-consensus.html) produces a new [ledger version](ledgers.html). To do that, first call the [subscribe method][] to get the type of events you want, then attach an event handler using the `on(eventType, callback)` method of the client.
|
You can set up handlers for various types of events in `xrpl.js`, such as whenever the XRP Ledger's [consensus process](intro-to-consensus.html) produces a new [ledger version](ledgers.html). To do that, first call the [subscribe method][] to get the type of events you want, then attach an event handler using the `on(eventType, callback)` method of the client.
|
||||||
|
|
||||||
{{ include_code("_code-samples/get-started/js/get-acct-info.js", start_with="// Listen to ledger close events", end_before="// Disconnect when done", language="js") }}
|
{{ include_code("_code-samples/get-started/js/get-acct-info.js", start_with="// Listen to ledger close events", end_before="// Disconnect when done", language="js") }}
|
||||||
|
|
||||||
|
|
||||||
## Keep on Building
|
## Keep on Building
|
||||||
|
|
||||||
Now that you know how to use xrpl.js to connect to the XRP Ledger, generate a wallet, and look up information about an account, you can also:
|
Now that you know how to use `xrpl.js` to connect to the XRP Ledger, generate a wallet, and look up information about an account, you can also:
|
||||||
|
|
||||||
* [Send XRP](send-xrp.html).
|
* [Send XRP](send-xrp.html).
|
||||||
* [Issue a Fungible Token](issue-a-fungible-token.html)
|
* [Issue a Fungible Token](issue-a-fungible-token.html)
|
||||||
@@ -157,7 +163,7 @@ Now that you know how to use xrpl.js to connect to the XRP Ledger, generate a wa
|
|||||||
- **Tutorials:**
|
- **Tutorials:**
|
||||||
- [Send XRP](send-xrp.html)
|
- [Send XRP](send-xrp.html)
|
||||||
- **References:**
|
- **References:**
|
||||||
- [xrpl.js Reference](TODO: final link for new reference docs)
|
- [`xrpl.js` Reference](https://xrplf.github.io/xrpl.js/)
|
||||||
- [Public API Methods](public-rippled-methods.html)
|
- [Public API Methods](public-rippled-methods.html)
|
||||||
- [API Conventions](api-conventions.html)
|
- [API Conventions](api-conventions.html)
|
||||||
- [base58 Encodings](base58-encodings.html)
|
- [base58 Encodings](base58-encodings.html)
|
||||||
@@ -11,7 +11,7 @@ labels:
|
|||||||
|
|
||||||
The XRP Ledger is always online and entirely public. Anyone can access it **directly from a web browser** with source code like what's on this page.
|
The XRP Ledger is always online and entirely public. Anyone can access it **directly from a web browser** with source code like what's on this page.
|
||||||
|
|
||||||
The following example gets the latest [ledger version](ledgers.html) and a list of transactions that were newly-validated in that ledger version, using the [`getLedger()` method](rippleapi-reference.html#getledger). Try running it as-is, or change the code and see what happens.
|
The following example gets the latest [ledger version](ledgers.html) and a list of transactions that were newly-validated in that ledger version, using the [ledger method][]. Try running it as-is, or change the code and see what happens.
|
||||||
|
|
||||||
**Tip:** If you can, open your browser's Developer Tools by pressing **F12**. The "Console" tab provides a native JavaScript console and can give insight into what code is running on any webpage. <!-- SPELLING_IGNORE: f12 -->
|
**Tip:** If you can, open your browser's Developer Tools by pressing **F12**. The "Console" tab provides a native JavaScript console and can give insight into what code is running on any webpage. <!-- SPELLING_IGNORE: f12 -->
|
||||||
|
|
||||||
@@ -21,69 +21,69 @@ The following example gets the latest [ledger version](ledgers.html) and a list
|
|||||||
<!-- JS_EDITOR_START step2 -->
|
<!-- JS_EDITOR_START step2 -->
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const mainnet = new ripple.RippleAPI({
|
async function main() {
|
||||||
server: 'wss://s1.ripple.com'
|
const api = new xrpl.Client('wss://xrplcluster.com');
|
||||||
});
|
|
||||||
|
|
||||||
(async function(api) {
|
|
||||||
await api.connect();
|
await api.connect();
|
||||||
|
|
||||||
let response = await api.getLedger({
|
let response = await api.request({
|
||||||
includeTransactions: true
|
"command": "ledger",
|
||||||
|
"ledger_index": "validated"
|
||||||
|
"transactions": true
|
||||||
});
|
});
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
}
|
||||||
})(mainnet);
|
main()
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const mainnet = new ripple.RippleAPI({
|
async function main() {
|
||||||
server: 'wss://s.altnet.rippletest.net/'
|
const api = new xrpl.Client('wss://s.altnet.rippletest.net/');
|
||||||
});
|
|
||||||
|
|
||||||
(async function(api) {
|
|
||||||
await api.connect();
|
await api.connect();
|
||||||
|
|
||||||
let response = await api.getLedger({
|
let response = await api.request({
|
||||||
includeTransactions: true
|
"command": "ledger",
|
||||||
});
|
"ledger_index": "validated"
|
||||||
|
"transactions": true
|
||||||
|
});
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
}
|
||||||
})(mainnet);
|
main()
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const mainnet = new ripple.RippleAPI({
|
async function main() {
|
||||||
server: 'wss://s1.ripple.com'
|
const api = new xrpl.Client('wss://xrplcluster.com');
|
||||||
});
|
|
||||||
|
|
||||||
(async function(api) {
|
|
||||||
await api.connect();
|
await api.connect();
|
||||||
|
|
||||||
let response = await api.getLedger({
|
let response = await api.request({
|
||||||
includeTransactions: true
|
"command": "ledger",
|
||||||
});
|
"ledger_index": "validated"
|
||||||
let tx_id = response.transactionHashes[0];
|
"transactions": true
|
||||||
let response2 = await api.getTransaction(tx_id);
|
});
|
||||||
|
|
||||||
|
let tx_id = response.result.transactions[0];
|
||||||
|
let response2 = await api.request({
|
||||||
|
"command": "tx",
|
||||||
|
"transaction": tx_id
|
||||||
|
});
|
||||||
console.log(response2);
|
console.log(response2);
|
||||||
|
}
|
||||||
})(mainnet);
|
main()
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const mainnet = new ripple.RippleAPI({
|
async function main() {
|
||||||
server: 'wss://s1.ripple.com'
|
const api = new xrpl.Client('wss://xrplcluster.com');
|
||||||
});
|
|
||||||
|
|
||||||
(async function(api) {
|
|
||||||
await api.connect();
|
await api.connect();
|
||||||
|
|
||||||
let response = await api.getLedger({
|
let response = await api.request({
|
||||||
includeTransactions: true
|
"command": "ledger",
|
||||||
});
|
"ledger_index": "validated"
|
||||||
console.log('Total XRP: '+api.dropsToXrp(response.totalDrops));
|
"transactions": true
|
||||||
|
});
|
||||||
})(mainnet);
|
console.log('Total XRP: '+xrpl.dropsToXrp(response.result.ledger.total_coins));
|
||||||
|
}
|
||||||
|
main()
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- JS_EDITOR_END -->
|
<!-- JS_EDITOR_END -->
|
||||||
@@ -100,7 +100,7 @@ Try editing the code above to do something different:
|
|||||||
|
|
||||||
## Setup Steps
|
## Setup Steps
|
||||||
|
|
||||||
This page has the necessary prerequisites already loaded, but you can access the XRP Ledger from **any webpage** if you load [RippleAPI for JavaScript (ripple-lib)](rippleapi-reference.html) in that page's HTML. For example:
|
This page has the necessary prerequisites already loaded, but you can access the XRP Ledger from **any webpage** if you load [xrpl.js](https://github.com/XRPLF/xrpl.js/) in that page's HTML. For example:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="https://unpkg.com/ripple-lib@1.10.0/build/ripple-latest-min.js"></script>
|
<script src="https://unpkg.com/ripple-lib@1.10.0/build/ripple-latest-min.js"></script>
|
||||||
@@ -115,3 +115,8 @@ When you're ready to move on, continue using the XRP Ledger with these resources
|
|||||||
- [Use the RippleAPI Reference](rippleapi-reference.html) to see what else you can do.
|
- [Use the RippleAPI Reference](rippleapi-reference.html) to see what else you can do.
|
||||||
- [Install `rippled`](install-rippled.html) to participate in the network.
|
- [Install `rippled`](install-rippled.html) to participate in the network.
|
||||||
- [Get Testnet XRP](xrp-testnet-faucet.html) to try sending and receiving payments.
|
- [Get Testnet XRP](xrp-testnet-faucet.html) to try sending and receiving payments.
|
||||||
|
|
||||||
|
<!--{# common link defs #}-->
|
||||||
|
{% include '_snippets/rippled-api-links.md' %}
|
||||||
|
{% include '_snippets/tx-type-links.md' %}
|
||||||
|
{% include '_snippets/rippled_versions.md' %}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ top_nav_grouping: Popular Pages
|
|||||||
---
|
---
|
||||||
# Send XRP
|
# Send XRP
|
||||||
|
|
||||||
This tutorial explains how to send a simple XRP Payment using ripple-lib for JavaScript, `xrpl-py` for Python, or xrpl4j for Java. First, we step through the process with the [XRP Ledger Testnet](parallel-networks.html). Then, we compare that to the additional requirements for doing the equivalent in production.
|
This tutorial explains how to send a simple XRP Payment using `xrpl.js` for JavaScript, `xrpl-py` for Python, or xrpl4j for Java. First, we step through the process with the [XRP Ledger Testnet](parallel-networks.html). Then, we compare that to the additional requirements for doing the equivalent in production.
|
||||||
|
|
||||||
**Tip:** Check out the [Code Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples) for a complete version of the code used in this tutorial.
|
**Tip:** Check out the [Code Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples) for a complete version of the code used in this tutorial.
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ This tutorial explains how to send a simple XRP Payment using ripple-lib for Jav
|
|||||||
|
|
||||||
To interact with the XRP Ledger, you need to set up a dev environment with the necessary tools. This tutorial provides examples using the following options:
|
To interact with the XRP Ledger, you need to set up a dev environment with the necessary tools. This tutorial provides examples using the following options:
|
||||||
|
|
||||||
- **JavaScript** with the [ripple-lib (RippleAPI) library](https://github.com/XRPLF/xrpl.js/). See the [RippleAPI Beginners Guide](get-started-with-rippleapi-for-javascript.html) for detailed instructions on getting started.
|
- **JavaScript** with the [xrpl.js library](https://github.com/XRPLF/xrpl.js/). See [Get Started Using JavaScript](get-started-using-javascript.html) for setup steps.
|
||||||
- **Python** with the [`xrpl-py` library](https://xrpl-py.readthedocs.io/). See [Get Started using Python](get-started-using-python.html) for setup steps.
|
- **Python** with the [`xrpl-py` library](https://xrpl-py.readthedocs.io/). See [Get Started using Python](get-started-using-python.html) for setup steps.
|
||||||
- **Java** with the [xrpl4j library](https://github.com/XRPLF/xrpl4j). See [Get Started Using Java](get-started-using-java.html) for setup steps.
|
- **Java** with the [xrpl4j library](https://github.com/XRPLF/xrpl4j). See [Get Started Using Java](get-started-using-java.html) for setup steps.
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ The bare minimum set of instructions you must provide for an XRP Payment is:
|
|||||||
|
|
||||||
Technically, a viable transaction must contain some additional fields, and certain optional fields such as `LastLedgerSequence` are strongly recommended. Some other language-specific notes:
|
Technically, a viable transaction must contain some additional fields, and certain optional fields such as `LastLedgerSequence` are strongly recommended. Some other language-specific notes:
|
||||||
|
|
||||||
- If you're using ripple-lib for JavaScript, you can use the [`prepareTransaction()` method](rippleapi-reference.html#preparetransaction) to automatically fill in good defaults for the remaining fields of a transaction.
|
- If you're using `xrpl.js` for JavaScript or TypeScript, you can use the [`Client.autofill()` method](TODO: link autofill) to automatically fill in good defaults for the remaining fields of a transaction.
|
||||||
- With `xrpl-py` for Python, you can use the models in `xrpl.models.transactions` to construct transactions as native Python objects.
|
- With `xrpl-py` for Python, you can use the models in `xrpl.models.transactions` to construct transactions as native Python objects.
|
||||||
- With xrpl4j for Java, you can use the model objects in the `xrpl4j-model` module to construct transactions as Java objects.
|
- With xrpl4j for Java, you can use the model objects in the `xrpl4j-model` module to construct transactions as Java objects.
|
||||||
- Unlike the other libraries, you must provide the account `sequence` and the `signingPublicKey` of the source
|
- Unlike the other libraries, you must provide the account `sequence` and the `signingPublicKey` of the source
|
||||||
@@ -156,7 +156,7 @@ _Java_
|
|||||||
|
|
||||||
Signing a transaction uses your credentials to authorize the transaction on your behalf. The input to this step is a completed set of transaction instructions (usually JSON), and the output is a binary blob containing the instructions and a signature from the sender.
|
Signing a transaction uses your credentials to authorize the transaction on your behalf. The input to this step is a completed set of transaction instructions (usually JSON), and the output is a binary blob containing the instructions and a signature from the sender.
|
||||||
|
|
||||||
- **JavaScript:** Use the [sign() method](rippleapi-reference.html#sign) to sign the transaction with ripple-lib. The first argument is a string version of the JSON transaction to sign.
|
- **JavaScript:** Use the [sign() method of a Wallet instance](TODO: link sign) to sign the transaction with `xrpl.js`.
|
||||||
- **Python:** Use the [`xrpl.transaction.safe_sign_transaction()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.safe_sign_transaction) with a model and wallet object.
|
- **Python:** Use the [`xrpl.transaction.safe_sign_transaction()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.safe_sign_transaction) with a model and wallet object.
|
||||||
- **Java:** Use a [`SignatureService`](https://javadoc.io/doc/org.xrpl/xrpl4j-crypto-core/latest/org/xrpl/xrpl4j/crypto/signing/SignatureService.html) instance to sign the transaction. For this tutorial, use the [`SingleKeySignatureService`](https://javadoc.io/doc/org.xrpl/xrpl4j-crypto-bouncycastle/latest/org/xrpl/xrpl4j/crypto/signing/SingleKeySignatureService.html).
|
- **Java:** Use a [`SignatureService`](https://javadoc.io/doc/org.xrpl/xrpl4j-crypto-core/latest/org/xrpl/xrpl4j/crypto/signing/SignatureService.html) instance to sign the transaction. For this tutorial, use the [`SingleKeySignatureService`](https://javadoc.io/doc/org.xrpl/xrpl4j-crypto-bouncycastle/latest/org/xrpl/xrpl4j/crypto/signing/SingleKeySignatureService.html).
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ _Java_
|
|||||||
|
|
||||||
The result of the signing operation is a transaction object containing a signature. Typically, XRP Ledger APIs expect a signed transaction to be the hexadecimal representation of the transaction's canonical [binary format](serialization.html), called a "blob".
|
The result of the signing operation is a transaction object containing a signature. Typically, XRP Ledger APIs expect a signed transaction to be the hexadecimal representation of the transaction's canonical [binary format](serialization.html), called a "blob".
|
||||||
|
|
||||||
- In ripple-lib, the signing API also returns the transaction's ID, or identifying hash, which you can use to look up the transaction later. This is a 64-character hexadecimal string that is unique to this transaction.
|
- In `xrpl.js`, the signing API also returns the transaction's ID, or identifying hash, which you can use to look up the transaction later. This is a 64-character hexadecimal string that is unique to this transaction.
|
||||||
- In `xrpl-py`, you can get the transaction's hash in the response to submitting it in the next step.
|
- In `xrpl-py`, you can get the transaction's hash in the response to submitting it in the next step.
|
||||||
- In xrpl4j, `SignatureService.sign` returns a `SignedTransaction`, which contains the transaction's hash, which you can use to look up the transaction later.
|
- In xrpl4j, `SignatureService.sign` returns a `SignedTransaction`, which contains the transaction's hash, which you can use to look up the transaction later.
|
||||||
|
|
||||||
@@ -196,8 +196,8 @@ The result of the signing operation is a transaction object containing a signatu
|
|||||||
|
|
||||||
Now that you have a signed transaction, you can submit it to an XRP Ledger server, and that server will relay it through the network. It's also a good idea to take note of the latest validated ledger index before you submit. The earliest ledger version that your transaction could get into as a result of this submission is one higher than the latest validated ledger when you submit it. Of course, if the same transaction was previously submitted, it could already be in a previous ledger. (It can't succeed a second time, but you may not realize it succeeded if you aren't looking in the right ledger versions.)
|
Now that you have a signed transaction, you can submit it to an XRP Ledger server, and that server will relay it through the network. It's also a good idea to take note of the latest validated ledger index before you submit. The earliest ledger version that your transaction could get into as a result of this submission is one higher than the latest validated ledger when you submit it. Of course, if the same transaction was previously submitted, it could already be in a previous ledger. (It can't succeed a second time, but you may not realize it succeeded if you aren't looking in the right ledger versions.)
|
||||||
|
|
||||||
- **JavaScript:** Use the [`submit()` method](rippleapi-reference.html#submit) to submit a transaction to the network. Use the [`getLedgerVersion()` method](rippleapi-reference.html#getledgerversion) to get the latest validated ledger index.
|
- **JavaScript:** Use the [`submitReliable()` method of the Client](TODO: link) to submit a transaction to the network and wait for the response.
|
||||||
- **Python:** Use the [`xrpl.transaction.submit_transaction()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.submit_transaction) to submit a transaction to the network. Use the [`xrpl.ledger.get_latest_validated_ledger_sequence()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.ledger.html#xrpl.ledger.get_latest_validated_ledger_sequence) to get the latest validated ledger index.
|
- **Python:** Use the [`xrpl.transaction.send_reliable_submission()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.send_reliable_submission) to submit a transaction to the network and wait for a response.
|
||||||
- **Java:** Use the [`XrplClient.submit(SignedTransaction)` method](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#submit(org.xrpl.xrpl4j.crypto.signing.SignedTransaction)) to submit a transaction to the network. Use the [`XrplClient.ledger()`](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#ledger(org.xrpl.xrpl4j.model.client.ledger.LedgerRequestParams)) method to get the latest validated ledger index.
|
- **Java:** Use the [`XrplClient.submit(SignedTransaction)` method](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#submit(org.xrpl.xrpl4j.crypto.signing.SignedTransaction)) to submit a transaction to the network. Use the [`XrplClient.ledger()`](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#ledger(org.xrpl.xrpl4j.model.client.ledger.LedgerRequestParams)) method to get the latest validated ledger index.
|
||||||
|
|
||||||
<!-- MULTICODE_BLOCK_START -->
|
<!-- MULTICODE_BLOCK_START -->
|
||||||
@@ -348,15 +348,15 @@ Generating an address and secret doesn't get you XRP directly; you're only choos
|
|||||||
|
|
||||||
### Connecting to the Production XRP Ledger
|
### Connecting to the Production XRP Ledger
|
||||||
|
|
||||||
When you instantiate the `RippleAPI` object, you must specify a server that's synced with the appropriate XRP Ledger. For many cases, you can use Ripple's public servers, such as in the following snippet:
|
When you instantiate the `RippleAPI` object, you must specify a server that's synced with the appropriate XRP Ledger. For many cases, you can use [public servers](public-servers.html), such as in the following snippet:
|
||||||
|
|
||||||
<!-- MULTICODE_BLOCK_START -->
|
<!-- MULTICODE_BLOCK_START -->
|
||||||
|
|
||||||
_JavaScript_
|
_JavaScript_
|
||||||
|
|
||||||
```js
|
```js
|
||||||
ripple = require('ripple-lib')
|
const xrpl = require('xrpl')
|
||||||
api = new ripple.RippleAPI({server: 'wss://xrplcluster.com'})
|
const api = new xrpl.Client('wss://xrplcluster.com')
|
||||||
api.connect()
|
api.connect()
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -364,8 +364,7 @@ _Python_
|
|||||||
|
|
||||||
```py
|
```py
|
||||||
from xrpl.clients import JsonRpcClient
|
from xrpl.clients import JsonRpcClient
|
||||||
mainnet_url = "https://xrplcluster.com"
|
client = JsonRpcClient("https://xrplcluster.com")
|
||||||
client = JsonRpcClient(mainnet_url)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
_Java_
|
_Java_
|
||||||
@@ -384,8 +383,8 @@ If you [install `rippled`](install-rippled.html) yourself, it connects to the pr
|
|||||||
_JavaScript_
|
_JavaScript_
|
||||||
|
|
||||||
```js
|
```js
|
||||||
ripple = require('ripple-lib')
|
const xrpl = require('xrpl')
|
||||||
api = new ripple.RippleAPI({server: 'ws://localhost:6006'})
|
const api = new xrpl.Client('ws://localhost:6006')
|
||||||
api.connect()
|
api.connect()
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -393,8 +392,7 @@ _Python_
|
|||||||
|
|
||||||
```py
|
```py
|
||||||
from xrpl.clients import JsonRpcClient
|
from xrpl.clients import JsonRpcClient
|
||||||
mainnet_url = "http://localhost:5005"
|
client = JsonRpcClient("http://localhost:5005")
|
||||||
client = JsonRpcClient(mainnet_url)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
_Java_
|
_Java_
|
||||||
@@ -413,7 +411,7 @@ XrplClient xrplClient = new XrplClient(rippledUrl);
|
|||||||
After completing this tutorial, you may want to try the following:
|
After completing this tutorial, you may want to try the following:
|
||||||
|
|
||||||
- Build [Reliable transaction submission](reliable-transaction-submission.html) for production systems.
|
- Build [Reliable transaction submission](reliable-transaction-submission.html) for production systems.
|
||||||
- Consult [RippleAPI JavaScript Reference](rippleapi-reference.html), [`xrpl-py` Python Reference](https://xrpl-py.readthedocs.io/), or [xrpl4j Javadocs](https://javadoc.io/doc/org.xrpl/) for the full range of XRP Ledger functionality. <!-- SPELLING_IGNORE: javadocs -->
|
- Consult the your [client library](client-libraries.html)'s API reference for the full range of XRP Ledger functionality. <!-- SPELLING_IGNORE: javadocs -->
|
||||||
- Customize your [Account Settings](manage-account-settings.html).
|
- Customize your [Account Settings](manage-account-settings.html).
|
||||||
- Learn how [Transaction Metadata](transaction-metadata.html) describes the outcome of a transaction in detail.
|
- Learn how [Transaction Metadata](transaction-metadata.html) describes the outcome of a transaction in detail.
|
||||||
- Explore more [Payment Types](payment-types.html) such as Escrows and Payment Channels.
|
- Explore more [Payment Types](payment-types.html) such as Escrows and Payment Channels.
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ The offline machine needs secure persistent storage (for example, an encrypted d
|
|||||||
Software options for signing on the XRP Ledger include:
|
Software options for signing on the XRP Ledger include:
|
||||||
|
|
||||||
- [Install `rippled`](install-rippled.html) from a package (`.deb` or `.rpm` depending on which Linux distribution you use) file, then [run it in stand-alone mode](rippled-server-modes.html).
|
- [Install `rippled`](install-rippled.html) from a package (`.deb` or `.rpm` depending on which Linux distribution you use) file, then [run it in stand-alone mode](rippled-server-modes.html).
|
||||||
- Install [ripple-lib](rippleapi-reference.html) and its dependencies offline. The Yarn package manager, for example, has [recommended instructions for offline usage](https://yarnpkg.com/blog/2016/11/24/offline-mirror/).
|
- Install [xrpl.js](https://github.com/XRPLF/xrpl.js/) (or another [client library](client-libraries.html)) and its dependencies offline. The Yarn package manager, for example, has [recommended instructions for offline usage](https://yarnpkg.com/blog/2016/11/24/offline-mirror/).
|
||||||
- See also: [Set Up Secure Signing](set-up-secure-signing.html)
|
- See also: [Set Up Secure Signing](set-up-secure-signing.html)
|
||||||
|
|
||||||
You may want to set up custom software to help construct transaction instructions on the offline machine. For example, your software may track what [sequence number][] to use next, or contain preset templates for certain types of transactions you expect to send.
|
You may want to set up custom software to help construct transaction instructions on the offline machine. For example, your software may track what [sequence number][] to use next, or contain preset templates for certain types of transactions you expect to send.
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ blurb: Require users to specify a destination tag when sending to your address.
|
|||||||
embed_ripple_lib: true
|
embed_ripple_lib: true
|
||||||
filters:
|
filters:
|
||||||
- interactive_steps
|
- interactive_steps
|
||||||
|
- include_code
|
||||||
labels:
|
labels:
|
||||||
- Accounts
|
- Accounts
|
||||||
---
|
---
|
||||||
@@ -21,7 +22,7 @@ This tutorial demonstrates how to enable the Require Destination Tag flag on you
|
|||||||
- You need a funded XRP Ledger account, with an address, secret key, and some XRP. For production, you can use the same address and secret consistently. For this tutorial, you can generate new test credentials as needed.
|
- You need a funded XRP Ledger account, with an address, secret key, and some XRP. For production, you can use the same address and secret consistently. For this tutorial, you can generate new test credentials as needed.
|
||||||
- You need a connection to the XRP Ledger network.
|
- You need a connection to the XRP Ledger network.
|
||||||
|
|
||||||
This page provides examples that use [ripple-lib for JavaScript](get-started-with-rippleapi-for-javascript.html). Since JavaScript works in the web browser, you can read along and use the interactive steps without any setup.
|
This page provides examples that use [xrpl.js](get-started-using-javascript.html) in the web browser, so you can read along and use the interactive steps without any setup.
|
||||||
|
|
||||||
<!-- Source for this specific tutorial's interactive bits: -->
|
<!-- Source for this specific tutorial's interactive bits: -->
|
||||||
<script type="application/javascript" src="assets/js/tutorials/require-destination-tags.js"></script>
|
<script type="application/javascript" src="assets/js/tutorials/require-destination-tags.js"></script>
|
||||||
@@ -40,24 +41,9 @@ When you're [building actual production-ready software](production-readiness.htm
|
|||||||
|
|
||||||
### {{n.next()}}. Connect to the Network
|
### {{n.next()}}. Connect to the Network
|
||||||
|
|
||||||
You must be connected to the network to submit transactions to it.
|
You must be connected to the network to submit transactions to it. The following code shows how to connect to a public XRP Ledger Testnet server a supported [client library](client-libraries.html):
|
||||||
|
|
||||||
The following code uses a [ripple-lib for JavaScript](rippleapi-reference.html) instance to connect to a public XRP Ledger Testnet server:
|
{{ include_code("_code-samples/get-started/js/base.js", language="js") }}
|
||||||
|
|
||||||
```js
|
|
||||||
ripple = require('ripple-lib') // Node.js only. Use a <script> tag in browsers.
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
api = new ripple.RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
|
|
||||||
await api.connect()
|
|
||||||
|
|
||||||
// Code in the following examples continues here...
|
|
||||||
}
|
|
||||||
|
|
||||||
main()
|
|
||||||
```
|
|
||||||
|
|
||||||
**Note:** The code samples in this tutorial use JavaScript's [`async`/`await` pattern](https://javascript.info/async-await). Since `await` needs to be used from within an `async` function, the remaining code samples are written to continue inside the `main()` function started here. You can also use Promise methods `.then()` and `.catch()` instead of `async`/`await` if you prefer.
|
|
||||||
|
|
||||||
For this tutorial, you can connect directly from your browser by pressing the following button:
|
For this tutorial, you can connect directly from your browser by pressing the following button:
|
||||||
|
|
||||||
@@ -69,27 +55,13 @@ To enable the `RequireDest` flag, set the [`asfRequireDest` value (`1`)](account
|
|||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```js
|
<!-- MULTICODE_BLOCK_START -->
|
||||||
const prepared = await api.prepareTransaction({
|
|
||||||
"TransactionType": "AccountSet",
|
|
||||||
"Account": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
|
||||||
"SetFlag": 1 // RequireDest
|
|
||||||
})
|
|
||||||
console.log("Prepared transaction:", prepared.txJSON)
|
|
||||||
const max_ledger = prepared.instructions.maxLedgerVersion
|
|
||||||
|
|
||||||
const signed = api.sign(prepared.txJSON, "s████████████████████████████")
|
_JavaScript_
|
||||||
console.log("Transaction hash:", signed.id)
|
|
||||||
const tx_id = signed.id
|
|
||||||
const tx_blob = signed.signedTransaction
|
|
||||||
|
|
||||||
const prelim_result = await api.request("submit", {"tx_blob": tx_blob})
|
{{ include_code("_code-samples/require-destination-tags/require-destination-tags.js", language="js", start_with="// Send AccountSet", end_before="// Confirm Account") }}
|
||||||
console.log("Preliminary result:", prelim_result)
|
|
||||||
const min_ledger = prelim_result.validated_ledger_index
|
|
||||||
|
|
||||||
// min_ledger, max_ledger, and tx_id are useful for looking up the transaction's
|
<!-- MULTICODE_BLOCK_END -->
|
||||||
// status later.
|
|
||||||
```
|
|
||||||
|
|
||||||
{{ start_step("Send AccountSet") }}
|
{{ start_step("Send AccountSet") }}
|
||||||
<button id="send-accountset" class="btn btn-primary previous-steps-required" data-wait-step-name="Wait">Send AccountSet</button>
|
<button id="send-accountset" class="btn btn-primary previous-steps-required" data-wait-step-name="Wait">Send AccountSet</button>
|
||||||
@@ -111,15 +83,15 @@ Most transactions are accepted into the next ledger version after they're submit
|
|||||||
|
|
||||||
After the transaction is validated, you can check your account's settings to confirm that the Require Destination Tag flag is enabled.
|
After the transaction is validated, you can check your account's settings to confirm that the Require Destination Tag flag is enabled.
|
||||||
|
|
||||||
```js
|
|
||||||
let account_info = await api.request("account_info", {
|
<!-- MULTICODE_BLOCK_START -->
|
||||||
"account": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
|
||||||
"ledger_index": "validated"
|
_JavaScript_
|
||||||
})
|
|
||||||
const flags = api.parseAccountFlags(account_info.account_data.Flags)
|
{{ include_code("_code-samples/require-destination-tags/require-destination-tags.js", language="js", start_with="// Confirm Account", end_before="// End main()") }}
|
||||||
console.log(JSON.stringify(flags, null, 2))
|
|
||||||
// Look for "requireDestinationTag": true
|
<!-- MULTICODE_BLOCK_END -->
|
||||||
```
|
|
||||||
|
|
||||||
{{ start_step("Confirm Settings") }}
|
{{ start_step("Confirm Settings") }}
|
||||||
<button id="confirm-settings" class="btn btn-primary previous-steps-required" data-wait-step-name="Wait">Confirm Settings</button>
|
<button id="confirm-settings" class="btn btn-primary previous-steps-required" data-wait-step-name="Wait">Confirm Settings</button>
|
||||||
|
|||||||
@@ -65,9 +65,7 @@ When you're [building actual production-ready software](production-readiness.htm
|
|||||||
|
|
||||||
### {{n.next()}}. Connect to the Network
|
### {{n.next()}}. Connect to the Network
|
||||||
|
|
||||||
You must be connected to the network to submit transactions to it.
|
You must be connected to the network to submit transactions to it. The following code shows how to connect to a public XRP Ledger Testnet server a supported [client library](client-libraries.html):
|
||||||
|
|
||||||
The following code shows how to connect to a public XRP Ledger Testnet server a supported [client library](client-libraries.html):
|
|
||||||
|
|
||||||
<!-- MULTICODE_BLOCK_START -->
|
<!-- MULTICODE_BLOCK_START -->
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ default_keys: &defaults
|
|||||||
hover_anchors: <i class="fa fa-link"></i>
|
hover_anchors: <i class="fa fa-link"></i>
|
||||||
light_theme_enabled: true
|
light_theme_enabled: true
|
||||||
# Script tags used in a variety of tools & examples.
|
# Script tags used in a variety of tools & examples.
|
||||||
ripple_lib_tag: '<script type="application/javascript" src="assets/js/xrpl-2.0.0b2.min.js"></script>'
|
ripple_lib_tag: '<script type="application/javascript" src="assets/js/xrpl-2.0.0b5.min.js"></script>'
|
||||||
|
|
||||||
targets:
|
targets:
|
||||||
# First member is the default that gets built when target not specified
|
# First member is the default that gets built when target not specified
|
||||||
@@ -343,7 +343,7 @@ pages:
|
|||||||
top_nav_shortcuts:
|
top_nav_shortcuts:
|
||||||
# Programming Languages
|
# Programming Languages
|
||||||
- get-started-using-python.html
|
- get-started-using-python.html
|
||||||
- get-started-using-node-js.html
|
- get-started-using-javascript.html
|
||||||
- get-started-using-java.html
|
- get-started-using-java.html
|
||||||
- get-started-using-http-websocket-apis.html
|
- get-started-using-http-websocket-apis.html
|
||||||
# Popular pages
|
# Popular pages
|
||||||
@@ -378,7 +378,7 @@ pages:
|
|||||||
top_nav_shortcuts:
|
top_nav_shortcuts:
|
||||||
# Programming Languages
|
# Programming Languages
|
||||||
- get-started-using-python.html
|
- get-started-using-python.html
|
||||||
- get-started-using-node-js.html
|
- get-started-using-javascript.html
|
||||||
- get-started-using-java.html
|
- get-started-using-java.html
|
||||||
- get-started-using-http-websocket-apis.html
|
- get-started-using-http-websocket-apis.html
|
||||||
# Popular pages
|
# Popular pages
|
||||||
@@ -1018,19 +1018,28 @@ pages:
|
|||||||
- en
|
- en
|
||||||
- ja
|
- ja
|
||||||
|
|
||||||
- md: tutorials/get-started/get-started-using-node-js.md
|
- md: tutorials/get-started/get-started-using-javascript.md
|
||||||
targets:
|
targets:
|
||||||
- en
|
- en
|
||||||
|
|
||||||
- md: tutorials/get-started/get-started-using-node-js.ja.md
|
- md: tutorials/get-started/get-started-using-javascript.ja.md
|
||||||
targets:
|
targets:
|
||||||
- ja
|
- ja
|
||||||
|
|
||||||
# Redirect for old JS Client Library URL
|
# Redirect for old JS Client Library URLs
|
||||||
- name: Get Started Using Node.js
|
- name: Get Started Using JavaScript
|
||||||
|
html: get-started-using-node-js.html
|
||||||
|
template: pagetype-redirect.html.jinja
|
||||||
|
redirect_url: get-started-using-javascript.html
|
||||||
|
nav_omit: true
|
||||||
|
targets:
|
||||||
|
- en
|
||||||
|
- ja
|
||||||
|
|
||||||
|
- name: Get Started Using JavaScript
|
||||||
html: get-started-with-rippleapi-for-javascript.html
|
html: get-started-with-rippleapi-for-javascript.html
|
||||||
template: pagetype-redirect.html.jinja
|
template: pagetype-redirect.html.jinja
|
||||||
redirect_url: get-started-using-node-js.html
|
redirect_url: get-started-using-javascript.html
|
||||||
nav_omit: true
|
nav_omit: true
|
||||||
targets:
|
targets:
|
||||||
- en
|
- en
|
||||||
|
|||||||
Reference in New Issue
Block a user