1. Go to this page and download the library: Download xrplwin/xrpl library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xrplwin / xrpl example snippets
$client = new \XRPLWin\XRPL\Client([
# Following values are defined by default, uncomment to override
//'endpoint_reporting_uri' => 'http://s1.ripple.com:51234',
//'endpoint_fullhistory_uri' => 'https://xrplcluster.com'
]);
//(optional) Override default cooldown seconds (default is 5 seconds)
$account_tx->setCooldownSeconds(10);
//(optional) Override default number of tries when request is rate-limited (default is 3)
$account_tx->setTries(5);
//(optional) Set http timeout to 3 seconds (default is 0 - eg no timeout)
// After 3 seconds method will throw \XRPLWin\XRPL\Exceptions\BadRequestException on timeout
$account_tx->setTimeout(3);
//(optional) Define custom cooldown callback
$account_tx->setCooldownHandler(
/**
* @param int $current_try Current try 1 to max
* @param int $default_cooldown_seconds Predefined cooldown seconds
* @return void|boolean return false to stop process
*/
function(int $current_try, int $default_cooldown_seconds) {
//Sample usage: calculate how much sleep() is needed depending on
$sec = $default_cooldown_seconds * $current_try;
if($sec > 15) return false; //force stop
sleep($sec);
}
);
# Send request to Ledger
try {
$account_tx->send();
} catch (\XRPLWin\XRPL\Exceptions\XWException $e) {
// Handle errors
throw $e;
}
if(!$account_tx->isSuccess()) {
//XRPL response is returned but field result.status did not return 'success'
}
# Get fetched response as array
$response = $account_tx->resultArray(); //array response from ledger
# Get fetched response as object
$response = $account_tx->result(); //object response from ledger
# Get fetched final result from helper (varies method to method)
$transactions = $account_tx->finalResult(); //array of transactions
$promise = $account_tx->requestAsync();
$promises = [
'rAcct1' => $promise,
//...more promises
];
// Wait for the requests to complete
// Throws a ConnectException if any of the requests fail
$responses = \GuzzleHttp\Promise\Utils::unwrap($promises);
//Fill response data back into $account_tx instance
$account_tx->fill($responses['rAcct1']);
//...
$transactions = $account_tx->finalResult();
# Check if there is next page
//$has_next_page = $account_tx->hasNextPage(); //bool
# Fetch next page of transactions if there is next page (next() does not return null)
if($next_account_tx = $account_tx->next()) {
$next_result = $next_account_tx->send()->finalResult();
// ...
}