mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-24 05:35:51 +00:00
Migrate content syntax via script
The changes in this commit were auto-generated by running tool/migrate.sh Following this commit, the Dactyl build no longer works but the Redocly build (mostly) should.
This commit is contained in:
@@ -11,30 +11,30 @@ showcase_icon: assets/img/logos/globe.svg
|
||||
---
|
||||
# Get Started Using HTTP / WebSocket APIs
|
||||
|
||||
If you don't have or don't want to use a [client library](client-libraries.html) in your preferred programming language, you can access the XRP Ledger directly through the APIs of its core server software, [`rippled`](xrpl-servers.html). The server provides APIs over JSON-RPC and WebSocket protocols. If you don't [run your own instance of `rippled`](install-rippled.html) you can still use a [public server][public servers].
|
||||
If you don't have or don't want to use a [client library](../../references/client-libraries.md) in your preferred programming language, you can access the XRP Ledger directly through the APIs of its core server software, [`rippled`](../../concepts/networks-and-servers/index.md). The server provides APIs over JSON-RPC and WebSocket protocols. If you don't [run your own instance of `rippled`](../../infrastructure/installation/index.md) you can still use a [public server][public servers].
|
||||
|
||||
**Tip:** You can dive right into the API with the [**WebSocket API Tool**](websocket-api-tool.html), or use the [XRP Ledger Explorer](https://livenet.xrpl.org/) to watch the progress of the ledger live.
|
||||
**Tip:** You can dive right into the API with the [**WebSocket API Tool**](/resources/dev-tools/websocket-api-tool), or use the [XRP Ledger Explorer](https://livenet.xrpl.org/) to watch the progress of the ledger live.
|
||||
|
||||
## Differences Between JSON-RPC and WebSocket
|
||||
|
||||
Both JSON-RPC and WebSocket are HTTP-based protocols, and for the most part the data provided over both protocols is the same. The major differences are as follows:
|
||||
|
||||
- JSON-RPC uses individual HTTP requests and responses for each call, similar to a RESTful API. You can use any common HTTP client such as [curl](https://curl.se/), [Postman](https://www.postman.com/downloads/), or [Requests](https://requests.readthedocs.io/) to access this API.
|
||||
- WebSocket uses a persistent connection that allows the server to push data to the client. Functions that require push messages, like [event subscriptions](subscribe.html), are only available using WebSocket.
|
||||
- WebSocket uses a persistent connection that allows the server to push data to the client. Functions that require push messages, like [event subscriptions](../../references/http-websocket-apis/public-api-methods/subscription-methods/subscribe.md), are only available using WebSocket.
|
||||
|
||||
Both APIs can be served unencrypted (`http://` and `ws://`) or encrypted using TLS (`https://` and `wss://`). Unencrypted connections should not be served over open networks, but can be used when the client is on the same machine as the server.
|
||||
|
||||
|
||||
## Admin Access
|
||||
|
||||
The API methods are divided into [Public Methods](public-api-methods.html) and [Admin Methods](admin-api-methods.html) so that organizations can offer public servers for the benefit of the community. To access admin methods, or admin functionality of public methods, you must connect to the API on a **port and IP address marked as admin** in the server's config file.
|
||||
The API methods are divided into [Public Methods](../../references/http-websocket-apis/public-api-methods/index.md) and [Admin Methods](../../references/http-websocket-apis/admin-api-methods/index.md) so that organizations can offer public servers for the benefit of the community. To access admin methods, or admin functionality of public methods, you must connect to the API on a **port and IP address marked as admin** in the server's config file.
|
||||
|
||||
The [example config file](https://github.com/XRPLF/rippled/blob/f00f263852c472938bf8e993e26c7f96f435935c/cfg/rippled-example.cfg#L1154-L1179) listens for connections on the local loopback network (127.0.0.1), with JSON-RPC (HTTP) on port 5005 and WebSocket (WS) on port 6006, and treats all connected clients as admin.
|
||||
|
||||
|
||||
## WebSocket API
|
||||
|
||||
If you are looking to try out some methods on the XRP Ledger, you can skip writing your own WebSocket code and go straight to using the API at the [WebSocket API Tool](websocket-api-tool.html). Later on, when you want to connect to your own `rippled` server, you can [build your own client](monitor-incoming-payments-with-websocket.html) or use a [client library](client-libraries.html) with WebSocket support.
|
||||
If you are looking to try out some methods on the XRP Ledger, you can skip writing your own WebSocket code and go straight to using the API at the [WebSocket API Tool](/resources/dev-tools/websocket-api-tool). Later on, when you want to connect to your own `rippled` server, you can [build your own client](monitor-incoming-payments-with-websocket.md) or use a [client library](../../references/client-libraries.md) with WebSocket support.
|
||||
|
||||
Example WebSocket API request:
|
||||
|
||||
@@ -48,7 +48,7 @@ Example WebSocket API request:
|
||||
|
||||
The response shows you the current status of the server.
|
||||
|
||||
Read more: [Request Formatting >](request-formatting.html) [Response Formatting >](response-formatting.html) [About the server_info method >][server_info method]
|
||||
Read more: [Request Formatting >](../../references/http-websocket-apis/api-conventions/request-formatting.md) [Response Formatting >](../../references/http-websocket-apis/api-conventions/response-formatting.md) [About the server_info method >][server_info method]
|
||||
|
||||
## JSON-RPC
|
||||
|
||||
@@ -72,7 +72,7 @@ Content-Type: application/json
|
||||
|
||||
The response shows you the current status of the server.
|
||||
|
||||
Read more: [Request Formatting >](request-formatting.html#json-rpc-format) [Response Formatting >](response-formatting.html) [About the server_info method >][server_info method]
|
||||
Read more: [Request Formatting >](../../references/http-websocket-apis/api-conventions/request-formatting.md#json-rpc-format) [Response Formatting >](../../references/http-websocket-apis/api-conventions/response-formatting.md) [About the server_info method >][server_info method]
|
||||
|
||||
## Commandline
|
||||
|
||||
@@ -84,7 +84,7 @@ Example commandline request:
|
||||
rippled --conf=/etc/opt/ripple/rippled.cfg server_info
|
||||
```
|
||||
|
||||
Read more: [Commandline Usage Reference >](commandline-usage.html)
|
||||
Read more: [Commandline Usage Reference >](../../infrastructure/commandline-usage.md)
|
||||
|
||||
**Caution:** The commandline interface is intended for administrative purposes only and is _not a supported API_. New versions of `rippled` may introduce breaking changes to the commandline API without warning!
|
||||
|
||||
@@ -92,24 +92,21 @@ Read more: [Commandline Usage Reference >](commandline-usage.html)
|
||||
|
||||
For a full list of API methods, see:
|
||||
|
||||
- [Public `rippled` Methods](public-api-methods.html): Methods available on public servers, including looking up data from the ledger and submitting transactions.
|
||||
- [Admin `rippled` Methods](admin-api-methods.html): Methods for [managing](manage-the-rippled-server.html) the `rippled` server.
|
||||
- [Public `rippled` Methods](../../references/http-websocket-apis/public-api-methods/index.md): Methods available on public servers, including looking up data from the ledger and submitting transactions.
|
||||
- [Admin `rippled` Methods](../../references/http-websocket-apis/admin-api-methods/index.md): Methods for [managing](../../infrastructure/installation/install-rippled-on-ubuntu.md) the `rippled` server.
|
||||
|
||||
|
||||
## See Also
|
||||
|
||||
- **Concepts:**
|
||||
- [XRP Ledger Overview](xrp-ledger-overview.html)
|
||||
- [Client Libraries](client-libraries.html)
|
||||
- [Parallel Networks](parallel-networks.html)
|
||||
- [XRP Ledger Overview](/about/)
|
||||
- [Client Libraries](../../references/client-libraries.md)
|
||||
- [Parallel Networks](../../concepts/networks-and-servers/parallel-networks.md)
|
||||
- **Tutorials:**
|
||||
- [Get Started Using JavaScript](get-started-using-javascript.html)
|
||||
- [Reliable Transaction Submission](reliable-transaction-submission.html)
|
||||
- [Manage the rippled Server](manage-the-rippled-server.html)
|
||||
- [Get Started Using JavaScript](get-started-using-javascript.md)
|
||||
- [Reliable Transaction Submission](../../concepts/transactions/reliable-transaction-submission.md)
|
||||
- [Manage the rippled Server](../../infrastructure/installation/install-rippled-on-ubuntu.md)
|
||||
- **References:**
|
||||
- [rippled API Reference](http-websocket-apis.html)
|
||||
- [rippled API Reference](../../references/http-websocket-apis/index.md)
|
||||
|
||||
<!--{# common link defs #}-->
|
||||
{% include '_snippets/rippled-api-links.md' %}
|
||||
{% include '_snippets/tx-type-links.md' %}
|
||||
{% include '_snippets/rippled_versions.md' %}
|
||||
{% raw-partial file="/_snippets/common-links.md" /%}
|
||||
|
||||
@@ -24,7 +24,7 @@ In this tutorial, you'll learn:
|
||||
|
||||
* The basic building blocks of XRP Ledger-based applications.
|
||||
* How to connect to the XRP Ledger using `xrpl4j`.
|
||||
* How to get an account on the [Testnet](xrp-testnet-faucet.html) using `xrpl4j`.
|
||||
* How to get an account on the [Testnet](/resources/dev-tools/xrp-faucets) using `xrpl4j`.
|
||||
* How to use the `xrpl4j` library to look up information about an account on the XRP Ledger.
|
||||
* How to put these steps together to create a Java app.
|
||||
|
||||
@@ -76,7 +76,7 @@ Check out the [xrpl4j sample project](https://github.com/XRPLF/xrpl4j-sample) fo
|
||||
|
||||
## Start Building
|
||||
|
||||
When you're working with the XRP Ledger, there are a few things you'll need to manage, whether you're adding XRP to your [account](accounts.html), integrating with the [decentralized exchange](decentralized-exchange.html), or [issuing tokens](tokens.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 to your [account](../../concepts/accounts/accounts.md), integrating with the [decentralized exchange](../../concepts/tokens/decentralized-exchange/index.md), or [issuing tokens](../../concepts/tokens/index.md). 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:
|
||||
|
||||
@@ -90,31 +90,35 @@ Here are the basic steps you'll need to cover for almost any XRP Ledger project:
|
||||
To make queries and submit transactions, you need to connect to the XRP Ledger. To do this with `xrpl4j`,
|
||||
you can use an [`XrplClient`](https://javadoc.io/doc/org.xrpl/xrpl4j-client/3.0.1/org/xrpl/xrpl4j/client/XrplClient.html):
|
||||
|
||||
{{ include_code("_code-samples/get-started/java/GetAccountInfo.java", start_with="// Construct a network client", end_before="// Create a random KeyPair", language="java") }}
|
||||
{% code-snippet file="/_code-samples/get-started/java/GetAccountInfo.java" from="// Construct a network client" before="// Create a random KeyPair" language="java" /%}
|
||||
|
||||
#### 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](../../concepts/networks-and-servers/parallel-networks.md). 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:
|
||||
|
||||
* By [installing the core server](install-rippled.html) (`rippled`) and running a node yourself. The core server connects to the Mainnet by default, but you can [change the configuration to use Testnet or Devnet](connect-your-rippled-to-the-xrp-test-net.html). [There are good reasons to run your own core server](networks-and-servers.html#reasons-to-run-your-own-server). If you run your own server, you can connect to it like so:
|
||||
* By [installing the core server](../../infrastructure/installation/index.md) (`rippled`) and running a node yourself. The core server connects to the Mainnet by default, but you can [change the configuration to use Testnet or Devnet](../../infrastructure/configuration/connect-your-rippled-to-the-xrp-test-net.md). [There are good reasons to run your own core server](../../concepts/networks-and-servers/index.md#reasons-to-run-your-own-server). If you run your own server, you can connect to it like so:
|
||||
|
||||
final HttpUrl rippledUrl = HttpUrl.get("http://localhost:5005/");
|
||||
XrplClient xrplClient = new XrplClient(rippledUrl);
|
||||
```
|
||||
final HttpUrl rippledUrl = HttpUrl.get("http://localhost:5005/");
|
||||
XrplClient xrplClient = new XrplClient(rippledUrl);
|
||||
```
|
||||
|
||||
See the example [core server config file](https://github.com/XRPLF/rippled/blob/c0a0b79d2d483b318ce1d82e526bd53df83a4a2c/cfg/rippled-example.cfg#L1562) for more information about default values.
|
||||
|
||||
* By using one of the available [public servers][]:
|
||||
|
||||
final HttpUrl rippledUrl = HttpUrl.get("https://s2.ripple.com:51234/");
|
||||
XrplClient xrplClient = new XrplClient(rippledUrl);
|
||||
```
|
||||
final HttpUrl rippledUrl = HttpUrl.get("https://s2.ripple.com:51234/");
|
||||
XrplClient xrplClient = new XrplClient(rippledUrl);
|
||||
```
|
||||
|
||||
### 2. Get account
|
||||
|
||||
To store value and execute transactions on the XRP Ledger, you need to get an account: a [set of keys](cryptographic-keys.html#key-components) and an [address](addresses.html) that's been [funded with enough XRP](accounts.html#creating-accounts) to meet the [account reserve](reserves.html). The address is the identifier of your account and you use the [private key](cryptographic-keys.html#private-key) to sign transactions that you submit to the XRP Ledger. For production purposes, you should take care to store your keys and set up a [secure signing method](secure-signing.html).
|
||||
To store value and execute transactions on the XRP Ledger, you need to get an account: a [set of keys](../../concepts/accounts/cryptographic-keys.md#key-components) and an [address](../../concepts/accounts/addresses.md) that's been [funded with enough XRP](../../concepts/accounts/accounts.md#creating-accounts) to meet the [account reserve](../../concepts/accounts/reserves.md). The address is the identifier of your account and you use the [private key](../../concepts/accounts/cryptographic-keys.md#private-key) to sign transactions that you submit to the XRP Ledger. For production purposes, you should take care to store your keys and set up a [secure signing method](../../concepts/transactions/secure-signing.md).
|
||||
|
||||
To generate a new account, `xrpl4j` provides the [`DefaultWalletFactory`](https://javadoc.io/doc/org.xrpl/xrpl4j-keypairs/latest/org/xrpl/xrpl4j/wallet/DefaultWalletFactory.html).
|
||||
|
||||
{{ include_code("_code-samples/get-started/java/GetAccountInfo.java", start_with="// Create a random KeyPair", end_before="// Derive the Classic and X-Addresses from testWallet", language="java") }}
|
||||
{% code-snippet file="/_code-samples/get-started/java/GetAccountInfo.java" from="// Create a random KeyPair" before="// Derive the Classic and X-Addresses from testWallet" language="java" /%}
|
||||
|
||||
|
||||
The result of a call to `walletFactory.randomWallet(true).wallet()` is a [`Wallet` instance](https://javadoc.io/doc/org.xrpl/xrpl4j-keypairs/latest/org/xrpl/xrpl4j/wallet/Wallet.html):
|
||||
@@ -132,17 +136,17 @@ Wallet {
|
||||
}
|
||||
```
|
||||
|
||||
For testing and development purposes, you can use a `FaucetClient` connected to the XRP Ledger [Testnet](parallel-networks.html):
|
||||
For testing and development purposes, you can use a `FaucetClient` connected to the XRP Ledger [Testnet](../../concepts/networks-and-servers/parallel-networks.md):
|
||||
|
||||
{{ include_code("_code-samples/get-started/java/GetAccountInfo.java", start_with="// Fund the account using the testnet Faucet", end_before="// Look up your Account Info", language="java") }}
|
||||
{% code-snippet file="/_code-samples/get-started/java/GetAccountInfo.java" from="// Fund the account using the testnet Faucet" before="// Look up your Account Info" language="java" /%}
|
||||
|
||||
### 3. Query the XRP Ledger
|
||||
|
||||
You can query the XRP Ledger to get information about [a specific account](account-methods.html), [a specific transaction](tx.html), the state of a [current or a historical ledger](ledger-methods.html), and [the XRP Ledger's decentralized exchange](path-and-order-book-methods.html). You need to make these queries, among other reasons, to look up account info to follow best practices for [reliable transaction submission](reliable-transaction-submission.html).
|
||||
You can query the XRP Ledger to get information about [a specific account](../../references/http-websocket-apis/public-api-methods/account-methods/index.md), [a specific transaction](../../references/http-websocket-apis/public-api-methods/transaction-methods/tx.md), the state of a [current or a historical ledger](../../references/http-websocket-apis/public-api-methods/ledger-methods/index.md), and [the XRP Ledger's decentralized exchange](../../references/http-websocket-apis/public-api-methods/path-and-order-book-methods/index.md). You need to make these queries, among other reasons, to look up account info to follow best practices for [reliable transaction submission](../../concepts/transactions/reliable-transaction-submission.md).
|
||||
|
||||
Here, we'll use the [`XrplClient` we constructed](#1-connect-to-the-xrp-ledger) to look up information about the [account we got](#2-get-account) in the previous step.
|
||||
|
||||
{{ include_code("_code-samples/get-started/java/GetAccountInfo.java", start_with="// Look up your Account Info", end_before="// Print the result", language="java") }}
|
||||
{% code-snippet file="/_code-samples/get-started/java/GetAccountInfo.java" from="// Look up your Account Info" before="// Print the result" language="java" /%}
|
||||
|
||||
|
||||
### 4. Putting it all together
|
||||
@@ -154,9 +158,7 @@ Using these building blocks, we can create a Java app that:
|
||||
3. Looks up and prints information about the account you created.
|
||||
|
||||
|
||||
```java
|
||||
{% include '_code-samples/get-started/java/GetAccountInfo.java' %}
|
||||
```
|
||||
{% code-snippet file="/_code-samples/get-started/java/GetAccountInfo.java" language="java" /%}
|
||||
|
||||
To run the app, you can download the code from [Github](https://github.com/XRPLF/xrpl4j-sample) and run `GetAccountInfo` either
|
||||
from your IDE or from the command line.
|
||||
@@ -208,22 +210,18 @@ The response fields contained in `AccountInfoResult` that you want to inspect in
|
||||
|
||||
* `accountData.sequence` — This is the sequence number of the next valid transaction for the account. You need to specify the sequence number when you prepare transactions.
|
||||
|
||||
* `accountData.balance` — This is the account's balance of XRP, in drops. You can use this to confirm that you have enough XRP to send (if you're making a payment) and to meet the [current transaction cost](transaction-cost.html#current-transaction-cost) for a given transaction.
|
||||
* `accountData.balance` — This is the account's balance of XRP, in drops. You can use this to confirm that you have enough XRP to send (if you're making a payment) and to meet the [current transaction cost](../../concepts/transactions/transaction-cost.md#current-transaction-cost) for a given transaction.
|
||||
|
||||
* `validated` — Indicates whether the returned data is from a [validated ledger](open-closed-validated-ledgers.html). When inspecting transactions, it's important to confirm that [the results are final](finality-of-results.html) before further processing the transaction. If `validated` is `true` then you know for sure the results won't change. For more information about best practices for transaction processing, see [Reliable Transaction Submission](reliable-transaction-submission.html).
|
||||
* `validated` — Indicates whether the returned data is from a [validated ledger](../../concepts/ledgers/open-closed-validated-ledgers.md). When inspecting transactions, it's important to confirm that [the results are final](../../concepts/transactions/finality-of-results/index.md) before further processing the transaction. If `validated` is `true` then you know for sure the results won't change. For more information about best practices for transaction processing, see [Reliable Transaction Submission](../../concepts/transactions/reliable-transaction-submission.md).
|
||||
|
||||
For a detailed description of every response field, see [account_info](account_info.html#response-format).
|
||||
For a detailed description of every response field, see [account_info](../../references/http-websocket-apis/public-api-methods/account-methods/account_info.md#response-format).
|
||||
|
||||
|
||||
## Keep on building
|
||||
|
||||
Now that you know how to use `xrpl4j` to connect to the XRP Ledger, get an account, and look up information about it, you can also use `xrpl4j` to:
|
||||
|
||||
* [Send XRP](send-xrp.html).
|
||||
* [Set up secure signing](secure-signing.html) for your account.
|
||||
* [Send XRP](send-xrp.md).
|
||||
* [Set up secure signing](../../concepts/transactions/secure-signing.md) for your account.
|
||||
|
||||
|
||||
<!--{# common link defs #}-->
|
||||
{% include '_snippets/rippled-api-links.md' %}
|
||||
{% include '_snippets/tx-type-links.md' %}
|
||||
{% include '_snippets/rippled_versions.md' %}
|
||||
{% raw-partial file="/_snippets/common-links.md" /%}
|
||||
|
||||
@@ -12,7 +12,7 @@ showcase_icon: assets/img/logos/javascript.svg
|
||||
|
||||
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]({{target.github_forkurl}}/tree/{{target.github_branch}}/content/_code-samples/get-started/js/).
|
||||
The scripts and config files used in this guide are {% repo-link path="content/_code-samples/get-started/js/" %}available in this website's GitHub Repository{% /repo-link %}.
|
||||
|
||||
|
||||
## Learning Goals
|
||||
@@ -21,7 +21,7 @@ In this tutorial, you'll learn:
|
||||
|
||||
* The basic building blocks of XRP Ledger-based applications.
|
||||
* How to connect to the XRP Ledger using `xrpl.js`.
|
||||
* How to get an account on the [Testnet](xrp-testnet-faucet.html) using `xrpl.js`.
|
||||
* How to get an account on the [Testnet](/resources/dev-tools/xrp-faucets) using `xrpl.js`.
|
||||
* 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 JavaScript app or web-app.
|
||||
|
||||
@@ -42,7 +42,7 @@ npm install xrpl
|
||||
|
||||
## Start Building
|
||||
|
||||
When you're working with the XRP Ledger, there are a few things you'll need to manage, whether you're adding XRP to your [account](accounts.html), integrating with the [decentralized exchange](decentralized-exchange.html), or [issuing tokens](tokens.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 to your [account](../../concepts/accounts/accounts.md), integrating with the [decentralized exchange](../../concepts/tokens/decentralized-exchange/index.md), or [issuing tokens](../../concepts/tokens/index.md). 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 some steps you use in many XRP Ledger projects:
|
||||
|
||||
@@ -89,32 +89,36 @@ To make queries and submit transactions, you need to connect to the XRP Ledger.
|
||||
|
||||
**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") }}
|
||||
{% code-snippet file="/_code-samples/get-started/js/base.js" language="js" /%}
|
||||
|
||||
#### Connect to the XRP Ledger Mainnet
|
||||
|
||||
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 move to production, you'll need to connect to the XRP Ledger 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](../../concepts/networks-and-servers/parallel-networks.md). When you're ready to move to production, you'll need to connect to the XRP Ledger Mainnet. You can do that in two ways:
|
||||
|
||||
* By [installing the core server](install-rippled.html) (`rippled`) and running a node yourself. The core server connects to the Mainnet by default, but you can [change the configuration to use Testnet or Devnet](connect-your-rippled-to-the-xrp-test-net.html). [There are good reasons to run your own core server](networks-and-servers.html#reasons-to-run-your-own-server). If you run your own server, you can connect to it like so:
|
||||
* By [installing the core server](../../infrastructure/installation/index.md) (`rippled`) and running a node yourself. The core server connects to the Mainnet by default, but you can [change the configuration to use Testnet or Devnet](../../infrastructure/configuration/connect-your-rippled-to-the-xrp-test-net.md). [There are good reasons to run your own core server](../../concepts/networks-and-servers/index.md#reasons-to-run-your-own-server). If you run your own server, you can connect to it like so:
|
||||
|
||||
const MY_SERVER = "ws://localhost:6006/"
|
||||
const client = new xrpl.Client(MY_SERVER)
|
||||
await client.connect()
|
||||
```
|
||||
const MY_SERVER = "ws://localhost:6006/"
|
||||
const client = new xrpl.Client(MY_SERVER)
|
||||
await client.connect()
|
||||
```
|
||||
|
||||
See the example [core server config file](https://github.com/XRPLF/rippled/blob/c0a0b79d2d483b318ce1d82e526bd53df83a4a2c/cfg/rippled-example.cfg#L1562) for more information about default values.
|
||||
|
||||
* By using one of the available [public servers][]:
|
||||
|
||||
const PUBLIC_SERVER = "wss://xrplcluster.com/"
|
||||
const client = new xrpl.Client(PUBLIC_SERVER)
|
||||
await client.connect()
|
||||
```
|
||||
const PUBLIC_SERVER = "wss://xrplcluster.com/"
|
||||
const client = new xrpl.Client(PUBLIC_SERVER)
|
||||
await client.connect()
|
||||
```
|
||||
|
||||
|
||||
### 3. Get Account
|
||||
|
||||
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 account like this:
|
||||
|
||||
{{ include_code("_code-samples/get-started/js/get-acct-info.js", start_with="// Create a wallet", end_before="// Get info", language="js") }}
|
||||
{% code-snippet file="/_code-samples/get-started/js/get-acct-info.js" from="// Create a wallet" before="// Get info" language="js" /%}
|
||||
|
||||
If you only want to generate keys, you can create a new `Wallet` instance like this:
|
||||
|
||||
@@ -130,42 +134,39 @@ const test_wallet = xrpl.Wallet.fromSeed("sn3nxiW7v8KXzPzAqzyHXbSSKNuN9") // Tes
|
||||
|
||||
### 4. Query the XRP Ledger
|
||||
|
||||
Use the Client's `request()` method to access the XRP Ledger's [WebSocket API](request-formatting.html). For example:
|
||||
Use the Client's `request()` method to access the XRP Ledger's [WebSocket API](../../references/http-websocket-apis/api-conventions/request-formatting.md). 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") }}
|
||||
{% code-snippet file="/_code-samples/get-started/js/get-acct-info.js" from="// Get info" before="// Listen to ledger close events" language="js" /%}
|
||||
|
||||
|
||||
### 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](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](../../concepts/consensus-protocol/index.md) produces a new [ledger version](../../concepts/ledgers/index.md). 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") }}
|
||||
{% code-snippet file="/_code-samples/get-started/js/get-acct-info.js" from="// Listen to ledger close events" before="// Disconnect when done" language="js" /%}
|
||||
|
||||
|
||||
## Keep on Building
|
||||
|
||||
Now that you know how to use `xrpl.js` to connect to the XRP Ledger, get an account, and look up information about it, you can also:
|
||||
|
||||
* [Send XRP](send-xrp.html).
|
||||
* [Issue a Fungible Token](issue-a-fungible-token.html)
|
||||
* [Set up secure signing](secure-signing.html) for your account.
|
||||
* [Send XRP](send-xrp.md).
|
||||
* [Issue a Fungible Token](../use-tokens/issue-a-fungible-token.md)
|
||||
* [Set up secure signing](../../concepts/transactions/secure-signing.md) for your account.
|
||||
|
||||
|
||||
## See Also
|
||||
|
||||
- **Concepts:**
|
||||
- [XRP Ledger Overview](xrp-ledger-overview.html)
|
||||
- [Client Libraries](client-libraries.html)
|
||||
- [XRP Ledger Overview](/about/)
|
||||
- [Client Libraries](../../references/client-libraries.md)
|
||||
- **Tutorials:**
|
||||
- [Send XRP](send-xrp.html)
|
||||
- [Send XRP](send-xrp.md)
|
||||
- **References:**
|
||||
- [`xrpl.js` Reference](https://js.xrpl.org/)
|
||||
- [Public API Methods](public-api-methods.html)
|
||||
- [API Conventions](api-conventions.html)
|
||||
- [base58 Encodings](base58-encodings.html)
|
||||
- [Transaction Formats](transaction-formats.html)
|
||||
- [Public API Methods](../../references/http-websocket-apis/public-api-methods/index.md)
|
||||
- [API Conventions](../../references/http-websocket-apis/api-conventions/index.md)
|
||||
- [base58 Encodings](../../references/protocol/data-types/base58-encodings.md)
|
||||
- [Transaction Formats](../../references/protocol/transactions/index.md)
|
||||
|
||||
<!--{# common link defs #}-->
|
||||
{% include '_snippets/rippled-api-links.md' %}
|
||||
{% include '_snippets/tx-type-links.md' %}
|
||||
{% include '_snippets/rippled_versions.md' %}
|
||||
{% raw-partial file="/_snippets/common-links.md" /%}
|
||||
|
||||
@@ -24,7 +24,7 @@ In this tutorial, you'll learn:
|
||||
|
||||
* The basic building blocks of XRP Ledger-based applications.
|
||||
* How to connect to the XRP Ledger using `XRPL_PHP`.
|
||||
* How to get an account on the [Testnet](xrp-testnet-faucet.html) using `XRPL_PHP`.
|
||||
* How to get an account on the [Testnet](/resources/dev-tools/xrp-faucets) using `XRPL_PHP`.
|
||||
* How to use the `XRPL_PHP` library to look up information about an account on the XRP Ledger.
|
||||
* How to put these steps together to create a simple application.
|
||||
|
||||
@@ -44,7 +44,7 @@ composer require hardcastle/xrpl_php
|
||||
|
||||
## Start Building
|
||||
|
||||
When you're working with the XRP Ledger, there are a few things you'll need to manage, whether you're adding XRP to your [account](accounts.html), integrating with the [decentralized exchange](decentralized-exchange.html), or [issuing tokens](tokens.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 to your [account](../../concepts/accounts/accounts.md), integrating with the [decentralized exchange](../../concepts/tokens/decentralized-exchange/index.md), or [issuing tokens](../../concepts/tokens/index.md). 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:
|
||||
|
||||
@@ -74,27 +74,31 @@ Note that PHP has no native support for WebSockets, so the Client does not estab
|
||||
|
||||
#### 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](../../concepts/networks-and-servers/parallel-networks.md). 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:
|
||||
|
||||
* By [installing the core server](install-rippled.html) (`rippled`) and running a node yourself. The core server connects to the Mainnet by default, but you can [change the configuration to use Testnet or Devnet](connect-your-rippled-to-the-xrp-test-net.html). [There are good reasons to run your own core server](networks-and-servers.html#reasons-to-run-your-own-server). If you run your own server, you can connect to it like so:
|
||||
* By [installing the core server](../../infrastructure/installation/index.md) (`rippled`) and running a node yourself. The core server connects to the Mainnet by default, but you can [change the configuration to use Testnet or Devnet](../../infrastructure/configuration/connect-your-rippled-to-the-xrp-test-net.md). [There are good reasons to run your own core server](../../concepts/networks-and-servers/index.md#reasons-to-run-your-own-server). If you run your own server, you can connect to it like so:
|
||||
|
||||
use XRPL_PHP\Client\JsonRpcClient;
|
||||
```
|
||||
use XRPL_PHP\Client\JsonRpcClient;
|
||||
|
||||
const LOCAL_JSON_RPC_URL = "http://localhost:5005/";
|
||||
$client = new JsonRpcClient("LOCAL_JSON_RPC_URL");
|
||||
const LOCAL_JSON_RPC_URL = "http://localhost:5005/";
|
||||
$client = new JsonRpcClient("LOCAL_JSON_RPC_URL");
|
||||
```
|
||||
|
||||
See the example [core server config file](https://github.com/XRPLF/rippled/blob/c0a0b79d2d483b318ce1d82e526bd53df83a4a2c/cfg/rippled-example.cfg#L1562) for more information about default values.
|
||||
|
||||
* By using one of the available [public servers][]:
|
||||
|
||||
use XRPL_PHP\Client\JsonRpcClient;
|
||||
```
|
||||
use XRPL_PHP\Client\JsonRpcClient;
|
||||
|
||||
const MAINNET_JSON_RPC_URL = "https://s2.ripple.com:51234/";
|
||||
$client = new JsonRpcClient("MAINNET_JSON_RPC_URL");
|
||||
const MAINNET_JSON_RPC_URL = "https://s2.ripple.com:51234/";
|
||||
$client = new JsonRpcClient("MAINNET_JSON_RPC_URL");
|
||||
```
|
||||
|
||||
### 2. Get account
|
||||
|
||||
To store value and execute transactions on the XRP Ledger, you need to get an account: a [set of keys](cryptographic-keys.html#key-components) and an [address](addresses.html) that's been [funded with enough XRP](accounts.html#creating-accounts) to meet the [account reserve](reserves.html). The address is the identifier of your account and you use the [private key](cryptographic-keys.html#private-key) to sign transactions that you submit to the XRP Ledger. For production purposes, you should take care to store your keys and set up a [secure signing method](secure-signing.html).
|
||||
To store value and execute transactions on the XRP Ledger, you need to get an account: a [set of keys](../../concepts/accounts/cryptographic-keys.md#key-components) and an [address](../../concepts/accounts/addresses.md) that's been [funded with enough XRP](../../concepts/accounts/accounts.md#creating-accounts) to meet the [account reserve](../../concepts/accounts/reserves.md). The address is the identifier of your account and you use the [private key](../../concepts/accounts/cryptographic-keys.md#private-key) to sign transactions that you submit to the XRP Ledger. For production purposes, you should take care to store your keys and set up a [secure signing method](../../concepts/transactions/secure-signing.md).
|
||||
|
||||
To generate a new account, `PHP_XRPL` provides the static `generate()` method in the `Wallet` class:
|
||||
|
||||
@@ -133,17 +137,17 @@ print_r([
|
||||
|
||||
```
|
||||
|
||||
For testing and development purposes, you can use the `fundWallet()` helper function on the XRP Ledger [Testnet](parallel-networks.html):
|
||||
For testing and development purposes, you can use the `fundWallet()` helper function on the XRP Ledger [Testnet](../../concepts/networks-and-servers/parallel-networks.md):
|
||||
|
||||
{{ include_code("_code-samples/get-started/php/get-account-info.php", start_with="<?php", end_before="// Create an AccountInfoRequest", language="php") }}
|
||||
{% code-snippet file="/_code-samples/get-started/php/get-account-info.php" from="<?php" before="// Create an AccountInfoRequest" language="php" /%}
|
||||
|
||||
### 3. Query the XRP Ledger
|
||||
|
||||
You can query the XRP Ledger to get information about [a specific account](account-methods.html), [a specific transaction](tx.html), the state of a [current or a historical ledger](ledger-methods.html), and [the XRP Ledger's decentralized exchange](path-and-order-book-methods.html). You need to make these queries, among other reasons, to look up account info to follow best practices for [reliable transaction submission](reliable-transaction-submission.html).
|
||||
You can query the XRP Ledger to get information about [a specific account](../../references/http-websocket-apis/public-api-methods/account-methods/index.md), [a specific transaction](../../references/http-websocket-apis/public-api-methods/transaction-methods/tx.md), the state of a [current or a historical ledger](../../references/http-websocket-apis/public-api-methods/ledger-methods/index.md), and [the XRP Ledger's decentralized exchange](../../references/http-websocket-apis/public-api-methods/path-and-order-book-methods/index.md). You need to make these queries, among other reasons, to look up account info to follow best practices for [reliable transaction submission](../../concepts/transactions/reliable-transaction-submission.md).
|
||||
|
||||
Here, we'll use the [`JsonRpcClient` we constructed](#1-connect-to-the-xrp-ledger) to look up information about the [account we got](#2-get-account) in the previous step.
|
||||
|
||||
{{ include_code("_code-samples/get-started/php/get-account-info.php", language="php", start_with="// Create an AccountInfoRequest") }}
|
||||
{% code-snippet file="/_code-samples/get-started/php/get-account-info.php" from="// Create an AccountInfoRequest" language="php" /%}
|
||||
|
||||
### 4. Starting the script
|
||||
|
||||
@@ -153,7 +157,7 @@ Now, we have a simple application that:
|
||||
2. Connects to the XRP Ledger.
|
||||
3. Looks up and prints information about the account you created.
|
||||
|
||||
To run the app, you can copy the code from [this website's GitHub Repository]({{target.github_forkurl}}/tree/{{target.github_branch}}/content/_code-samples/get-started/php/) and run it from the command line:
|
||||
To run the app, you can copy the code from {% repo-link path="content/_code-samples/get-started/php/" %}this website's GitHub Repository{% /repo-link %} and run it from the command line:
|
||||
|
||||
```console
|
||||
composer require hardcastle/xrpl_php
|
||||
@@ -216,22 +220,18 @@ The response fields contained in `AccountInfoResponse` that you want to inspect
|
||||
|
||||
* `['account_data']['Sequence']` — This is the sequence number of the next valid transaction for the account. You need to specify the sequence number when you prepare transactions.
|
||||
|
||||
* `['account_data']['Balance']` — This is the account's balance of XRP, in drops. You can use this to confirm that you have enough XRP to send (if you're making a payment) and to meet the [current transaction cost](transaction-cost.html#current-transaction-cost) for a given transaction.
|
||||
* `['account_data']['Balance']` — This is the account's balance of XRP, in drops. You can use this to confirm that you have enough XRP to send (if you're making a payment) and to meet the [current transaction cost](../../concepts/transactions/transaction-cost.md#current-transaction-cost) for a given transaction.
|
||||
|
||||
* `['validated']` — Indicates whether the returned data is from a [validated ledger](open-closed-validated-ledgers.html). When inspecting transactions, it's important to confirm that [the results are final](finality-of-results.html) before further processing the transaction. If `validated` is `true` then you know for sure the results won't change. For more information about best practices for transaction processing, see [Reliable Transaction Submission](reliable-transaction-submission.html).
|
||||
* `['validated']` — Indicates whether the returned data is from a [validated ledger](../../concepts/ledgers/open-closed-validated-ledgers.md). When inspecting transactions, it's important to confirm that [the results are final](../../concepts/transactions/finality-of-results/index.md) before further processing the transaction. If `validated` is `true` then you know for sure the results won't change. For more information about best practices for transaction processing, see [Reliable Transaction Submission](../../concepts/transactions/reliable-transaction-submission.md).
|
||||
|
||||
For a detailed description of every response field, see [account_info](account_info.html#response-format).
|
||||
For a detailed description of every response field, see [account_info](../../references/http-websocket-apis/public-api-methods/account-methods/account_info.md#response-format).
|
||||
|
||||
|
||||
## Keep on building
|
||||
|
||||
Now that you know how to use `XRPL_PHP` to connect to the XRP Ledger, get an account, and look up information about it, you can also use `XRPL_PHP` to:
|
||||
|
||||
* [Send XRP](send-xrp.html).
|
||||
* [Set up secure signing](secure-signing.html) for your account.
|
||||
* [Send XRP](send-xrp.md).
|
||||
* [Set up secure signing](../../concepts/transactions/secure-signing.md) for your account.
|
||||
|
||||
|
||||
<!--{# common link defs #}-->
|
||||
{% include '_snippets/rippled-api-links.md' %}
|
||||
{% include '_snippets/tx-type-links.md' %}
|
||||
{% include '_snippets/rippled_versions.md' %}
|
||||
{% raw-partial file="/_snippets/common-links.md" /%}
|
||||
|
||||
@@ -21,7 +21,7 @@ In this tutorial, you'll learn:
|
||||
|
||||
* The basic building blocks of XRP Ledger-based applications.
|
||||
* How to connect to the XRP Ledger using `xrpl-py`.
|
||||
* How to get an account on the [Testnet](xrp-testnet-faucet.html) using `xrpl-py`.
|
||||
* How to get an account on the [Testnet](/resources/dev-tools/xrp-faucets) using `xrpl-py`.
|
||||
* How to use the `xrpl-py` library to look up information about an account on the XRP Ledger.
|
||||
* How to put these steps together to create a Python app.
|
||||
|
||||
@@ -41,7 +41,7 @@ pip3 install xrpl-py
|
||||
|
||||
## Start Building
|
||||
|
||||
When you're working with the XRP Ledger, there are a few things you'll need to manage, whether you're adding XRP to your [account](accounts.html), integrating with the [decentralized exchange](decentralized-exchange.html), or [issuing tokens](tokens.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 to your [account](../../concepts/accounts/accounts.md), integrating with the [decentralized exchange](../../concepts/tokens/decentralized-exchange/index.md), or [issuing tokens](../../concepts/tokens/index.md). 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:
|
||||
|
||||
@@ -54,36 +54,40 @@ Here are the basic steps you'll need to cover for almost any XRP Ledger project:
|
||||
|
||||
To make queries and submit transactions, you need to connect to the XRP Ledger. To do this with `xrpl-py`, use the [`xrp.clients` module](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.clients.html):
|
||||
|
||||
{{ include_code("_code-samples/get-started/py/get-acct-info.py", start_with="# Define the network client", end_before="# Create a wallet using the testnet faucet:", language="py") }}
|
||||
{% code-snippet file="/_code-samples/get-started/py/get-acct-info.py" from="# Define the network client" before="# Create a wallet using the testnet faucet:" language="py" /%}
|
||||
|
||||
#### Connect to the production XRP Ledger
|
||||
|
||||
The sample code in the previous section shows you how to connect to the Testnet, which is a [parallel network](parallel-networks.html) for testing where the money has no real value. 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 a [parallel network](../../concepts/networks-and-servers/parallel-networks.md) for testing where the money has no real value. 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:
|
||||
|
||||
* By [installing the core server](install-rippled.html) (`rippled`) and running a node yourself. The core server connects to the Mainnet by default, but you can [change the configuration to use Testnet or Devnet](connect-your-rippled-to-the-xrp-test-net.html). [There are good reasons to run your own core server](networks-and-servers.html#reasons-to-run-your-own-server). If you run your own server, you can connect to it like so:
|
||||
* By [installing the core server](../../infrastructure/installation/index.md) (`rippled`) and running a node yourself. The core server connects to the Mainnet by default, but you can [change the configuration to use Testnet or Devnet](../../infrastructure/configuration/connect-your-rippled-to-the-xrp-test-net.md). [There are good reasons to run your own core server](../../concepts/networks-and-servers/index.md#reasons-to-run-your-own-server). If you run your own server, you can connect to it like so:
|
||||
|
||||
from xrpl.clients import JsonRpcClient
|
||||
JSON_RPC_URL = "http://localhost:5005/"
|
||||
client = JsonRpcClient(JSON_RPC_URL)
|
||||
```
|
||||
from xrpl.clients import JsonRpcClient
|
||||
JSON_RPC_URL = "http://localhost:5005/"
|
||||
client = JsonRpcClient(JSON_RPC_URL)
|
||||
```
|
||||
|
||||
See the example [core server config file](https://github.com/XRPLF/rippled/blob/c0a0b79d2d483b318ce1d82e526bd53df83a4a2c/cfg/rippled-example.cfg#L1562) for more information about default values.
|
||||
|
||||
* By using one of the available [public servers][]:
|
||||
|
||||
from xrpl.clients import JsonRpcClient
|
||||
JSON_RPC_URL = "https://s2.ripple.com:51234/"
|
||||
client = JsonRpcClient(JSON_RPC_URL)
|
||||
```
|
||||
from xrpl.clients import JsonRpcClient
|
||||
JSON_RPC_URL = "https://s2.ripple.com:51234/"
|
||||
client = JsonRpcClient(JSON_RPC_URL)
|
||||
```
|
||||
|
||||
|
||||
### 2. Get account
|
||||
|
||||
To store value and execute transactions on the XRP Ledger, you need an account: a [set of keys](cryptographic-keys.html#key-components) and an [address](addresses.html) that's been [funded with enough XRP](accounts.html#creating-accounts) to meet the [account reserve](reserves.html). The address is the identifier of your account and you use the [private key](cryptographic-keys.html#private-key) to sign transactions that you submit to the XRP Ledger.
|
||||
To store value and execute transactions on the XRP Ledger, you need an account: a [set of keys](../../concepts/accounts/cryptographic-keys.md#key-components) and an [address](../../concepts/accounts/addresses.md) that's been [funded with enough XRP](../../concepts/accounts/accounts.md#creating-accounts) to meet the [account reserve](../../concepts/accounts/reserves.md). The address is the identifier of your account and you use the [private key](../../concepts/accounts/cryptographic-keys.md#private-key) to sign transactions that you submit to the XRP Ledger.
|
||||
|
||||
For testing and development purposes, you can use the [XRP Faucets](xrp-testnet-faucet.html) to generate keys and fund the account on the Testnet or Devnet. For production purposes, you should take care to store your keys and set up a [secure signing method](secure-signing.html). Another difference in production is that XRP has real worth, so you can't get it for free from a faucet.
|
||||
For testing and development purposes, you can use the [XRP Faucets](/resources/dev-tools/xrp-faucets) to generate keys and fund the account on the Testnet or Devnet. For production purposes, you should take care to store your keys and set up a [secure signing method](../../concepts/transactions/secure-signing.md). Another difference in production is that XRP has real worth, so you can't get it for free from a faucet.
|
||||
|
||||
To create and fund an account on the Testnet, `xrpl-py` provides the [`generate_faucet_wallet`](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.wallet.html#xrpl.wallet.generate_faucet_wallet) method:
|
||||
|
||||
{{ include_code("_code-samples/get-started/py/get-acct-info.py", start_with="# Create a wallet using the testnet faucet:", end_before="# Create an account str from the wallet", language="py") }}
|
||||
{% code-snippet file="/_code-samples/get-started/py/get-acct-info.py" from="# Create a wallet using the testnet faucet:" before="# Create an account str from the wallet" language="py" /%}
|
||||
|
||||
|
||||
This method returns a [`Wallet` instance](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.wallet.html#xrpl.wallet.Wallet):
|
||||
@@ -107,7 +111,7 @@ In this tutorial we only query details about the generated account from the XRP
|
||||
|
||||
To prepare the transaction:
|
||||
|
||||
{{ include_code("_code-samples/get-started/py/prepare-payment.py", start_with="# Prepare payment", end_before="# print prepared payment", language="py") }}
|
||||
{% code-snippet file="/_code-samples/get-started/py/prepare-payment.py" from="# Prepare payment" before="# print prepared payment" language="py" /%}
|
||||
|
||||
|
||||
|
||||
@@ -115,26 +119,26 @@ To prepare the transaction:
|
||||
|
||||
To sign and submit the transaction:
|
||||
|
||||
{{ include_code("_code-samples/get-started/py/prepare-payment.py", start_with="# Sign and submit the transaction", end_before="# Print tx response", language="py") }}
|
||||
{% code-snippet file="/_code-samples/get-started/py/prepare-payment.py" from="# Sign and submit the transaction" before="# Print tx response" language="py" /%}
|
||||
|
||||
|
||||
##### Derive an X-address
|
||||
|
||||
You can use `xrpl-py`'s [`xrpl.core.addresscodec`](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.core.addresscodec.html) module to derive an [X-address](https://xrpaddress.info/) from the `Wallet.address` field:
|
||||
|
||||
{{ include_code("_code-samples/get-started/py/get-acct-info.py", start_with="# Derive an x-address from the classic address:", end_before="# Look up info about your account", language="py") }}
|
||||
{% code-snippet file="/_code-samples/get-started/py/get-acct-info.py" from="# Derive an x-address from the classic address:" before="# Look up info about your account" language="py" /%}
|
||||
|
||||
The X-address format [packs the address and destination tag](https://github.com/XRPLF/XRPL-Standards/issues/6) into a more user-friendly value.
|
||||
|
||||
|
||||
### 3. Query the XRP Ledger
|
||||
|
||||
You can query the XRP Ledger to get information about [a specific account](account-methods.html), [a specific transaction](tx.html), the state of a [current or a historical ledger](ledger-methods.html), and [the XRP Ledger's decentralized exchange](path-and-order-book-methods.html). You need to make these queries, among other reasons, to look up account info to follow best practices for [reliable transaction submission](reliable-transaction-submission.html).
|
||||
You can query the XRP Ledger to get information about [a specific account](../../references/http-websocket-apis/public-api-methods/account-methods/index.md), [a specific transaction](../../references/http-websocket-apis/public-api-methods/transaction-methods/tx.md), the state of a [current or a historical ledger](../../references/http-websocket-apis/public-api-methods/ledger-methods/index.md), and [the XRP Ledger's decentralized exchange](../../references/http-websocket-apis/public-api-methods/path-and-order-book-methods/index.md). You need to make these queries, among other reasons, to look up account info to follow best practices for [reliable transaction submission](../../concepts/transactions/reliable-transaction-submission.md).
|
||||
|
||||
Here, we use `xrpl-py`'s [`xrpl.account`](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.account.html) module to look up information about the [account we got](#2-get-account) in the previous step.
|
||||
|
||||
|
||||
{{ include_code("_code-samples/get-started/py/get-acct-info.py", start_with="# Look up info about your account", language="py") }}
|
||||
{% code-snippet file="/_code-samples/get-started/py/get-acct-info.py" from="# Look up info about your account" language="py" /%}
|
||||
|
||||
|
||||
|
||||
@@ -147,9 +151,7 @@ Using these building blocks, we can create a Python app that:
|
||||
3. Looks up and prints information about the account you created.
|
||||
|
||||
|
||||
```python
|
||||
{% include '_code-samples/get-started/py/get-acct-info.py' %}
|
||||
```
|
||||
{% code-snippet file="/_code-samples/get-started/py/get-acct-info.py" language="python" /%}
|
||||
|
||||
To run the app, you can copy and paste the code into an editor or IDE and run it from there. Or you could download the file from the [XRP Ledger Dev Portal repo](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples/get-started/py) and run it locally:
|
||||
|
||||
@@ -196,22 +198,18 @@ The response fields that you want to inspect in most cases are:
|
||||
|
||||
* `account_data.Sequence` — This is the sequence number of the next valid transaction for the account. You need to specify the sequence number when you prepare transactions. With `xrpl-py`, you can use the [`get_next_valid_seq_number`](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.account.html#xrpl.account.get_next_valid_seq_number) to get this automatically from the XRP Ledger. See an example of this usage in the project [README](https://github.com/XRPLF/xrpl-py#serialize-and-sign-transactions).
|
||||
|
||||
* `account_data.Balance` — This is the account's balance of [XRP, in drops][]. You can use this to confirm that you have enough XRP to send (if you're making a payment) and to meet the [current transaction cost](transaction-cost.html#current-transaction-cost) for a given transaction.
|
||||
* `account_data.Balance` — This is the account's balance of [XRP, in drops][]. You can use this to confirm that you have enough XRP to send (if you're making a payment) and to meet the [current transaction cost](../../concepts/transactions/transaction-cost.md#current-transaction-cost) for a given transaction.
|
||||
|
||||
* `validated` — Indicates whether the returned data is from a [validated ledger](open-closed-validated-ledgers.html). When inspecting transactions, it's important to confirm that [the results are final](finality-of-results.html) before further processing the transaction. If `validated` is `true` then you know for sure the results won't change. For more information about best practices for transaction processing, see [Reliable Transaction Submission](reliable-transaction-submission.html).
|
||||
* `validated` — Indicates whether the returned data is from a [validated ledger](../../concepts/ledgers/open-closed-validated-ledgers.md). When inspecting transactions, it's important to confirm that [the results are final](../../concepts/transactions/finality-of-results/index.md) before further processing the transaction. If `validated` is `true` then you know for sure the results won't change. For more information about best practices for transaction processing, see [Reliable Transaction Submission](../../concepts/transactions/reliable-transaction-submission.md).
|
||||
|
||||
For a detailed description of every response field, see [account_info](account_info.html#response-format).
|
||||
For a detailed description of every response field, see [account_info](../../references/http-websocket-apis/public-api-methods/account-methods/account_info.md#response-format).
|
||||
|
||||
|
||||
## Keep on building
|
||||
|
||||
Now that you know how to use `xrpl-py` to connect to the XRP Ledger, get an account, and look up information about it, you can also use `xrpl-py` to:
|
||||
|
||||
* [Send XRP](send-xrp.html).
|
||||
* [Set up secure signing](secure-signing.html) for your account.
|
||||
* [Send XRP](send-xrp.md).
|
||||
* [Set up secure signing](../../concepts/transactions/secure-signing.md) for your account.
|
||||
|
||||
|
||||
<!--{# common link defs #}-->
|
||||
{% include '_snippets/rippled-api-links.md' %}
|
||||
{% include '_snippets/tx-type-links.md' %}
|
||||
{% include '_snippets/rippled_versions.md' %}
|
||||
{% raw-partial file="/_snippets/common-links.md" /%}
|
||||
|
||||
@@ -9,7 +9,7 @@ labels:
|
||||
---
|
||||
# Monitor Incoming Payments with WebSocket
|
||||
|
||||
This tutorial shows how to monitor for incoming [payments](payment-types.html) using the [WebSocket API](http-websocket-apis.html). Since all XRP Ledger transactions are public, anyone can monitor incoming payments to any address.
|
||||
This tutorial shows how to monitor for incoming [payments](../../concepts/payment-types/index.md) using the [WebSocket API](../../references/http-websocket-apis/index.md). Since all XRP Ledger transactions are public, anyone can monitor incoming payments to any address.
|
||||
|
||||
WebSocket follows a model where the client and server open one connection, then send messages both ways through the same connection, which stays open until explicitly closed (or until the connection fails). This is in contrast to the HTTP-based API model (including JSON-RPC and RESTful APIs), where the client opens and closes a new connection for each request.[¹](#footnote-1)<a id="from-footnote-1"></a>
|
||||
|
||||
@@ -18,8 +18,8 @@ WebSocket follows a model where the client and server open one connection, then
|
||||
## Prerequisites
|
||||
|
||||
- The examples in this page use JavaScript and the WebSocket protocol, which are available in all major modern browsers. If you have some JavaScript knowledge and expertise in another programming language with a WebSocket client, you can follow along while adapting the instructions to the language of your choice.
|
||||
- You need a stable internet connection and access to an XRP Ledger server. The embedded examples connect to Ripple's pool of public servers. If you [run your own `rippled` or Clio server](install-rippled.html), you can also connect to that server locally.
|
||||
- To properly handle XRP values without rounding errors, you need access to a number type that can do math on 64-bit unsigned integers. The examples in this tutorial use [big.js](https://github.com/MikeMcl/big.js/). If you are working with [tokens](tokens.html), you need even more precision. For more information, see [Currency Precision](currency-formats.html#xrp-precision).
|
||||
- You need a stable internet connection and access to an XRP Ledger server. The embedded examples connect to Ripple's pool of public servers. If you [run your own `rippled` or Clio server](../../infrastructure/installation/index.md), you can also connect to that server locally.
|
||||
- To properly handle XRP values without rounding errors, you need access to a number type that can do math on 64-bit unsigned integers. The examples in this tutorial use [big.js](https://github.com/MikeMcl/big.js/). If you are working with [tokens](../../concepts/tokens/index.md), you need even more precision. For more information, see [Currency Precision](../../references/protocol/data-types/currency-formats.md#xrp-precision).
|
||||
|
||||
<!-- Big number support -->
|
||||
<script type="application/javascript" src="assets/vendor/big.min.js"></script>
|
||||
@@ -62,13 +62,13 @@ socket.addEventListener('close', (event) => {
|
||||
})
|
||||
```
|
||||
|
||||
The above example opens a secure connection (`wss://`) to one of Ripple's public API servers on the [Test Net](xrp-test-net-faucet.html). To connect to a locally-running `rippled` server with the default configuration instead, open an _unsecured_ connection (`ws://`) on port **6006** locally, using the following first line:
|
||||
The above example opens a secure connection (`wss://`) to one of Ripple's public API servers on the [Test Net](/resources/dev-tools/xrp-faucets). To connect to a locally-running `rippled` server with the default configuration instead, open an _unsecured_ connection (`ws://`) on port **6006** locally, using the following first line:
|
||||
|
||||
```js
|
||||
const socket = new WebSocket('ws://localhost:6006')
|
||||
```
|
||||
|
||||
**Tip:** By default, connecting to a local `rippled` server gives you access to the full set of [admin methods](admin-api-methods.html) and admin-only data in some responses such as [server_info][server_info method], plus the [public methods](public-api-methods.html) that are available when you connect to public servers over the internet.
|
||||
**Tip:** By default, connecting to a local `rippled` server gives you access to the full set of [admin methods](../../references/http-websocket-apis/admin-api-methods/index.md) and admin-only data in some responses such as [server_info][server_info method], plus the [public methods](../../references/http-websocket-apis/public-api-methods/index.md) that are available when you connect to public servers over the internet.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -118,11 +118,11 @@ Since WebSocket connections can have several messages going each way and there i
|
||||
|
||||
- An `id` field that matches the `id` provided in the request this is a response for. (This is important because responses may arrive out of order.)
|
||||
|
||||
- A `status` field that indicates whether the API successfully processed your request. The string value `success` indicates [a successful response](response-formatting.html). The string value `error` indicates [an error](error-formatting.html).
|
||||
- A `status` field that indicates whether the API successfully processed your request. The string value `success` indicates [a successful response](../../references/http-websocket-apis/api-conventions/response-formatting.md). The string value `error` indicates [an error](../../references/http-websocket-apis/api-conventions/error-formatting.md).
|
||||
|
||||
**Warning:** When submitting transactions, a `status` of `success` at the top level of the WebSocket message does not mean that the transaction itself succeeded. It only indicates that the server understood your request. For looking up a transaction's actual outcome, see [Look Up Transaction Results](look-up-transaction-results.html).
|
||||
**Warning:** When submitting transactions, a `status` of `success` at the top level of the WebSocket message does not mean that the transaction itself succeeded. It only indicates that the server understood your request. For looking up a transaction's actual outcome, see [Look Up Transaction Results](../../concepts/transactions/finality-of-results/look-up-transaction-results.md).
|
||||
|
||||
- For follow-up messages from [subscriptions](subscribe.html), the `type` indicates the type of follow-up message it is, such as the notification of a new transaction, ledger, or validation; or a follow-up to an ongoing [pathfinding request](path_find.html). Your client only receives these messages if it subscribes to them.
|
||||
- For follow-up messages from [subscriptions](../../references/http-websocket-apis/public-api-methods/subscription-methods/subscribe.md), the `type` indicates the type of follow-up message it is, such as the notification of a new transaction, ledger, or validation; or a follow-up to an ongoing [pathfinding request](../../references/http-websocket-apis/public-api-methods/path-and-order-book-methods/path_find.md). Your client only receives these messages if it subscribes to them.
|
||||
|
||||
**Tip:** The [xrpl.js library for JavaScript](https://js.xrpl.org/) handles this step by default. All asynchronous API requests use Promises to provide the response, and you can listen to streams using the `.on(event, callback)` method of the `Client`.
|
||||
|
||||
@@ -288,7 +288,7 @@ const log_tx = function(tx) {
|
||||
WS_HANDLERS["transaction"] = log_tx
|
||||
```
|
||||
|
||||
For the following example, try opening the [Transaction Sender](tx-sender.html) in a different window or even on a different device and sending transactions to the address you subscribed to:
|
||||
For the following example, try opening the [Transaction Sender](/resources/dev-tools/tx-sender) in a different window or even on a different device and sending transactions to the address you subscribed to:
|
||||
|
||||
{{ start_step("Subscribe") }}
|
||||
<label for="subscribe_address">Test Net Address:</label>
|
||||
@@ -332,33 +332,31 @@ WS_HANDLERS["transaction"] = log_tx
|
||||
|
||||
## 4. Read Incoming Payments
|
||||
|
||||
When you subscribe to an account, you get messages for _all transactions to or from the account_, as well as _transactions that affect the account indirectly_, such as trading its [tokens](tokens.html). If your goal is to recognize when the account has received incoming payments, you must filter the transactions stream and process the payments based on the amount they actually delivered. Look for the following information:
|
||||
When you subscribe to an account, you get messages for _all transactions to or from the account_, as well as _transactions that affect the account indirectly_, such as trading its [tokens](../../concepts/tokens/index.md). If your goal is to recognize when the account has received incoming payments, you must filter the transactions stream and process the payments based on the amount they actually delivered. Look for the following information:
|
||||
|
||||
- The **`validated` field** indicates that the transaction's outcome is [final](finality-of-results.html). This should always be the case when you subscribe to `accounts`, but if you _also_ subscribe to `accounts_proposed` or the `transactions_proposed` stream then the server sends similar messages on the same connection for unconfirmed transactions. As a precaution, it's best to always check the `validated` field.
|
||||
- The **`meta.TransactionResult` field** is the [transaction result](transaction-results.html). If the result is not `tesSUCCESS`, the transaction failed and cannot have delivered any value.
|
||||
- The **`validated` field** indicates that the transaction's outcome is [final](../../concepts/transactions/finality-of-results/index.md). This should always be the case when you subscribe to `accounts`, but if you _also_ subscribe to `accounts_proposed` or the `transactions_proposed` stream then the server sends similar messages on the same connection for unconfirmed transactions. As a precaution, it's best to always check the `validated` field.
|
||||
- The **`meta.TransactionResult` field** is the [transaction result](../../references/protocol/transactions/transaction-results/transaction-results.md). If the result is not `tesSUCCESS`, the transaction failed and cannot have delivered any value.
|
||||
- The **`transaction.Account`** field is the sender of the transaction. If you are only looking for transactions sent by others, you can ignore any transactions where this field matches your account's address. (Keep in mind, it _is_ possible to make a cross-currency payment to yourself.)
|
||||
- The **`transaction.TransactionType` field** is the type of transaction. The transaction types that can possibly deliver currency to an account are as follows:
|
||||
- **[Payment transactions][]** can deliver XRP or [tokens](tokens.html). Filter these by the `transaction.Destination` field, which contains the address of the recipient, and always use the `meta.delivered_amount` to see how much the payment actually delivered. XRP amounts are [formatted as strings](basic-data-types.html#specifying-currency-amounts).
|
||||
- **[Payment transactions][]** can deliver XRP or [tokens](../../concepts/tokens/index.md). Filter these by the `transaction.Destination` field, which contains the address of the recipient, and always use the `meta.delivered_amount` to see how much the payment actually delivered. XRP amounts are [formatted as strings](../../references/protocol/data-types/basic-data-types.md#specifying-currency-amounts).
|
||||
|
||||
**Warning:** If you use the `transaction.Amount` field instead, you may be vulnerable to the [partial payments exploit](partial-payments.html#partial-payments-exploit). Malicious users can use this exploit to trick you into allowing the malicious user to trade or withdraw more money than they paid you.
|
||||
**Warning:** If you use the `transaction.Amount` field instead, you may be vulnerable to the [partial payments exploit](../../concepts/payment-types/partial-payments.md#partial-payments-exploit). Malicious users can use this exploit to trick you into allowing the malicious user to trade or withdraw more money than they paid you.
|
||||
|
||||
- **[CheckCash transactions][]** allow an account to receive money authorized by a different account's [CheckCreate transaction][]. Look at the metadata of a **CheckCash transaction** to see how much currency the account received.
|
||||
|
||||
- **[EscrowFinish transactions][]** can deliver XRP by finishing an [Escrow](escrow.html) created by a previous [EscrowCreate transaction][]. Look at the metadata of the **EscrowFinish transaction** to see which account received XRP from the escrow and how much.
|
||||
- **[EscrowFinish transactions][]** can deliver XRP by finishing an [Escrow](../../concepts/payment-types/escrow.md) created by a previous [EscrowCreate transaction][]. Look at the metadata of the **EscrowFinish transaction** to see which account received XRP from the escrow and how much.
|
||||
|
||||
- **[OfferCreate transactions][]** can deliver XRP or tokens by consuming offers your account has previously placed in the XRP Ledger's [decentralized exchange](decentralized-exchange.html). If you never place offers, you cannot receive money this way. Look at the metadata to see what currency the account received, if any, and how much.
|
||||
- **[OfferCreate transactions][]** can deliver XRP or tokens by consuming offers your account has previously placed in the XRP Ledger's [decentralized exchange](../../concepts/tokens/decentralized-exchange/index.md). If you never place offers, you cannot receive money this way. Look at the metadata to see what currency the account received, if any, and how much.
|
||||
|
||||
- **[PaymentChannelClaim transactions][]** can deliver XRP from a [payment channel](payment-channels.html). Look at the metadata to see which accounts, if any, received XRP from the transaction.
|
||||
- **[PaymentChannelClaim transactions][]** can deliver XRP from a [payment channel](../../concepts/payment-types/payment-channels.md). Look at the metadata to see which accounts, if any, received XRP from the transaction.
|
||||
|
||||
- **[PaymentChannelFund transactions][]** can return XRP from a closed (expired) payment channel to the sender.
|
||||
|
||||
- The **`meta` field** contains [transaction metadata](transaction-metadata.html), including exactly how much of which currency or currencies was delivered where. See [Look Up transaction Results](look-up-transaction-results.html) for more information on how to understand transaction metadata.
|
||||
- The **`meta` field** contains [transaction metadata](../../references/protocol/transactions/metadata.md), including exactly how much of which currency or currencies was delivered where. See [Look Up transaction Results](../../concepts/transactions/finality-of-results/look-up-transaction-results.md) for more information on how to understand transaction metadata.
|
||||
|
||||
The following sample code looks at transaction metadata of all the above transaction types to report how much XRP an account received:
|
||||
|
||||
```js
|
||||
{% include '_code-samples/monitor-payments-websocket/js/read-amount-received.js' %}
|
||||
```
|
||||
{% code-snippet file="/_code-samples/monitor-payments-websocket/js/read-amount-received.js" language="js" /%}
|
||||
|
||||
{{ start_step("Read Payments") }}
|
||||
<button id="tx_read" class="btn btn-primary" disabled="disabled">Start Reading</button>
|
||||
@@ -463,30 +461,26 @@ $("#tx_read").click((event) => {
|
||||
|
||||
## Next Steps
|
||||
|
||||
- [Look Up Transaction Results](look-up-transaction-results.html) to see exactly what a transaction did, and build your software to react appropriately.
|
||||
- Try [Sending XRP](send-xrp.html) from your own address.
|
||||
- Try monitoring for transactions of advanced types like [Escrows](escrow.html), [Checks](checks.html), or [Payment Channels](payment-channels.html), and responding to incoming notifications.
|
||||
- [Look Up Transaction Results](../../concepts/transactions/finality-of-results/look-up-transaction-results.md) to see exactly what a transaction did, and build your software to react appropriately.
|
||||
- Try [Sending XRP](send-xrp.md) from your own address.
|
||||
- Try monitoring for transactions of advanced types like [Escrows](../../concepts/payment-types/escrow.md), [Checks](../../concepts/payment-types/checks.md), or [Payment Channels](../../concepts/payment-types/payment-channels.md), and responding to incoming notifications.
|
||||
<!--{# TODO: uncomment when it's ready. - To more robustly handle internet instability, [Follow a Transaction Chain](follow-a-transaction-chain.html) to detect if you missed a notification. #}-->
|
||||
|
||||
## Other Programming Languages
|
||||
|
||||
Many programming languages have libraries for sending and receiving data over a WebSocket connection. If you want a head-start on communicating with `rippled`'s WebSocket API in a language other than JavaScript, the following examples show how:
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
{% tabs %}
|
||||
|
||||
_Go_
|
||||
{% tab label="Go" %}
|
||||
{% code-snippet file="/_code-samples/monitor-payments-websocket/go/monitor-incoming-payments.go" language="go" /%}
|
||||
{% /tab %}
|
||||
|
||||
```go
|
||||
{% include '_code-samples/monitor-payments-websocket/go/monitor-incoming-payments.go' %}
|
||||
```
|
||||
{% tab label="Python" %}
|
||||
{% code-snippet file="/_code-samples/monitor-payments-websocket/py/monitor_incoming.py" language="py" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
|
||||
```py
|
||||
{% include '_code-samples/monitor-payments-websocket/py/monitor_incoming.py' %}
|
||||
```
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
{% /tabs %}
|
||||
|
||||
**Tip:** Don't see the programming language of your choice? Click the "Edit on GitHub" link at the top of this page and contribute your own sample code!
|
||||
|
||||
@@ -498,18 +492,14 @@ _Python_
|
||||
## See Also
|
||||
|
||||
- **Concepts:**
|
||||
- [Transactions](transactions.html)
|
||||
- [Finality of Results](finality-of-results.html) - How to know when a transaction's success or failure is final. (Short version: if a transaction is in a validated ledger, its outcome and metadata are final.)
|
||||
- [Transactions](../../concepts/transactions/index.md)
|
||||
- [Finality of Results](../../concepts/transactions/finality-of-results/index.md) - How to know when a transaction's success or failure is final. (Short version: if a transaction is in a validated ledger, its outcome and metadata are final.)
|
||||
- **Tutorials:**
|
||||
- [Reliable Transaction Submission](reliable-transaction-submission.html)
|
||||
- [Look Up Transaction Results](look-up-transaction-results.html)
|
||||
- [Reliable Transaction Submission](../../concepts/transactions/reliable-transaction-submission.md)
|
||||
- [Look Up Transaction Results](../../concepts/transactions/finality-of-results/look-up-transaction-results.md)
|
||||
- **References:**
|
||||
- [Transaction Types](transaction-types.html)
|
||||
- [Transaction Metadata](transaction-metadata.html) - Summary of the metadata format and fields that appear in metadata
|
||||
- [Transaction Results](transaction-results.html) - Tables of all possible result codes for transactions.
|
||||
- [Transaction Types](../../references/protocol/transactions/types/index.md)
|
||||
- [Transaction Metadata](../../references/protocol/transactions/metadata.md) - Summary of the metadata format and fields that appear in metadata
|
||||
- [Transaction Results](../../references/protocol/transactions/transaction-results/transaction-results.md) - Tables of all possible result codes for transactions.
|
||||
|
||||
|
||||
<!--{# common link defs #}-->
|
||||
{% include '_snippets/rippled-api-links.md' %}
|
||||
{% include '_snippets/tx-type-links.md' %}
|
||||
{% include '_snippets/rippled_versions.md' %}
|
||||
{% raw-partial file="/_snippets/common-links.md" /%}
|
||||
|
||||
@@ -7,20 +7,20 @@ labels:
|
||||
---
|
||||
# Public Servers
|
||||
|
||||
If you don't [run your own `rippled` server](install-rippled.html), you can use the following public servers to submit transactions or read data from the ledger.
|
||||
If you don't [run your own `rippled` server](../../infrastructure/installation/index.md), you can use the following public servers to submit transactions or read data from the ledger.
|
||||
|
||||
| Operator | [Network][] | JSON-RPC URL | WebSocket URL | Notes |
|
||||
|:----------|:------------|:-------------|:--------------|:---------------------|
|
||||
| XRP Ledger Foundation | **Mainnet** | `https://xrplcluster.com/` <br> `https://xrpl.ws/` [²][] | `wss://xrplcluster.com/` <br> `wss://xrpl.ws/` [²][] | Full history server cluster with CORS support. |
|
||||
| Ripple[¹][] | **Mainnet** | `https://s1.ripple.com:51234/` | `wss://s1.ripple.com/` | General purpose server cluster |
|
||||
| Ripple[¹][] | **Mainnet** | `https://s2.ripple.com:51234/` | `wss://s2.ripple.com/` | [Full-history server](ledger-history.html#full-history) cluster |
|
||||
| Ripple[¹][] | **Mainnet** | `https://s2.ripple.com:51234/` | `wss://s2.ripple.com/` | [Full-history server](../../concepts/networks-and-servers/ledger-history.md#full-history) cluster |
|
||||
| Ripple[¹][] | Testnet | `https://s.altnet.rippletest.net:51234/` | `wss://s.altnet.rippletest.net:51233/` | Testnet public server |
|
||||
| XRPL Labs | Testnet | `https://testnet.xrpl-labs.com/` | `wss://testnet.xrpl-labs.com/` | Testnet public server with CORS support |
|
||||
| Ripple[¹][] | Devnet | `https://s.devnet.rippletest.net:51234/` | `wss://s.devnet.rippletest.net:51233/` | Devnet public server |
|
||||
| Ripple[¹][] | Sidechain-Devnet | `https://sidechain-net2.devnet.rippletest.net:51234/` | `wss://sidechain-net2.devnet.rippletest.net:51233/` | Sidechain Devnet to test cross-chain bridge features. Devnet serves as the locking chain while this sidechain serves as the issuing chain. |
|
||||
| XRPL Labs | Xahau Testnet | `https://xahau-test.net/` | `wss://xahau-test.net/` | [Hooks-enabled](https://hooks.xrpl.org/) Xahau Testnet |
|
||||
|
||||
[Network]: parallel-networks.html
|
||||
[Network]: ../../concepts/networks-and-servers/parallel-networks.md
|
||||
[¹]: #footnote-1
|
||||
[²]: #footnote-2
|
||||
|
||||
@@ -28,7 +28,4 @@ If you don't [run your own `rippled` server](install-rippled.html), you can use
|
||||
|
||||
<a id="footnote-2"></a>² `xrpl.ws` is an alias for `xrplcluster.com`. However, the `.ws` top-level domain's reliability may be unsuitable for production uses.
|
||||
|
||||
<!--{# common link defs #}-->
|
||||
{% include '_snippets/rippled-api-links.md' %}
|
||||
{% include '_snippets/tx-type-links.md' %}
|
||||
{% include '_snippets/rippled_versions.md' %}
|
||||
{% raw-partial file="/_snippets/common-links.md" /%}
|
||||
|
||||
@@ -13,7 +13,7 @@ top_nav_grouping: Popular Pages
|
||||
---
|
||||
# Send XRP
|
||||
|
||||
This tutorial explains how to send a direct XRP Payment using `xrpl.js` for JavaScript, `xrpl-py` for Python, `xrpl4j` for Java or `XRPL_PHP` for PHP. 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 direct XRP Payment using `xrpl.js` for JavaScript, `xrpl-py` for Python, `xrpl4j` for Java or `XRPL_PHP` for PHP. First, we step through the process with the [XRP Ledger Testnet](../../concepts/networks-and-servers/parallel-networks.md). 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.
|
||||
|
||||
@@ -25,10 +25,10 @@ This tutorial explains how to send a direct XRP Payment using `xrpl.js` for Java
|
||||
|
||||
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 [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.
|
||||
- **Java** with the [xrpl4j library](https://github.com/XRPLF/xrpl4j). See [Get Started Using Java](get-started-using-java.html) for setup steps.
|
||||
- **PHP** with the [XRPL_PHP library](https://github.com/AlexanderBuzz/xrpl-php). See [Get Started Using PHP](get-started-using-php.html) for setup steps.
|
||||
- **JavaScript** with the [xrpl.js library](https://github.com/XRPLF/xrpl.js/). See [Get Started Using JavaScript](get-started-using-javascript.md) for setup steps.
|
||||
- **Python** with the [`xrpl-py` library](https://xrpl-py.readthedocs.io/). See [Get Started using Python](get-started-using-python.md) for setup steps.
|
||||
- **Java** with the [xrpl4j library](https://github.com/XRPLF/xrpl4j). See [Get Started Using Java](get-started-using-java.md) for setup steps.
|
||||
- **PHP** with the [XRPL_PHP library](https://github.com/AlexanderBuzz/xrpl-php). See [Get Started Using PHP](get-started-using-php.md) for setup steps.
|
||||
|
||||
|
||||
## Send a Payment on the Test Net
|
||||
@@ -37,67 +37,67 @@ To interact with the XRP Ledger, you need to set up a dev environment with the n
|
||||
|
||||
To transact on the XRP Ledger, you need an address and secret key, and some XRP. The address and secret key look like this:
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
{% tabs %}
|
||||
|
||||
_JavaScript_
|
||||
{% tab label="JavaScript" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/js/send-xrp.js" from="// Example credentials" before="// Connect" language="js" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/js/send-xrp.js", start_with="// Example credentials", end_before="// Connect", language="js") }}
|
||||
{% tab label="Python" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/py/send-xrp.py" before="# Connect" language="py" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
{% tab label="Java" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/java/SendXrp.java" before="// Connect" language="java" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/py/send-xrp.py", end_before="# Connect", language="py") }}
|
||||
{% tab label="PHP" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Example credentials" before="// Create" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Java_
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/java/SendXrp.java", end_before="// Connect", language="java") }}
|
||||
|
||||
_PHP_
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/php/send-xrp.php", start_with="// Example credentials", end_before="// Create", language="php") }}
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
{% /tabs %}
|
||||
|
||||
The secret key shown here is for example only. For development purposes, you can get your own credentials, pre-funded with XRP, on the Testnet using the following interface:
|
||||
|
||||
{% include '_snippets/interactive-tutorials/generate-step.md' %}
|
||||
{% partial file="/_snippets/interactive-tutorials/generate-step.md" /%}
|
||||
|
||||
When you're building production-ready software, you should use an existing account, and manage your keys using a [secure signing configuration](secure-signing.html).
|
||||
When you're building production-ready software, you should use an existing account, and manage your keys using a [secure signing configuration](../../concepts/transactions/secure-signing.md).
|
||||
|
||||
|
||||
### 2. Connect to a Testnet Server
|
||||
|
||||
First, you must connect to an XRP Ledger server so you can get the current status of your account and the shared ledger. You can use this information to [automatically fill in some required fields of a transaction](transaction-common-fields.html#auto-fillable-fields). You also must be connected to the network to submit transactions to it.
|
||||
First, you must connect to an XRP Ledger server so you can get the current status of your account and the shared ledger. You can use this information to [automatically fill in some required fields of a transaction](../../references/protocol/transactions/common-fields.md#auto-fillable-fields). You also must be connected to the network to submit transactions to it.
|
||||
|
||||
The following code connects to a public Testnet servers:
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
{% tabs %}
|
||||
|
||||
_JavaScript_
|
||||
{% tab label="JavaScript" %}
|
||||
{% code-snippet file="/_code-samples/get-started/js/base.js" language="js" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/get-started/js/base.js", language="js") }}
|
||||
{% tab label="Python" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/py/send-xrp.py" from="# Connect" before="# Get credentials" language="py" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
{% tab label="Java" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/java/SendXrp.java" from="// Connect" before="// Prepare transaction" language="java" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/py/send-xrp.py", start_with="# Connect", end_before="# Get credentials", language="py") }}
|
||||
{% tab label="PHP" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Create a client" before="// Transaction definition" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Java_
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/java/SendXrp.java", start_with="// Connect", end_before="// Prepare transaction", language="java") }}
|
||||
|
||||
_PHP_
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/php/send-xrp.php", start_with="// Create a client", end_before="// Transaction definition", language="php") }}
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
{% /tabs %}
|
||||
|
||||
For this tutorial, click the following button to connect:
|
||||
|
||||
{% include '_snippets/interactive-tutorials/connect-step.md' %}
|
||||
{% partial file="/_snippets/interactive-tutorials/connect-step.md" /%}
|
||||
|
||||
|
||||
### 3. Prepare Transaction
|
||||
|
||||
Typically, we create XRP Ledger transactions as objects in the JSON [transaction format](transaction-formats.html). The following example shows a minimal Payment specification:
|
||||
Typically, we create XRP Ledger transactions as objects in the JSON [transaction format](../../references/protocol/transactions/index.md). The following example shows a minimal Payment specification:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -125,26 +125,25 @@ Technically, a transaction must contain some additional fields, and certain opti
|
||||
|
||||
Here's an example of preparing the above payment:
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
{% tabs %}
|
||||
|
||||
_JavaScript_
|
||||
{% tab label="JavaScript" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/js/send-xrp.js" from="// Prepare" before="// Sign" language="js" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/js/send-xrp.js", start_with="// Prepare", end_before="// Sign", language="js" ) }}
|
||||
{% tab label="Python" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/py/send-xrp.py" from="# Prepare" before="# Sign" language="py" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
{% tab label="Java" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/java/SendXrp.java" from="// Prepare" before="// Sign" language="java" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/py/send-xrp.py", start_with="# Prepare", end_before="# Sign", language="py" ) }}
|
||||
{% tab label="PHP" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Transaction definition" before="// Sign" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Java_
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/java/SendXrp.java", start_with="// Prepare", end_before="// Sign", language="java") }}
|
||||
|
||||
_PHP_
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/php/send-xrp.php", start_with="// Transaction definition", end_before="// Sign", language="php") }}
|
||||
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
{% /tabs %}
|
||||
|
||||
{{ start_step("Prepare") }}
|
||||
<div class="input-group mb-3">
|
||||
@@ -173,32 +172,27 @@ Signing a transaction uses your credentials to authorize the transaction on your
|
||||
- **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).
|
||||
- **PHP:** Use a [`sign()` method of a `Wallet` instance](https://alexanderbuzz.github.io/xrpl-php-docs/wallet.html#signing-a-transaction) instance to sign the transaction. The input to this step is a completed array of transaction instructions.
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
{% tabs %}
|
||||
|
||||
_JavaScript_
|
||||
{% tab label="JavaScript" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/js/send-xrp.js" from="// Sign" before="// Submit" language="js" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/js/send-xrp.js",
|
||||
start_with="// Sign", end_before="// Submit", language="js" ) }}
|
||||
{% tab label="Python" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/py/send-xrp.py" from="# Sign" before="# Submit" language="py" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
{% tab label="Java" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/java/SendXrp.java" from="// Sign" before="// Submit" language="java" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/py/send-xrp.py",
|
||||
start_with="# Sign", end_before="# Submit", language="py" ) }}
|
||||
{% tab label="PHP" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Sign" before="// Submit" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Java_
|
||||
{% /tabs %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/java/SendXrp.java",
|
||||
start_with="// Sign", end_before="// Submit", language="java" ) }}
|
||||
|
||||
|
||||
_PHP_
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/php/send-xrp.php",
|
||||
start_with="// Sign", end_before="// Submit", language="php" ) }}
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
|
||||
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](../../references/protocol/binary-format.md), called a "blob".
|
||||
|
||||
- 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.
|
||||
@@ -221,23 +215,25 @@ Now that you have a signed transaction, you can submit it to an XRP Ledger serve
|
||||
- **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.
|
||||
- **PHP:** Use the [`submitAndWait()` method of the Client](https://alexanderbuzz.github.io/xrpl-php-docs/client.html) to submit a transaction to the network and wait for the response.
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
{% tabs %}
|
||||
|
||||
_JavaScript_
|
||||
{% tab label="JavaScript" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/js/send-xrp.js" from="// Submit" before="// Wait" language="js" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/js/send-xrp.js", start_with="// Submit", end_before="// Wait", language="js" ) }}
|
||||
{% tab label="Python" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/py/send-xrp.py" from="# Submit" before="# Wait" language="py" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
{% tab label="Java" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/java/SendXrp.java" from="// Submit" before="// Wait" language="java" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/py/send-xrp.py", start_with="# Submit", end_before="# Wait", language="py") }}
|
||||
{% tab label="PHP" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Submit" before="// Wait" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Java_
|
||||
{{ include_code("_code-samples/send-xrp/java/SendXrp.java", start_with="// Submit", end_before="// Wait", language="java" ) }}
|
||||
|
||||
_PHP_
|
||||
{{ include_code("_code-samples/send-xrp/php/send-xrp.php", start_with="// Submit", end_before="// Wait", language="php" ) }}
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
{% /tabs %}
|
||||
|
||||
This method returns the **tentative** result of trying to apply the transaction to the open ledger. This result _can_ change when the transaction is included in a validated ledger: transactions that succeed initially might ultimately fail, and transactions that fail initially might ultimately succeed. Still, the tentative result often matches the final result, so it's OK to get excited if you see `tesSUCCESS` here. 😁
|
||||
|
||||
@@ -245,10 +241,10 @@ If you see any other result, you should check the following:
|
||||
|
||||
- Are you using the correct addresses for the sender and destination?
|
||||
- Did you forget any other fields of the transaction, skip any steps, or make any other typos?
|
||||
- Do you have enough Test XRP to send the transaction? The amount of XRP you can send is limited by the [reserve requirement](reserves.html), which is currently 10 XRP with an additional 2 XRP for each "object" you own in the ledger. (If you generated a new address with the Testnet Faucet, you don't own any objects.)
|
||||
- Do you have enough Test XRP to send the transaction? The amount of XRP you can send is limited by the [reserve requirement](../../concepts/accounts/reserves.md), which is currently 10 XRP with an additional 2 XRP for each "object" you own in the ledger. (If you generated a new address with the Testnet Faucet, you don't own any objects.)
|
||||
- Are you connected to a server on the test network?
|
||||
|
||||
See the full list of [transaction results](transaction-results.html) for more possibilities.
|
||||
See the full list of [transaction results](../../references/protocol/transactions/transaction-results/transaction-results.md) for more possibilities.
|
||||
|
||||
{{ start_step("Submit") }}
|
||||
<button id="submit-button" class="btn btn-primary previous-steps-required" data-tx-blob-from="#signed-tx-blob" data-wait-step-name="Wait">Submit
|
||||
@@ -260,7 +256,7 @@ example transaction</button>
|
||||
|
||||
### 6. Wait for Validation
|
||||
|
||||
Most transactions are accepted into the next ledger version after they're submitted, which means it may take 4-7 seconds for a transaction's outcome to be final. If the XRP Ledger is busy or poor network connectivity delays a transaction from being relayed throughout the network, a transaction may take longer to be confirmed. (For more information on expiration of unconfirmed transactions, see [Reliable Transaction Submission](reliable-transaction-submission.html).)
|
||||
Most transactions are accepted into the next ledger version after they're submitted, which means it may take 4-7 seconds for a transaction's outcome to be final. If the XRP Ledger is busy or poor network connectivity delays a transaction from being relayed throughout the network, a transaction may take longer to be confirmed. (For more information on expiration of unconfirmed transactions, see [Reliable Transaction Submission](../../concepts/transactions/reliable-transaction-submission.md).)
|
||||
|
||||
- **JavaScript:** If you used the [`.submitAndWait()` method](https://js.xrpl.org/classes/Client.html#submitAndWait), you can wait until the returned Promise resolves. Other, more asynchronous approaches are also possible.
|
||||
|
||||
@@ -270,28 +266,28 @@ Most transactions are accepted into the next ledger version after they're submit
|
||||
|
||||
- **PHP:** If you used the [`.submitAndWait()` method](https://alexanderbuzz.github.io/xrpl-php-docs/client.html), you can wait until the returned Promise resolves. Other, more asynchronous approaches are also possible.
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
{% tabs %}
|
||||
|
||||
_JavaScript_
|
||||
{% tab label="JavaScript" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/js/send-xrp.js" from="// Wait" before="// Check" language="js" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/js/send-xrp.js", start_with="// Wait", end_before="// Check", language="js" ) }}
|
||||
{% tab label="Python" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/py/send-xrp.py" from="# Wait" before="# Check" language="py" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
{% tab label="Java" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/java/SendXrp.java" from="// Wait" before="// Check" language="java" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/py/send-xrp.py", start_with="# Wait", end_before="# Check", language="py") }}
|
||||
{% tab label="PHP" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Wait" before="// Check" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Java_
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/java/SendXrp.java", start_with="// Wait", end_before="// Check", language="java" ) }}
|
||||
|
||||
_PHP_
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/php/send-xrp.php", start_with="// Wait", end_before="// Check", language="php" ) }}
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
{% /tabs %}
|
||||
|
||||
{{ start_step("Wait") }}
|
||||
{% include '_snippets/interactive-tutorials/wait-step.md' %}
|
||||
{% partial file="/_snippets/interactive-tutorials/wait-step.md" /%}
|
||||
{{ end_step() }}
|
||||
|
||||
|
||||
@@ -303,33 +299,33 @@ To know for sure what a transaction did, you must look up the outcome of the tra
|
||||
|
||||
**Tip:** In **TypeScript** you can pass a [`TxRequest`](https://js.xrpl.org/interfaces/TxRequest.html) to the [`Client.request()`](https://js.xrpl.org/classes/Client.html#request) method.
|
||||
|
||||
- **Python:** Use the response from [`submit_and_wait()`](https://xrpl-py.readthedocs.io/en/stable/source/xrpl.transaction.html#xrpl.transaction.submit_and_wait) or call the [`xrpl.transaction.get_transaction_from_hash()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.get_transaction_from_hash). (See the [tx method response format](tx.html#response-format) for a detailed reference of the fields this can contain.)
|
||||
- **Python:** Use the response from [`submit_and_wait()`](https://xrpl-py.readthedocs.io/en/stable/source/xrpl.transaction.html#xrpl.transaction.submit_and_wait) or call the [`xrpl.transaction.get_transaction_from_hash()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.get_transaction_from_hash). (See the [tx method response format](../../references/http-websocket-apis/public-api-methods/transaction-methods/tx.md#response-format) for a detailed reference of the fields this can contain.)
|
||||
|
||||
- **Java:** Use the [`XrplClient.transaction()`](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#transaction(org.xrpl.xrpl4j.model.client.transactions.TransactionRequestParams,java.lang.Class)) method to check the status of a transaction.
|
||||
|
||||
- **PHP:** Use the response from `submitAndWait()` or call the `tx method` using [`$client->syncRequest()`](https://alexanderbuzz.github.io/xrpl-php-docs/client.html).
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
{% tabs %}
|
||||
|
||||
_JavaScript_
|
||||
{% tab label="JavaScript" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/js/send-xrp.js" from="// Check" before="// End of" language="js" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/js/send-xrp.js", start_with="// Check", end_before="// End of", language="js" ) }}
|
||||
{% tab label="Python" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/py/send-xrp.py" from="# Check" language="py" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
{% tab label="Java" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/java/SendXrp.java" from="// Check" language="java" /%}
|
||||
{% /tab %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/py/send-xrp.py", start_with="# Check", language="py") }}
|
||||
{% tab label="PHP" %}
|
||||
{% code-snippet file="/_code-samples/send-xrp/php/send-xrp.php" from="// Check" language="php" /%}
|
||||
{% /tab %}
|
||||
|
||||
_Java_
|
||||
{% /tabs %}
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/java/SendXrp.java", start_with="// Check", language="java" ) }}
|
||||
|
||||
_PHP_
|
||||
|
||||
{{ include_code("_code-samples/send-xrp/php/send-xrp.php", start_with="// Check", language="php" ) }}
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
|
||||
**Caution:** XRP Ledger APIs may return tentative results from ledger versions that have not yet been validated. For example, in [tx method][] response, be sure to look for `"validated": true` to confirm that the data comes from a validated ledger version. Transaction results that are not from a validated ledger version are subject to change. For more information, see [Finality of Results](finality-of-results.html).
|
||||
**Caution:** XRP Ledger APIs may return tentative results from ledger versions that have not yet been validated. For example, in [tx method][] response, be sure to look for `"validated": true` to confirm that the data comes from a validated ledger version. Transaction results that are not from a validated ledger version are subject to change. For more information, see [Finality of Results](../../concepts/transactions/finality-of-results/index.md).
|
||||
|
||||
{{ start_step("Check") }}
|
||||
<button id="get-tx-button" class="btn btn-primary previous-steps-required">Check transaction status</button>
|
||||
@@ -348,27 +344,26 @@ To send an XRP payment on the production XRP Ledger, the steps you take are larg
|
||||
|
||||
This tutorial uses a button to get an address that's already funded with Test Net XRP, which only works because Test Net XRP is not worth anything. For actual XRP, you need to get XRP from someone who already has some. (For example, you might buy it on an exchange.) You can generate an address and secret that'll work on either production or the Testnet as follows:
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
|
||||
_JavaScript_
|
||||
{% tabs %}
|
||||
|
||||
{% tab label="JavaScript" %}
|
||||
```js
|
||||
const wallet = new xrpl.Wallet()
|
||||
console.log(wallet.address) // Example: rGCkuB7PBr5tNy68tPEABEtcdno4hE6Y7f
|
||||
console.log(wallet.seed) // Example: sp6JS7f14BuwFY8Mw6bTtLKWauoUs
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
|
||||
{% tab label="Python" %}
|
||||
```py
|
||||
from xrpl.wallet import Wallet
|
||||
my_wallet = Wallet.create()
|
||||
print(my_wallet.address) # Example: rGCkuB7PBr5tNy68tPEABEtcdno4hE6Y7f
|
||||
print(my_wallet.seed) # Example: sp6JS7f14BuwFY8Mw6bTtLKWauoUs
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
_Java_
|
||||
|
||||
{% tab label="Java" %}
|
||||
```java
|
||||
WalletFactory walletFactory = DefaultWalletFactory.getInstance();
|
||||
SeedWalletGenerationResult generationResult = walletFactory.randomWallet(false);
|
||||
@@ -376,9 +371,9 @@ Wallet wallet = generationResult.wallet();
|
||||
System.out.println(wallet.classicAddress()); // Example: rGCkuB7PBr5tNy68tPEABEtcdno4hE6Y7f
|
||||
System.out.println(generationResult.seed()); // Example: sp6JS7f14BuwFY8Mw6bTtLKWauoUs
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
_PHP_
|
||||
|
||||
{% tab label="PHP" %}
|
||||
```php
|
||||
use XRPL_PHP\Wallet\Wallet;
|
||||
|
||||
@@ -387,86 +382,87 @@ $wallet = Wallet::generate();
|
||||
print_r("Address: " . $wallet->getAddress()); // Example: rGCkuB7PBr5tNy68tPEABEtcdno4hE6Y7f
|
||||
print_r("Seed: " . $wallet->getSeed()); // Example: sp6JS7f14BuwFY8Mw6bTtLKWauoUs
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
{% /tabs %}
|
||||
|
||||
**Warning:** You should only use an address and secret that you generated securely, on your local machine. If another computer generated the address and secret and sent it to you over a network, it's possible that someone else on the network may see that information. If they do, they'll have as much control over your XRP as you do. It's also recommended not to use the same address for the Testnet and Mainnet, because transactions that you created for use on one network could also be valid to execute on the other network, depending on the parameters you provided.
|
||||
|
||||
Generating an address and secret doesn't get you XRP directly; you're only choosing a random number. You must also receive XRP at that address to [fund the account](accounts.html#creating-accounts). A common way to acquire XRP is to buy it from an exchange, then withdraw it to your own address.
|
||||
Generating an address and secret doesn't get you XRP directly; you're only choosing a random number. You must also receive XRP at that address to [fund the account](../../concepts/accounts/accounts.md#creating-accounts). A common way to acquire XRP is to buy it from an exchange, then withdraw it to your own address.
|
||||
|
||||
### Connecting to the Production XRP Ledger
|
||||
|
||||
When you instantiate your client's connect to the XRP Ledger, you must specify a server that's synced with the appropriate [network](parallel-networks.html). For many cases, you can use [public servers](public-servers.html), such as in the following example:
|
||||
When you instantiate your client's connect to the XRP Ledger, you must specify a server that's synced with the appropriate [network](../../concepts/networks-and-servers/parallel-networks.md). For many cases, you can use [public servers](public-servers.md), such as in the following example:
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
|
||||
_JavaScript_
|
||||
{% tabs %}
|
||||
|
||||
{% tab label="JavaScript" %}
|
||||
```js
|
||||
const xrpl = require('xrpl')
|
||||
const api = new xrpl.Client('wss://xrplcluster.com')
|
||||
api.connect()
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
|
||||
{% tab label="Python" %}
|
||||
```py
|
||||
from xrpl.clients import JsonRpcClient
|
||||
client = JsonRpcClient("https://xrplcluster.com")
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
_Java_
|
||||
|
||||
{% tab label="Java" %}
|
||||
```java
|
||||
final HttpUrl rippledUrl = HttpUrl.get("https://xrplcluster.com");
|
||||
XrplClient xrplClient = new XrplClient(rippledUrl);
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
_PHP_
|
||||
|
||||
{% tab label="PHP" %}
|
||||
```
|
||||
use XRPL_PHP\Client\JsonRpcClient;
|
||||
|
||||
$client = new JsonRpcClient("https://xrplcluster.com");
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
{% /tabs %}
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
If you [install `rippled`](../../infrastructure/installation/index.md) yourself, it connects to the production network by default. (You can also [configure it to connect to the test net](../../infrastructure/configuration/connect-your-rippled-to-the-xrp-test-net.md) instead.) After the server has synced (typically within about 15 minutes of starting it up), you can connect to it locally, which has [various benefits](../../concepts/networks-and-servers/index.md). The following example shows how to connect to a server running the default configuration:
|
||||
|
||||
If you [install `rippled`](install-rippled.html) yourself, it connects to the production network by default. (You can also [configure it to connect to the test net](connect-your-rippled-to-the-xrp-test-net.html) instead.) After the server has synced (typically within about 15 minutes of starting it up), you can connect to it locally, which has [various benefits](xrpl-servers.html). The following example shows how to connect to a server running the default configuration:
|
||||
|
||||
<!-- MULTICODE_BLOCK_START -->
|
||||
|
||||
_JavaScript_
|
||||
{% tabs %}
|
||||
|
||||
{% tab label="JavaScript" %}
|
||||
```js
|
||||
const xrpl = require('xrpl')
|
||||
const api = new xrpl.Client('ws://localhost:6006')
|
||||
api.connect()
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
_Python_
|
||||
|
||||
{% tab label="Python" %}
|
||||
```py
|
||||
from xrpl.clients import JsonRpcClient
|
||||
client = JsonRpcClient("http://localhost:5005")
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
_Java_
|
||||
|
||||
{% tab label="Java" %}
|
||||
```java
|
||||
final HttpUrl rippledUrl = HttpUrl.get("http://localhost:5005");
|
||||
XrplClient xrplClient = new XrplClient(rippledUrl);
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
_PHP_
|
||||
{% tab label="PHP" %}
|
||||
```php
|
||||
use XRPL_PHP\Client\JsonRpcClient;
|
||||
|
||||
$client = new JsonRpcClient("http://localhost:5005");
|
||||
```
|
||||
{% /tab %}
|
||||
|
||||
<!-- MULTICODE_BLOCK_END -->
|
||||
{% /tabs %}
|
||||
|
||||
**Tip:** The local connection uses an unencrypted protocol (`ws` or `http`) rather than the TLS-encrypted version (`wss` or `https`). This is secure only because the communications never leave the same machine, and is easier to set up because it does not require a TLS certificate. For connections on an outside network, always use `wss` or `https`.
|
||||
|
||||
@@ -474,17 +470,12 @@ $client = new JsonRpcClient("http://localhost:5005");
|
||||
|
||||
After completing this tutorial, you may want to try the following:
|
||||
|
||||
- [Issue a token](issue-a-fungible-token.html) on the XRP Ledger Testnet.
|
||||
- [Trade in the Decentralized Exchange](trade-in-the-decentralized-exchange.html).
|
||||
- Build [Reliable transaction submission](reliable-transaction-submission.html) for production systems.
|
||||
- Check your [client library](client-libraries.html)'s API reference for the full range of XRP Ledger functionality.
|
||||
- Customize your [Account Settings](manage-account-settings.html).
|
||||
- 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.
|
||||
- [Issue a token](../use-tokens/issue-a-fungible-token.md) on the XRP Ledger Testnet.
|
||||
- [Trade in the Decentralized Exchange](../use-tokens/trade-in-the-decentralized-exchange.md).
|
||||
- Build [Reliable transaction submission](../../concepts/transactions/reliable-transaction-submission.md) for production systems.
|
||||
- Check your [client library](../../references/client-libraries.md)'s API reference for the full range of XRP Ledger functionality.
|
||||
- Customize your [Account Settings](../tasks/manage-account-settings/index.md).
|
||||
- Learn how [Transaction Metadata](../../references/protocol/transactions/metadata.md) describes the outcome of a transaction in detail.
|
||||
- Explore more [Payment Types](../../concepts/payment-types/index.md) such as Escrows and Payment Channels.
|
||||
|
||||
|
||||
|
||||
<!--{# common link defs #}-->
|
||||
{% include '_snippets/rippled-api-links.md' %}
|
||||
{% include '_snippets/tx-type-links.md' %}
|
||||
{% include '_snippets/rippled_versions.md' %}
|
||||
{% raw-partial file="/_snippets/common-links.md" /%}
|
||||
|
||||
Reference in New Issue
Block a user