1. Go to this page and download the library: Download hardcastle/xrpl_php 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/ */
hardcastle / xrpl_php example snippets
use Hardcastle\XRPL_PHP\Client\JsonRpcClient;
use Hardcastle\XRPL_PHP\Models\Account\AccountObjectsRequest;
// Those will be purged from the Testnet in regular intervals, you can use fundWallet()
// to generate prefunded Wallets on the Testnet
$testnetAccountAddress = 'raKXrkYfbh4Uzqc481jTXbaKsWnW5XRMjp';
$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");
$request = new AccountObjectsRequest(
account: $testnetAccountAddress,
ledgerIndex: 'validated',
deletionBlockersOnly: true
);
// Synchronous
$response = $client->syncRequest($request);
print_r($response->getResult());
// Asynchronous - the promise resolves to the same response object
// $response = $client->request($request)->wait();
// print_r($response->getResult());
// Use your own credentials here:
$senderWallet = Wallet::fromSeed('sEdTcvQ9k4UUEHD9y947QiXEs93Fp2k');
$destination = 'rEQ3ik2kmAvajqpFweKgDghJFZQGpXxuRN';
$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");
$tx = [
"TransactionType" => "Payment",
"Account" => $senderWallet->getAddress(),
"Amount" => xrpToDrops("10"),
"Destination" => $destination
];
// Fills in Sequence, Fee and LastLedgerSequence, signs, submits, and waits
// until the transaction is in a validated ledger.
$txResponse = $client->submitAndWait($tx, autofill: true, wallet: $senderWallet);
$result = $txResponse->getResult();
// A tec result still reaches the ledger, so the code has to be checked -
// submitAndWait() returning is not by itself a success.
if ($result['meta']['TransactionResult'] !== 'tesSUCCESS') {
print_r("Payment failed with {$result['meta']['TransactionResult']}! TxHash: {$result['hash']}" . PHP_EOL);
} else {
print_r("Payment done! TxHash: {$result['hash']}" . PHP_EOL);
}
$balances = (new AccountReader($client))->getBalances($address);
// same as
$balances = $client->getBalances($address);
use Hardcastle\XRPL_PHP\Core\RippleBinaryCodec\BinaryCodec;
use Hardcastle\XRPL_PHP\Core\RippleBinaryCodec\Definitions\Definitions;
use Hardcastle\XRPL_PHP\Client\JsonRpcClient;
use Hardcastle\XRPL_PHP\Wallet\Wallet;
$definitions = Definitions::fromFile('/path/to/xahau-definitions.json');
// or Definitions::fromArray($decodedJson);
$codec = new BinaryCodec($definitions);
$wallet = Wallet::fromSeed($seed, $definitions);
$client = new JsonRpcClient('https://xahau.network', null, null, 3.0, $definitions);
use Hardcastle\XRPL_PHP\Client\Autofiller;
use Hardcastle\XRPL_PHP\Client\JsonRpcClient;
class XahauClient extends JsonRpcClient
{
public function getAutofiller(): Autofiller
{
return new XahauAutofiller($this);
}
}