mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-12-06 17:27:57 +00:00
Merge pull request #2234 from AlexanderBuzz/add_php_xrpl_to_client_libraries
Added PHP_XRPL to client-libraries.md
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -7,3 +7,6 @@ package-lock.json
|
||||
yarn-error.log
|
||||
/.idea
|
||||
.venv/
|
||||
|
||||
# PHP
|
||||
composer.lock
|
||||
|
||||
96
assets/img/logos/php.svg
Normal file
96
assets/img/logos/php.svg
Normal file
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg height="383.5975" id="svg3430" version="1.1" viewBox="0 0 711.20123 383.5975" width="711.20123" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<title id="title3510">Official PHP Logo</title>
|
||||
<metadata id="metadata3436">
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title>Official PHP Logo</dc:title>
|
||||
<dc:creator>
|
||||
<cc:Agent>
|
||||
<dc:title>Colin Viebrock</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:creator>
|
||||
<dc:description/>
|
||||
<dc:contributor>
|
||||
<cc:Agent>
|
||||
<dc:title/>
|
||||
</cc:Agent>
|
||||
</dc:contributor>
|
||||
<cc:license rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/"/>
|
||||
<dc:rights>
|
||||
<cc:Agent>
|
||||
<dc:title>Copyright Colin Viebrock 1997 - All rights reserved.</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:rights>
|
||||
<dc:date>1997</dc:date>
|
||||
</cc:Work>
|
||||
<cc:License rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
|
||||
<cc:permits rdf:resource="http://creativecommons.org/ns#Reproduction"/>
|
||||
<cc:permits rdf:resource="http://creativecommons.org/ns#Distribution"/>
|
||||
<cc:requires rdf:resource="http://creativecommons.org/ns#Notice"/>
|
||||
<cc:requires rdf:resource="http://creativecommons.org/ns#Attribution"/>
|
||||
<cc:permits rdf:resource="http://creativecommons.org/ns#DerivativeWorks"/>
|
||||
<cc:requires rdf:resource="http://creativecommons.org/ns#ShareAlike"/>
|
||||
</cc:License>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs id="defs3434">
|
||||
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath3444">
|
||||
<path d="M 11.52,162 C 11.52,81.677 135.307,16.561 288,16.561 l 0,0 c 152.693,0 276.481,65.116 276.481,145.439 l 0,0 c 0,80.322 -123.788,145.439 -276.481,145.439 l 0,0 C 135.307,307.439 11.52,242.322 11.52,162" id="path3446"/>
|
||||
</clipPath>
|
||||
<radialGradient cx="0" cy="0" fx="0" fy="0" gradientTransform="matrix(363.05789,0,0,-363.05789,177.52002,256.30713)" gradientUnits="userSpaceOnUse" id="radialGradient3452" r="1" spreadMethod="pad">
|
||||
<stop id="stop3454" offset="0" style="stop-opacity:1;stop-color:#aeb2d5"/>
|
||||
<stop id="stop3456" offset="0.3" style="stop-opacity:1;stop-color:#aeb2d5"/>
|
||||
<stop id="stop3458" offset="0.75" style="stop-opacity:1;stop-color:#484c89"/>
|
||||
<stop id="stop3460" offset="1" style="stop-opacity:1;stop-color:#484c89"/>
|
||||
</radialGradient>
|
||||
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath3468">
|
||||
<path d="M 0,324 576,324 576,0 0,0 0,324 Z" id="path3470"/>
|
||||
</clipPath>
|
||||
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath3480">
|
||||
<path d="M 0,324 576,324 576,0 0,0 0,324 Z" id="path3482"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
<g id="g3438" transform="matrix(1.25,0,0,-1.25,-4.4,394.29875)">
|
||||
<g id="g3440">
|
||||
<g clip-path="url(#clipPath3444)" id="g3442">
|
||||
<g id="g3448">
|
||||
<g id="g3450">
|
||||
<path d="M 11.52,162 C 11.52,81.677 135.307,16.561 288,16.561 l 0,0 c 152.693,0 276.481,65.116 276.481,145.439 l 0,0 c 0,80.322 -123.788,145.439 -276.481,145.439 l 0,0 C 135.307,307.439 11.52,242.322 11.52,162" id="path3462" style="fill:url(#radialGradient3452);stroke:none"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g id="g3464">
|
||||
<g clip-path="url(#clipPath3468)" id="g3466">
|
||||
<g id="g3472" transform="translate(288,27.3594)">
|
||||
<path d="M 0,0 C 146.729,0 265.68,60.281 265.68,134.641 265.68,209 146.729,269.282 0,269.282 -146.729,269.282 -265.68,209 -265.68,134.641 -265.68,60.281 -146.729,0 0,0" id="path3474" style="fill:#777bb3;fill-opacity:1;fill-rule:nonzero;stroke:none"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g id="g3476">
|
||||
<g clip-path="url(#clipPath3480)" id="g3478">
|
||||
<g id="g3484" transform="translate(161.7344,145.3066)">
|
||||
<path d="m 0,0 c 12.065,0 21.072,2.225 26.771,6.611 5.638,4.341 9.532,11.862 11.573,22.353 1.903,9.806 1.178,16.653 -2.154,20.348 C 32.783,53.086 25.417,55 14.297,55 L -4.984,55 -15.673,0 0,0 Z m -63.063,-67.75 c -0.895,0 -1.745,0.4 -2.314,1.092 -0.57,0.691 -0.801,1.601 -0.63,2.48 L -37.679,81.573 C -37.405,82.982 -36.17,84 -34.734,84 L 26.32,84 C 45.508,84 59.79,78.79 68.767,68.513 77.792,58.182 80.579,43.741 77.05,25.592 75.614,18.198 73.144,11.331 69.709,5.183 66.27,-0.972 61.725,-6.667 56.198,-11.747 49.582,-17.939 42.094,-22.429 33.962,-25.071 25.959,-27.678 15.681,-29 3.414,-29 l -24.722,0 -7.06,-36.322 c -0.274,-1.41 -1.508,-2.428 -2.944,-2.428 l -31.751,0 z" id="path3486" style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"/>
|
||||
</g>
|
||||
<g id="g3488" transform="translate(159.2236,197.3071)">
|
||||
<path d="m 0,0 16.808,0 c 13.421,0 18.083,-2.945 19.667,-4.7 2.628,-2.914 3.124,-9.058 1.435,-17.767 C 36.012,-32.217 32.494,-39.13 27.452,-43.012 22.29,-46.986 13.898,-49 2.511,-49 L -9.523,-49 0,0 Z m 28.831,35 -61.055,0 c -2.872,0 -5.341,-2.036 -5.889,-4.855 l -28.328,-145.751 c -0.342,-1.759 0.12,-3.578 1.259,-4.961 1.14,-1.383 2.838,-2.183 4.63,-2.183 l 31.75,0 c 2.873,0 5.342,2.036 5.89,4.855 l 6.588,33.895 22.249,0 c 12.582,0 23.174,1.372 31.479,4.077 8.541,2.775 16.399,7.48 23.354,13.984 5.752,5.292 10.49,11.232 14.08,17.657 3.591,6.427 6.171,13.594 7.668,21.302 3.715,19.104 0.697,34.402 -8.969,45.466 C 63.965,29.444 48.923,35 28.831,35 m -45.633,-90 19.313,0 c 12.801,0 22.336,2.411 28.601,7.234 6.266,4.824 10.492,12.875 12.688,24.157 2.101,10.832 1.144,18.476 -2.871,22.929 C 36.909,3.773 28.87,6 16.808,6 L -4.946,6 -16.802,-55 M 28.831,29 C 47.198,29 60.597,24.18 69.019,14.539 77.44,4.898 79.976,-8.559 76.616,-25.836 75.233,-32.953 72.894,-39.46 69.601,-45.355 66.304,-51.254 61.999,-56.648 56.679,-61.539 50.339,-67.472 43.296,-71.7 35.546,-74.218 27.796,-76.743 17.925,-78 5.925,-78 l -27.196,0 -7.531,-38.75 -31.75,0 28.328,145.75 61.055,0" id="path3490" style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"/>
|
||||
</g>
|
||||
<g id="g3492" transform="translate(311.583,116.3066)">
|
||||
<path d="m 0,0 c -0.896,0 -1.745,0.4 -2.314,1.092 -0.571,0.691 -0.802,1.6 -0.631,2.48 L 9.586,68.061 C 10.778,74.194 10.484,78.596 8.759,80.456 7.703,81.593 4.531,83.5 -4.848,83.5 L -27.55,83.5 -43.305,2.428 C -43.579,1.018 -44.814,0 -46.25,0 l -31.5,0 c -0.896,0 -1.745,0.4 -2.315,1.092 -0.57,0.691 -0.801,1.601 -0.63,2.48 l 28.328,145.751 c 0.274,1.409 1.509,2.427 2.945,2.427 l 31.5,0 c 0.896,0 1.745,-0.4 2.315,-1.091 0.57,-0.692 0.801,-1.601 0.63,-2.481 L -21.813,113 2.609,113 c 18.605,0 31.221,-3.28 38.569,-10.028 7.49,-6.884 9.827,-17.891 6.947,-32.719 L 34.945,2.428 C 34.671,1.018 33.437,0 32,0 L 0,0 Z" id="path3494" style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"/>
|
||||
</g>
|
||||
<g id="g3496" transform="translate(293.6611,271.0571)">
|
||||
<path d="m 0,0 -31.5,0 c -2.873,0 -5.342,-2.036 -5.89,-4.855 l -28.328,-145.751 c -0.342,-1.759 0.12,-3.578 1.26,-4.961 1.14,-1.383 2.838,-2.183 4.63,-2.183 l 31.5,0 c 2.872,0 5.342,2.036 5.89,4.855 l 15.283,78.645 20.229,0 c 9.363,0 11.328,-2 11.407,-2.086 0.568,-0.611 1.315,-3.441 0.082,-9.781 l -12.531,-64.489 c -0.342,-1.759 0.12,-3.578 1.26,-4.961 1.14,-1.383 2.838,-2.183 4.63,-2.183 l 32,0 c 2.872,0 5.342,2.036 5.89,4.855 l 13.179,67.825 c 3.093,15.921 0.447,27.864 -7.861,35.5 -7.928,7.281 -21.208,10.82 -40.599,10.82 l -20.784,0 6.143,31.605 C 6.231,-5.386 5.77,-3.566 4.63,-2.184 3.49,-0.801 1.792,0 0,0 m 0,-6 -7.531,-38.75 28.062,0 c 17.657,0 29.836,-3.082 36.539,-9.238 6.703,-6.16 8.711,-16.141 6.032,-29.938 l -13.18,-67.824 -32,0 12.531,64.488 c 1.426,7.336 0.902,12.34 -1.574,15.008 -2.477,2.668 -7.746,4.004 -15.805,4.004 l -25.176,0 -16.226,-83.5 -31.5,0 L -31.5,-6 0,-6" id="path3498" style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"/>
|
||||
</g>
|
||||
<g id="g3500" transform="translate(409.5498,145.3066)">
|
||||
<path d="m 0,0 c 12.065,0 21.072,2.225 26.771,6.611 5.638,4.34 9.532,11.861 11.574,22.353 1.903,9.806 1.178,16.653 -2.155,20.348 C 32.783,53.086 25.417,55 14.297,55 L -4.984,55 -15.673,0 0,0 Z m -63.062,-67.75 c -0.895,0 -1.745,0.4 -2.314,1.092 -0.57,0.691 -0.802,1.601 -0.631,2.48 L -37.679,81.573 C -37.404,82.982 -36.17,84 -34.733,84 L 26.32,84 C 45.509,84 59.79,78.79 68.768,68.513 77.793,58.183 80.579,43.742 77.051,25.592 75.613,18.198 73.144,11.331 69.709,5.183 66.27,-0.972 61.725,-6.667 56.198,-11.747 49.582,-17.939 42.094,-22.429 33.962,-25.071 25.959,-27.678 15.681,-29 3.414,-29 l -24.723,0 -7.057,-36.322 c -0.275,-1.41 -1.509,-2.428 -2.946,-2.428 l -31.75,0 z" id="path3502" style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"/>
|
||||
</g>
|
||||
<g id="g3504" transform="translate(407.0391,197.3071)">
|
||||
<path d="M 0,0 16.808,0 C 30.229,0 34.891,-2.945 36.475,-4.7 39.104,-7.614 39.6,-13.758 37.91,-22.466 36.012,-32.217 32.493,-39.13 27.452,-43.012 22.29,-46.986 13.898,-49 2.511,-49 L -9.522,-49 0,0 Z m 28.831,35 -61.054,0 c -2.872,0 -5.341,-2.036 -5.889,-4.855 L -66.44,-115.606 c -0.342,-1.759 0.12,-3.578 1.259,-4.961 1.14,-1.383 2.838,-2.183 4.63,-2.183 l 31.75,0 c 2.872,0 5.342,2.036 5.89,4.855 l 6.587,33.895 22.249,0 c 12.582,0 23.174,1.372 31.479,4.077 8.541,2.775 16.401,7.481 23.356,13.986 5.752,5.291 10.488,11.23 14.078,17.655 3.591,6.427 6.171,13.594 7.668,21.302 3.715,19.105 0.697,34.403 -8.969,45.467 C 63.965,29.444 48.924,35 28.831,35 m -45.632,-90 19.312,0 c 12.801,0 22.336,2.411 28.601,7.234 6.267,4.824 10.492,12.875 12.688,24.157 2.102,10.832 1.145,18.476 -2.871,22.929 C 36.909,3.773 28.87,6 16.808,6 L -4.946,6 -16.801,-55 M 28.831,29 C 47.198,29 60.597,24.18 69.019,14.539 77.441,4.898 79.976,-8.559 76.616,-25.836 75.233,-32.953 72.894,-39.46 69.601,-45.355 66.304,-51.254 61.999,-56.648 56.679,-61.539 50.339,-67.472 43.296,-71.7 35.546,-74.218 27.796,-76.743 17.925,-78 5.925,-78 l -27.196,0 -7.53,-38.75 -31.75,0 28.328,145.75 61.054,0" id="path3506" style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 10 KiB |
@@ -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)
|
||||
|
||||
26
content/_code-samples/get-started/php/base.php
Normal file
26
content/_code-samples/get-started/php/base.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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);
|
||||
|
||||
// print wallet properties
|
||||
print_r([
|
||||
'publicKey' => $wallet->getPublicKey(),
|
||||
'privateKey' => $wallet->getPrivateKey(),
|
||||
'classicAddress' => $wallet->getAddress(),
|
||||
'seed' => $wallet->getSeed()
|
||||
]);
|
||||
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"
|
||||
}
|
||||
}
|
||||
31
content/_code-samples/get-started/php/get-account-info.php
Normal file
31
content/_code-samples/get-started/php/get-account-info.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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);
|
||||
|
||||
// Create an AccountInfoRequest method
|
||||
$accountInfoRequest = new AccountInfoRequest(
|
||||
account: $wallet->getAddress(),
|
||||
ledgerIndex: 'validated'
|
||||
);
|
||||
|
||||
// Send the request to the XRPL
|
||||
$accountInfoResponse = $client->syncRequest($accountInfoRequest);
|
||||
|
||||
// Print formatted response
|
||||
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);
|
||||
@@ -9,9 +9,10 @@ These client libraries simplify some of the common work of accessing and process
|
||||
|
||||
For other programming languages, you can access the XRP Ledger through the [HTTP APIs](http-websocket-apis.html).
|
||||
|
||||
| Language | Library Name | Get Started | API Reference | Source Code |
|
||||
|----------|--------------|-------------|---------------|-------------|
|
||||
| **Python** | `xrpl-py` | [Get Started Using Python](get-started-using-python.html) | [API Reference](https://xrpl-py.readthedocs.io/) | [Repo](https://github.com/XRPLF/xrpl-py) |
|
||||
| **JavaScript** / **TypeScript** | `xrpl.js` | [Get Started](get-started-using-javascript.html) | [API Reference](https://js.xrpl.org/) | [Repo](https://github.com/XRPLF/xrpl.js) |
|
||||
| **C++** | `rippled` Signing Library | [Get Started](https://github.com/XRPLF/rippled/tree/develop/Builds/linux#signing-library) | | (Part of [`rippled`](https://github.com/XRPLF/rippled/)) |
|
||||
| **Java** | `xrpl4j` | [Get Started Using Java](get-started-using-java.html) | [API Reference](https://javadoc.io/doc/org.xrpl/) | [Repo](https://github.com/XRPLF/xrpl4j) |
|
||||
| Language | Library Name | Get Started | API Reference | Source Code |
|
||||
|---------------------------------|---------------------------|-------------|--------------|-------------|
|
||||
| **Python** | `xrpl-py` | [Get Started Using Python](get-started-using-python.html) | [API Reference](https://xrpl-py.readthedocs.io/) | [Repo](https://github.com/XRPLF/xrpl-py) |
|
||||
| **JavaScript** / **TypeScript** | `xrpl.js` | [Get Started](get-started-using-javascript.html) | [API Reference](https://js.xrpl.org/) | [Repo](https://github.com/XRPLF/xrpl.js) |
|
||||
| **C++** | `rippled` Signing Library | [Get Started](https://github.com/XRPLF/rippled/tree/develop/Builds/linux#signing-library) | | (Part of [`rippled`](https://github.com/XRPLF/rippled/)) |
|
||||
| **Java** | `xrpl4j` | [Get Started Using Java](get-started-using-java.html) | [API Reference](https://javadoc.io/doc/org.xrpl/) | [Repo](https://github.com/XRPLF/xrpl4j) |
|
||||
| **PHP** | `XRPL_PHP` | [Get Started Using PHP](get-started-using-php.html) | [XRPL_PHP Docs](https://alexanderbuzz.github.io/xrpl-php-docs/) | [Repo](https://github.com/AlexanderBuzz/xrpl-php) |
|
||||
|
||||
237
content/tutorials/get-started/get-started-using-php.md
Normal file
237
content/tutorials/get-started/get-started-using-php.md
Normal file
@@ -0,0 +1,237 @@
|
||||
---
|
||||
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 and the PHP extension [GMP](http://php.net/manual/en/book.gmp.php).
|
||||
* The PHP extension [BCMATH](https://www.php.net/manual/de/book.bc.php) is recommended for increased performance.
|
||||
|
||||
## Installation
|
||||
|
||||
`XRPL_PHP` can be installed via [Composer](https://getcomposer.org/doc/00-intro.md):
|
||||
|
||||
```console
|
||||
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.
|
||||
|
||||
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)
|
||||
|
||||
|
||||
### 1. 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`](https://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");
|
||||
|
||||
### 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 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):
|
||||
|
||||
{{ include_code("_code-samples/get-started/php/get-account-info.php", start_with="<?php", end_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).
|
||||
|
||||
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") }}
|
||||
|
||||
### 4. 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 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:
|
||||
|
||||
```console
|
||||
composer require hardcastle/xrpl_php
|
||||
php get-account-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 `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.
|
||||
|
||||
|
||||
<!--{# 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,12 +28,12 @@ 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
|
||||
{% set n = cycler(* range(1,99)) %}
|
||||
|
||||
### {{n.next()}}. Get Credentials
|
||||
### 1. Get Credentials
|
||||
|
||||
To transact on the XRP Ledger, you need an address and secret key, and some XRP. The address and secret key look like this:
|
||||
|
||||
@@ -51,6 +51,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:
|
||||
@@ -60,7 +64,7 @@ The secret key shown here is for example only. For development purposes, you can
|
||||
When you're [building production-ready software](production-readiness.html), you should use an existing account, and manage your keys using a [secure signing configuration](secure-signing.html).
|
||||
|
||||
|
||||
### {{n.next()}}. Connect to a Testnet Server
|
||||
### 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.
|
||||
|
||||
@@ -80,6 +84,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:
|
||||
@@ -87,7 +95,7 @@ For this tutorial, click the following button to connect:
|
||||
{% include '_snippets/interactive-tutorials/connect-step.md' %}
|
||||
|
||||
|
||||
### {{n.next()}}. Prepare Transaction
|
||||
### 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:
|
||||
|
||||
@@ -131,6 +139,11 @@ _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 -->
|
||||
|
||||
{{ start_step("Prepare") }}
|
||||
@@ -151,13 +164,14 @@ _Java_
|
||||
{{ end_step() }}
|
||||
|
||||
|
||||
### {{n.next()}}. Sign the Transaction Instructions
|
||||
### 4. Sign the Transaction Instructions
|
||||
|
||||
Signing a transaction uses your credentials to authorize the transaction on your behalf. The input to this step is a completed set of transaction instructions (usually JSON), and the output is a binary blob containing the instructions and a signature from the sender.
|
||||
|
||||
- **JavaScript:** Use the [`sign()` method 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" ) }}
|
||||
|
||||
|
||||
_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".
|
||||
@@ -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
|
||||
@@ -191,13 +212,14 @@ The result of the signing operation is a transaction object containing a signatu
|
||||
{{ end_step() }}
|
||||
|
||||
|
||||
### {{n.next()}}. Submit the Signed Blob
|
||||
### 5. Submit the Signed Blob
|
||||
|
||||
Now that you have a signed transaction, you can submit it to an XRP Ledger server, which relays it through the network. It's also a good idea to take note of the latest validated ledger index before you submit. The earliest ledger version that your transaction could get into as a result of this submission is one higher than the latest validated ledger when you submit it. Of course, if the same transaction was previously submitted, it could already be in a previous ledger. (It can't succeed a second time, but you may not realize it succeeded if you aren't looking in the right ledger versions.)
|
||||
|
||||
- **JavaScript:** Use the [`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. 😁
|
||||
@@ -233,7 +258,7 @@ example transaction</button>
|
||||
{{ end_step() }}
|
||||
|
||||
|
||||
### {{n.next()}}. Wait for Validation
|
||||
### 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).)
|
||||
|
||||
@@ -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") }}
|
||||
@@ -264,7 +295,7 @@ _Java_
|
||||
{{ end_step() }}
|
||||
|
||||
|
||||
### {{n.next()}}. Check Transaction Status
|
||||
### 7. Check Transaction Status
|
||||
|
||||
To know for sure what a transaction did, you must look up the outcome of the transaction when it appears in a validated ledger version.
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -418,6 +418,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
|
||||
@@ -1763,13 +1765,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 ---------------------------------------------------
|
||||
|
||||
- md: tutorials/http-websocket-apis/index.md
|
||||
|
||||
@@ -26,6 +26,12 @@
|
||||
"href": "javascript.html",
|
||||
"img": "./assets/img/logos/javascript.svg",
|
||||
},
|
||||
{
|
||||
"title": "PHP",
|
||||
"description": "Using the XRPL_PHP client library.",
|
||||
"href": "php.html",
|
||||
"img": "./assets/img/logos/php.svg",
|
||||
},
|
||||
{
|
||||
"title": "HTTP & Websocket APIs",
|
||||
"description": "Access the XRP Ledger directly through the APIs of its core server.",
|
||||
@@ -158,7 +164,7 @@
|
||||
{% else %}
|
||||
<h4 class="card-title h5">{{title}}</h4>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<p class="card-text">{{description}}</p>
|
||||
</div>
|
||||
<div class="card-footer"> </div>
|
||||
|
||||
Reference in New Issue
Block a user