mirror of
				https://github.com/XRPLF/xrpl-dev-portal.git
				synced 2025-11-04 11:55:50 +00:00 
			
		
		
		
	Content for getting-started-in-php.md and send-xrp.md
This commit is contained in:
		
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -7,3 +7,7 @@ package-lock.json
 | 
			
		||||
yarn-error.log
 | 
			
		||||
/.idea
 | 
			
		||||
.venv/
 | 
			
		||||
 | 
			
		||||
# PHP
 | 
			
		||||
vendor/
 | 
			
		||||
composer.lock
 | 
			
		||||
 
 | 
			
		||||
@@ -7,3 +7,4 @@ For more context, see the Get Started tutorial for your preferred language:
 | 
			
		||||
- [Python](https://xrpl.org/get-started-using-python.html)
 | 
			
		||||
- [Java](https://xrpl.org/get-started-using-java.html)
 | 
			
		||||
- [JavaScript](https://xrpl.org/get-started-using-javascript.html)
 | 
			
		||||
- [PHP](https://xrpl.org/get-started-using-php.html)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								content/_code-samples/get-started/php/base.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								content/_code-samples/get-started/php/base.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// Use the Composer autoloader
 | 
			
		||||
require __DIR__ . '/vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
// Imports
 | 
			
		||||
use XRPL_PHP\Client\JsonRpcClient;
 | 
			
		||||
use XRPL_PHP\Wallet\Wallet;
 | 
			
		||||
use function XRPL_PHP\Sugar\fundWallet;
 | 
			
		||||
 | 
			
		||||
// Create a client using the Testnet
 | 
			
		||||
$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");
 | 
			
		||||
 | 
			
		||||
// Create a new wallet
 | 
			
		||||
$wallet = Wallet::generate();
 | 
			
		||||
 | 
			
		||||
// Fund (and activate) the wallet
 | 
			
		||||
fundWallet($client, $wallet);
 | 
			
		||||
							
								
								
									
										5
									
								
								content/_code-samples/get-started/php/composer.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								content/_code-samples/get-started/php/composer.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
  "require": {
 | 
			
		||||
    "hardcastle/xrpl_php": "^0.8.5"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								content/_code-samples/get-started/php/get-acct-info.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								content/_code-samples/get-started/php/get-acct-info.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// Use the Composer autoloader
 | 
			
		||||
require __DIR__ . '/vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
// Imports
 | 
			
		||||
use XRPL_PHP\Client\JsonRpcClient;
 | 
			
		||||
use XRPL_PHP\Models\Account\AccountInfoRequest;
 | 
			
		||||
use XRPL_PHP\Wallet\Wallet;
 | 
			
		||||
use function XRPL_PHP\Sugar\fundWallet;
 | 
			
		||||
 | 
			
		||||
// Create a client using the Testnet
 | 
			
		||||
$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");
 | 
			
		||||
 | 
			
		||||
// Create a new wallet
 | 
			
		||||
$wallet = Wallet::generate();
 | 
			
		||||
 | 
			
		||||
// Fund (and activate) the wallet
 | 
			
		||||
fundWallet($client, $wallet);
 | 
			
		||||
 | 
			
		||||
$accountInfoRequest = new AccountInfoRequest(
 | 
			
		||||
    account: $wallet->getAddress(),
 | 
			
		||||
    ledgerIndex: 'validated'
 | 
			
		||||
 );
 | 
			
		||||
 | 
			
		||||
$accountInfoResponse = $client->syncRequest(($accountInfoRequest));
 | 
			
		||||
 | 
			
		||||
print_r($accountInfoResponse);
 | 
			
		||||
							
								
								
									
										5
									
								
								content/_code-samples/send-xrp/php/composer.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								content/_code-samples/send-xrp/php/composer.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
  "require": {
 | 
			
		||||
    "hardcastle/xrpl_php": "^0.8.5"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										49
									
								
								content/_code-samples/send-xrp/php/send-xrp.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								content/_code-samples/send-xrp/php/send-xrp.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// Use the Composer autoloader
 | 
			
		||||
require __DIR__ . '/vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
// Imports
 | 
			
		||||
use XRPL_PHP\Client\JsonRpcClient;
 | 
			
		||||
use XRPL_PHP\Models\Account\AccountInfoRequest;
 | 
			
		||||
use XRPL_PHP\Wallet\Wallet;
 | 
			
		||||
use function XRPL_PHP\Sugar\fundWallet;
 | 
			
		||||
use function XRPL_PHP\Sugar\xrpToDrops;
 | 
			
		||||
 | 
			
		||||
// Example credentials
 | 
			
		||||
$wallet = Wallet::fromSeed("sEd7zwWAu7vXMCBkkzokJHEXiKw2B2s");
 | 
			
		||||
print_r('Wallet Address: ' . $wallet->getAddress() .PHP_EOL); // rMCcNuTcajgw7YTgBy1sys3b89QqjUrMpH
 | 
			
		||||
 | 
			
		||||
// Create a client using the Testnet
 | 
			
		||||
$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");
 | 
			
		||||
 | 
			
		||||
// Transaction definition
 | 
			
		||||
$paymentTx = [
 | 
			
		||||
    "TransactionType" => "Payment",
 | 
			
		||||
    "Account" => $wallet->getAddress(),
 | 
			
		||||
    "Amount" => xrpToDrops('50'),
 | 
			
		||||
    "Destination" => "rfmMDuKPsXUgpkCvJeS132wtfXWujjHqiW",
 | 
			
		||||
    "DestinationTag" => 12345
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
// Autofill mandatory values like Sequence, Fee and LastLedgerSequence
 | 
			
		||||
$preparedTx = $client->autofill($paymentTx);
 | 
			
		||||
print_r("Prepared tx: " . PHP_EOL);
 | 
			
		||||
print_r($preparedTx);
 | 
			
		||||
 | 
			
		||||
// Sign prepared transaction
 | 
			
		||||
$signedTx = $wallet->sign($preparedTx);
 | 
			
		||||
print_r("Identifying hash: " . $signedTx['hash'] . PHP_EOL);
 | 
			
		||||
print_r("Signed blob: " . $signedTx['tx_blob'] . PHP_EOL);
 | 
			
		||||
 | 
			
		||||
 // Submit signed blob and wait for validation
 | 
			
		||||
$txResponse = $client->submitAndWait($signedTx['tx_blob']);
 | 
			
		||||
 | 
			
		||||
// Wait for validation
 | 
			
		||||
// submitAndWait() handles this automatically, but it can take 4-7s.
 | 
			
		||||
 | 
			
		||||
// Check transaction results
 | 
			
		||||
$result = $txResponse->getResult();
 | 
			
		||||
print_r("Transaction result:" . $result['meta']['TransactionResult'] . PHP_EOL);
 | 
			
		||||
 | 
			
		||||
print_r("You can check wallets/accounts and transactions on https://test.bithomp.com"  . PHP_EOL . PHP_EOL);
 | 
			
		||||
							
								
								
									
										288
									
								
								content/tutorials/get-started/get-started-using-php.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										288
									
								
								content/tutorials/get-started/get-started-using-php.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,288 @@
 | 
			
		||||
---
 | 
			
		||||
html: get-started-using-php.html
 | 
			
		||||
parent: php.html
 | 
			
		||||
funnel: Build
 | 
			
		||||
doc_type: Tutorials
 | 
			
		||||
category: Get Started
 | 
			
		||||
blurb: Build a PHP app that interacts with the XRP Ledger.
 | 
			
		||||
cta_text: Build an XRP Ledger-connected app
 | 
			
		||||
top_nav_name: PHP
 | 
			
		||||
top_nav_grouping: Get Started
 | 
			
		||||
labels:
 | 
			
		||||
  - Development
 | 
			
		||||
showcase_icon: assets/img/logos/java.svg
 | 
			
		||||
---
 | 
			
		||||
# Get Started Using PHP
 | 
			
		||||
 | 
			
		||||
This tutorial walks you through the basics of building an XRP Ledger-connected application using [`XRPL_PHP`](https://github.com/AlexanderBuzz/xrpl-php), a PHP library built to interact with the XRP Ledger.
 | 
			
		||||
 | 
			
		||||
This tutorial is intended for beginners and should take no longer than 30 minutes to complete.
 | 
			
		||||
 | 
			
		||||
## Learning Goals
 | 
			
		||||
 | 
			
		||||
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 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.
 | 
			
		||||
 | 
			
		||||
## Requirements
 | 
			
		||||
 | 
			
		||||
* `XRPL_PHP` requires PHP 8.1.
 | 
			
		||||
* Recommended for increased performance are the PHP extensions [GMP](http://php.net/manual/en/book.gmp.php) and / or [BCMATH](https://www.php.net/manual/de/book.bc.php)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Installation
 | 
			
		||||
 | 
			
		||||
`XRPL_PHP` can be installed via [Composer](http://getcomposer.org/doc/00-intro.html):
 | 
			
		||||
 | 
			
		||||
```console
 | 
			
		||||
composer require hardcastle/xrpl_php
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Start Building
 | 
			
		||||
{% set n = cycler(* range(1,99)) %}
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
 | 
			
		||||
Here are the basic steps you'll need to cover for almost any XRP Ledger project:
 | 
			
		||||
 | 
			
		||||
1. [Connect to the XRP Ledger.](#1-connect-to-the-xrp-ledger)
 | 
			
		||||
1. [Get an account.](#2-get-account)
 | 
			
		||||
1. [Query the XRP Ledger.](#3-query-the-xrp-ledger)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
### {{n.next()}}. Connect to the XRP Ledger
 | 
			
		||||
 | 
			
		||||
To make queries and submit transactions, you need to connect to the XRP Ledger. To do this with `XRPL_PHP`, you can use the [`JsonRpcClient`](hhttps://alexanderbuzz.github.io/xrpl-php-docs/client.html):
 | 
			
		||||
 | 
			
		||||
```php
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// Use the Composer autoloader
 | 
			
		||||
require __DIR__ . '/vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
// Imports 
 | 
			
		||||
use XRPL_PHP\Client\JsonRpcClient;
 | 
			
		||||
 | 
			
		||||
// Create a Client using the Testnet
 | 
			
		||||
$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Note that PHP has no native support for WebSockets, so the Client does not establish a permanent connection.
 | 
			
		||||
 | 
			
		||||
#### 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:
 | 
			
		||||
 | 
			
		||||
* 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:
 | 
			
		||||
 | 
			
		||||
        use XRPL_PHP\Client\JsonRpcClient;
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
 | 
			
		||||
        const MAINNET_JSON_RPC_URL = "https://s2.ripple.com:51234/";
 | 
			
		||||
        $client = new JsonRpcClient("MAINNET_JSON_RPC_URL");
 | 
			
		||||
 | 
			
		||||
### {{n.next()}}. 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 generate a new account, `PHP_XRPL` provides the static `generate()`method in the `Wallet` class:
 | 
			
		||||
 | 
			
		||||
```php
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// Use the Composer autoloader
 | 
			
		||||
require __DIR__ . '/vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
// Imports 
 | 
			
		||||
use XRPL_PHP\Wallet\Wallet;
 | 
			
		||||
 | 
			
		||||
// Create a new wallet
 | 
			
		||||
$wallet = Wallet::generate();
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
The result returns a `Wallet` instance:
 | 
			
		||||
 | 
			
		||||
```php
 | 
			
		||||
// print wallet properties
 | 
			
		||||
print_r([
 | 
			
		||||
  'publicKey' => $wallet->getPublicKey(),
 | 
			
		||||
  'privateKey' => $wallet->getPrivateKey(),
 | 
			
		||||
  'classicAddress' => $wallet->getAddress(),
 | 
			
		||||
  'seed' => $wallet->getSeed()
 | 
			
		||||
]);
 | 
			
		||||
 | 
			
		||||
// output
 | 
			
		||||
// Array
 | 
			
		||||
// (
 | 
			
		||||
//    [publicKey] => ED2C4CE69F663254840905AEF5FB8596FC243EDEBE0295A6ECEE86CE8EB8F76210
 | 
			
		||||
//    [privateKey] => -HIDDEN-
 | 
			
		||||
//    [classicAddress] => rBi9u1P3ofRKTFPFTgrguANz2wRqsdKHvm
 | 
			
		||||
//    [seed] => -HIDDEN-
 | 
			
		||||
//)
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
For testing and development purposes, you can use the `fundWallet()` helper function on the XRP Ledger [Testnet](parallel-networks.html):
 | 
			
		||||
 | 
			
		||||
```php
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// Use the Composer autoloader
 | 
			
		||||
require __DIR__ . '/vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
// Imports
 | 
			
		||||
use XRPL_PHP\Client\JsonRpcClient;
 | 
			
		||||
use XRPL_PHP\Wallet\Wallet;
 | 
			
		||||
use function XRPL_PHP\Sugar\fundWallet;
 | 
			
		||||
 | 
			
		||||
// Create a client using the Testnet
 | 
			
		||||
$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");
 | 
			
		||||
 | 
			
		||||
// Create a new wallet
 | 
			
		||||
$wallet = Wallet::generate();
 | 
			
		||||
 | 
			
		||||
// Fund (and activate) the wallet
 | 
			
		||||
$fundWalletResponse = fundWallet($client, $wallet);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### {{n.next()}}. 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).
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
 | 
			
		||||
```php
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
// Use the Composer autoloader
 | 
			
		||||
require __DIR__ . '/vendor/autoload.php';
 | 
			
		||||
 | 
			
		||||
// Imports
 | 
			
		||||
use XRPL_PHP\Client\JsonRpcClient;
 | 
			
		||||
use XRPL_PHP\Wallet\Wallet;
 | 
			
		||||
use function XRPL_PHP\Sugar\fundWallet;
 | 
			
		||||
 | 
			
		||||
// Create a client using the Testnet
 | 
			
		||||
$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");
 | 
			
		||||
 | 
			
		||||
// Create a new wallet
 | 
			
		||||
$wallet = Wallet::generate();
 | 
			
		||||
 | 
			
		||||
// Fund (and activate) the wallet
 | 
			
		||||
$fundWalletResponse = fundWallet($client, $wallet);
 | 
			
		||||
 | 
			
		||||
// Create an AccountInfo request "method"
 | 
			
		||||
$accountInfoRequest = new AccountInfoRequest(
 | 
			
		||||
    account: $wallet->getAddress(),
 | 
			
		||||
    ledgerIndex: 'validated'
 | 
			
		||||
 );
 | 
			
		||||
 | 
			
		||||
// Send AccountInfo request
 | 
			
		||||
$accountInfoResponse = $client->syncRequest(($accountInfoRequest));
 | 
			
		||||
 | 
			
		||||
print_r($accountInfoResponse);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### {{n.next()}}. Starting the script
 | 
			
		||||
 | 
			
		||||
Now, we have a simple application that:
 | 
			
		||||
 | 
			
		||||
1. Creates an account on the Testnet.
 | 
			
		||||
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-samples/get-started/php` directory [Github](https://github.com/XRPLF/xrpl4j-sample) and run it from the command line:
 | 
			
		||||
 | 
			
		||||
```console
 | 
			
		||||
composer require hardcastle/xrpl_php
 | 
			
		||||
php get-acct-info.php
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
You should see output similar to this example:
 | 
			
		||||
 | 
			
		||||
```console
 | 
			
		||||
XRPL_PHP\Models\Account\AccountInfoResponse Object
 | 
			
		||||
(
 | 
			
		||||
    [id:protected] => 
 | 
			
		||||
    [result:protected] => Array
 | 
			
		||||
        (
 | 
			
		||||
            [account_data] => Array
 | 
			
		||||
                (
 | 
			
		||||
                    [Account] => rDTRjR6sWrRmGe18KMVwBuL212gLpArVLy
 | 
			
		||||
                    [Balance] => 10000000000
 | 
			
		||||
                    [Flags] => 0
 | 
			
		||||
                    [LedgerEntryType] => AccountRoot
 | 
			
		||||
                    [OwnerCount] => 0
 | 
			
		||||
                    [PreviousTxnID] => AE18C0B30DE740490E66E92D9F45162C8860A6D9FCF279CF7A51FAFE05F573FB
 | 
			
		||||
                    [PreviousTxnLgrSeq] => 42719256
 | 
			
		||||
                    [Sequence] => 42719256
 | 
			
		||||
                    [index] => 4DD9F7FAE7365B7A917932D6453DBA9B223AA4FF7193691EF6E5EE230519F4CA
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
            [account_flags] => Array
 | 
			
		||||
                (
 | 
			
		||||
                    [defaultRipple] => 
 | 
			
		||||
                    [depositAuth] => 
 | 
			
		||||
                    [disableMasterKey] => 
 | 
			
		||||
                    [disallowIncomingCheck] => 
 | 
			
		||||
                    [disallowIncomingNFTokenOffer] => 
 | 
			
		||||
                    [disallowIncomingPayChan] => 
 | 
			
		||||
                    [disallowIncomingTrustline] => 
 | 
			
		||||
                    [disallowIncomingXRP] => 
 | 
			
		||||
                    [globalFreeze] => 
 | 
			
		||||
                    [noFreeze] => 
 | 
			
		||||
                    [passwordSpent] => 
 | 
			
		||||
                    [requireAuthorization] => 
 | 
			
		||||
                    [requireDestinationTag] => 
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
            [ledger_hash] => 57F0CB8311CDEAE9AC60854CC482990CE971D1FD36DB1CC215B7A6634E27E739
 | 
			
		||||
            [ledger_index] => 42719256
 | 
			
		||||
            [status] => success
 | 
			
		||||
            [validated] => 1
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    [warnings:protected] => 
 | 
			
		||||
    [status:protected] => success
 | 
			
		||||
    [type:protected] => response
 | 
			
		||||
)
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
#### Interpreting the response
 | 
			
		||||
 | 
			
		||||
The response fields contained in `AccountInfoResponse` 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.
 | 
			
		||||
 | 
			
		||||
* `['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.
 | 
			
		||||
 | 
			
		||||
* `['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).
 | 
			
		||||
 | 
			
		||||
For a detailed description of every response field, see [account_info](account_info.html#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.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<!--{# common link defs #}-->
 | 
			
		||||
{% include '_snippets/rippled-api-links.md' %}
 | 
			
		||||
{% include '_snippets/tx-type-links.md' %}
 | 
			
		||||
{% include '_snippets/rippled_versions.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, or xrpl4j for Java. First, we step through the process with the [XRP Ledger Testnet](parallel-networks.html). Then, we compare that to the additional requirements for doing the equivalent in production.
 | 
			
		||||
This tutorial explains how to send a 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.
 | 
			
		||||
 | 
			
		||||
**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.
 | 
			
		||||
 | 
			
		||||
@@ -28,6 +28,7 @@ To interact with the XRP Ledger, you need to set up a dev environment with the n
 | 
			
		||||
- **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.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Send a Payment on the Test Net
 | 
			
		||||
@@ -51,6 +52,10 @@ _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 -->
 | 
			
		||||
 | 
			
		||||
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:
 | 
			
		||||
@@ -80,6 +85,10 @@ _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 -->
 | 
			
		||||
 | 
			
		||||
For this tutorial, click the following button to connect:
 | 
			
		||||
@@ -131,6 +140,10 @@ _Java_
 | 
			
		||||
 | 
			
		||||
{{ include_code("_code-samples/send-xrp/java/SendXrp.java", start_with="// Prepare", end_before="// Sign", language="java") }}
 | 
			
		||||
 | 
			
		||||
_Java_
 | 
			
		||||
 | 
			
		||||
{{ include_code("_code-samples/send-xrp/php/send-xrp.php", start_with="// Transaction definition", end_before="// Sign", language="php") }}
 | 
			
		||||
 | 
			
		||||
<!-- MULTICODE_BLOCK_END -->
 | 
			
		||||
 | 
			
		||||
{{ start_step("Prepare") }}
 | 
			
		||||
@@ -158,6 +171,7 @@ Signing a transaction uses your credentials to authorize the transaction on your
 | 
			
		||||
- **JavaScript:** Use the [`sign()` method of a `Wallet` instance](https://js.xrpl.org/classes/Wallet.html#sign) to sign the transaction with `xrpl.js`.
 | 
			
		||||
- **Python:** Use the [`xrpl.transaction.safe_sign_transaction()` method](https://xrpl-py.readthedocs.io/en/latest/source/xrpl.transaction.html#xrpl.transaction.safe_sign_transaction) with a model and `Wallet` object.
 | 
			
		||||
- **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 -->
 | 
			
		||||
 | 
			
		||||
@@ -176,6 +190,12 @@ _Java_
 | 
			
		||||
{{ include_code("_code-samples/send-xrp/java/SendXrp.java",
 | 
			
		||||
    start_with="// Sign", end_before="// Submit", language="java" ) }}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
_Java_
 | 
			
		||||
 | 
			
		||||
{{ 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".
 | 
			
		||||
@@ -183,6 +203,7 @@ The result of the signing operation is a transaction object containing a signatu
 | 
			
		||||
- In `xrpl.js`, the signing API also returns the transaction's ID, or identifying hash, which you can use to look up the transaction later. This is a 64-character hexadecimal string that is unique to this transaction.
 | 
			
		||||
- In `xrpl-py`, you can get the transaction's hash in the response to submitting it in the next step.
 | 
			
		||||
- In xrpl4j, `SignatureService.sign` returns a `SignedTransaction`, which contains the transaction's hash, which you can use to look up the transaction later.
 | 
			
		||||
- In `XRPL_PHP`, 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.
 | 
			
		||||
 | 
			
		||||
{{ start_step("Sign") }}
 | 
			
		||||
<button id="sign-button" class="btn btn-primary previous-steps-required">Sign
 | 
			
		||||
@@ -198,6 +219,7 @@ Now that you have a signed transaction, you can submit it to an XRP Ledger serve
 | 
			
		||||
- **JavaScript:** Use the [`submitAndWait()` method of the Client](https://js.xrpl.org/classes/Client.html#submitAndWait) to submit a signed transaction to the network and wait for the response, or use [`submitSigned()`](https://js.xrpl.org/classes/Client.html#submitSigned) to submit a transaction and get only the preliminary response.
 | 
			
		||||
- **Python:** Use the [`xrpl.transaction.submit_and_wait()` method](https://xrpl-py.readthedocs.io/en/stable/source/xrpl.transaction.html#xrpl.transaction.submit_and_wait) to submit a transaction to the network and wait for a response.
 | 
			
		||||
- **Java:** Use the [`XrplClient.submit(SignedTransaction)` method](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#submit(org.xrpl.xrpl4j.crypto.signing.SignedTransaction)) to submit a transaction to the network. Use the [`XrplClient.ledger()`](https://javadoc.io/doc/org.xrpl/xrpl4j-client/latest/org/xrpl/xrpl4j/client/XrplClient.html#ledger(org.xrpl.xrpl4j.model.client.ledger.LedgerRequestParams)) method to get the latest validated ledger index.
 | 
			
		||||
- **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 -->
 | 
			
		||||
 | 
			
		||||
@@ -212,6 +234,9 @@ _Python_
 | 
			
		||||
_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 -->
 | 
			
		||||
 | 
			
		||||
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. 😁
 | 
			
		||||
@@ -243,6 +268,8 @@ Most transactions are accepted into the next ledger version after they're submit
 | 
			
		||||
 | 
			
		||||
- **Java** Poll the [`XrplClient.transaction()` method](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)) to see if your transaction has a final result. Periodically check that the latest validated ledger index has not passed the `LastLedgerIndex` of the transaction using 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.
 | 
			
		||||
 | 
			
		||||
- **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 -->
 | 
			
		||||
 | 
			
		||||
_JavaScript_
 | 
			
		||||
@@ -257,6 +284,10 @@ _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 -->
 | 
			
		||||
 | 
			
		||||
{{ start_step("Wait") }}
 | 
			
		||||
@@ -276,6 +307,8 @@ To know for sure what a transaction did, you must look up the outcome of the tra
 | 
			
		||||
 | 
			
		||||
- **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 -->
 | 
			
		||||
 | 
			
		||||
_JavaScript_
 | 
			
		||||
@@ -290,6 +323,10 @@ _Java_
 | 
			
		||||
 | 
			
		||||
{{ 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).
 | 
			
		||||
@@ -340,6 +377,17 @@ System.out.println(wallet.classicAddress()); // Example: rGCkuB7PBr5tNy68tPEABEt
 | 
			
		||||
System.out.println(generationResult.seed()); // Example: sp6JS7f14BuwFY8Mw6bTtLKWauoUs
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
_PHP_
 | 
			
		||||
 | 
			
		||||
```php
 | 
			
		||||
use XRPL_PHP\Wallet\Wallet;
 | 
			
		||||
 | 
			
		||||
$wallet = Wallet::generate();
 | 
			
		||||
 | 
			
		||||
print_r("Address: " . $wallet->getAddress());  // Example: rGCkuB7PBr5tNy68tPEABEtcdno4hE6Y7f
 | 
			
		||||
print_r("Seed: " . $wallet->getSeed()); // Example: sp6JS7f14BuwFY8Mw6bTtLKWauoUs
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
<!-- MULTICODE_BLOCK_END -->
 | 
			
		||||
 | 
			
		||||
**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.
 | 
			
		||||
@@ -374,6 +422,15 @@ final HttpUrl rippledUrl = HttpUrl.get("https://xrplcluster.com");
 | 
			
		||||
XrplClient xrplClient = new XrplClient(rippledUrl);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
_PHP_
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
use XRPL_PHP\Client\JsonRpcClient;
 | 
			
		||||
 | 
			
		||||
$client = new JsonRpcClient("https://xrplcluster.com");
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<!-- MULTICODE_BLOCK_END -->
 | 
			
		||||
 | 
			
		||||
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:
 | 
			
		||||
@@ -402,6 +459,13 @@ final HttpUrl rippledUrl = HttpUrl.get("http://localhost:5005");
 | 
			
		||||
XrplClient xrplClient = new XrplClient(rippledUrl);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
_PHP_
 | 
			
		||||
```php
 | 
			
		||||
use XRPL_PHP\Client\JsonRpcClient;
 | 
			
		||||
 | 
			
		||||
$client = new JsonRpcClient("http://localhost:5005");
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
<!-- MULTICODE_BLOCK_END -->
 | 
			
		||||
 | 
			
		||||
**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`.
 | 
			
		||||
 
 | 
			
		||||
@@ -417,6 +417,7 @@ pages:
 | 
			
		||||
            - get-started-using-python.html
 | 
			
		||||
            - get-started-using-javascript.html
 | 
			
		||||
            - get-started-using-java.html
 | 
			
		||||
            - get-started-using-php.html
 | 
			
		||||
            - get-started-using-http-websocket-apis.html
 | 
			
		||||
            # Popular pages
 | 
			
		||||
            - send-xrp.html
 | 
			
		||||
@@ -452,6 +453,7 @@ pages:
 | 
			
		||||
            - get-started-using-python.html
 | 
			
		||||
            - get-started-using-javascript.html
 | 
			
		||||
            - get-started-using-java.html
 | 
			
		||||
            - get-started-using-php.html
 | 
			
		||||
            - get-started-using-http-websocket-apis.html
 | 
			
		||||
            # Popular pages
 | 
			
		||||
            - send-xrp.html
 | 
			
		||||
@@ -1879,13 +1881,44 @@ pages:
 | 
			
		||||
        targets:
 | 
			
		||||
            - en
 | 
			
		||||
 | 
			
		||||
        # TODO: translate
 | 
			
		||||
    # TODO: translate
 | 
			
		||||
    -   md: tutorials/get-started/get-started-using-java.md
 | 
			
		||||
        top_nav_grouping: 始めましょう
 | 
			
		||||
        untranslated_warning: true
 | 
			
		||||
        targets:
 | 
			
		||||
            - ja
 | 
			
		||||
 | 
			
		||||
    # PHP ---------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
    -   name: PHP
 | 
			
		||||
        html: php.html
 | 
			
		||||
        parent: tutorials.html
 | 
			
		||||
        top_nav_grouping: Article Types
 | 
			
		||||
        template: pagetype-category.html.jinja
 | 
			
		||||
        blurb: XRPL tutorials in PHP.
 | 
			
		||||
        targets:
 | 
			
		||||
            - en
 | 
			
		||||
 | 
			
		||||
    - name: PHP
 | 
			
		||||
      html: php.html
 | 
			
		||||
      parent: tutorials.html
 | 
			
		||||
      top_nav_grouping: カテゴリ
 | 
			
		||||
      template: pagetype-category.html.jinja
 | 
			
		||||
      blurb: PHPでのXRPLチュートリアルです。
 | 
			
		||||
      targets:
 | 
			
		||||
          - ja
 | 
			
		||||
 | 
			
		||||
    -   md: tutorials/get-started/get-started-using-php.md
 | 
			
		||||
        targets:
 | 
			
		||||
            - en
 | 
			
		||||
 | 
			
		||||
    # TODO: translate
 | 
			
		||||
    - md: tutorials/get-started/get-started-using-php.md
 | 
			
		||||
      top_nav_grouping: 始めましょう
 | 
			
		||||
      untranslated_warning: true
 | 
			
		||||
      targets:
 | 
			
		||||
          - ja
 | 
			
		||||
 | 
			
		||||
    # HTTP / Websocket Tutorials ---------------------------------------------------
 | 
			
		||||
 | 
			
		||||
    -   name: HTTP / Websocket APIs
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user