A PHP library to interact with an XRP Ledger Node.
This library provides a simple way to interact with an XRP Ledger Node.
It covers 100% of the public XRP Ledger API JSON-RPC methods at date of writing.
The library is designed to be simple to use and easy to understand.
xrpl-php
allows you to:
- Communicate with the XRP Ledger
- Manage and generate XRP Ledger wallets
- Fund your testnet / devnet wallets using the Faucet
- Sign and submit transactions to the XRP Ledger
- Support for Single-Signature and Multi-Signature transactions
- Translate XRP to Drops amounts
Here are some usage examples.
Install the package using Composer:
composer require ecourty/xrpl-php
If you wish to communicate with an XRP Ledger Node, you can use the XRPLClient
class as follows:
<?php
use XRPL\Client\XRPLClient;
$client = new XRPLClient('https://s1.ripple.com:51234'); // Public XRP Ledger Node
// Testnet Public Node: https://s.altnet.rippletest.net:51234
// Devnet Public Node: https://s.devnet.rippletest.net:51234
xrpl-php
allows you to create and import XRP Ledger Wallets.
You can generate or import a wallet as follows:
<?php
use XRPL\Enum\Algorithm;
use XRPL\Service\Wallet\WalletGenerator;
use XRPL\ValueObject\Wallet;
$newWallet = WalletGenerator::generate(Algorithm::SECP256K1);
// Also works as Wallet::generate(Algorithm::ALGORITHM_SECP256K1);
$seed = 'sEd7Fv8k1vF9R5kFtPbQG7wYyVr'; // Example seed, do not reuse
$importedWallet = WalletGenerator::generateFromSeed($seed);
// Also works as Wallet::generateFromSeed($seed);
You can submit a transaction to the XRP Ledger with multiple approaches:
<?php
use XRPL\Client\XRPLClient;
use XRPL\ValueObject\Wallet;
$client = new XRPLClient('https://s1.ripple.com:51234');
$wallet = Wallet::generateFromSeed('...')
/**
* @see https://xrpl.org/docs/references/protocol/transactions/types
*/
$transactionData = [
'Account' => $wallet->getAddress(),
'TransactionType' => 'Payment',
'Destination' => 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
'Amount' => '1000000',
// ...
];
// 1. Use the XRPLCLient to submit the transaction directly
$client->submitSingleSignTransaction($transactionData, $wallet);
$client->submitMultiSignTransaction($transactionData, $wallet, $signers);
// 2. Hash the transaction yourself and submit it
$client->autofillTransaction(transactionData); // Add the missing fields if not already set (Fee, Sequence, LastLedgerSequence)
$transactionBlob = $wallet->sign($transactionData);
$client->transaction->submitOnly($transactionBlob);
Autofilling Transaction Fields
The XRP Ledger requires some fields to be set in the transaction data.
These fields are:
Fee
Sequence
LastLedgerSequence
If you want to automatically fill these fields in the transaction data, you can use the autofillTransaction
method.
This will query the correct values from your account and fill them in the transaction data.
Code examples can be found in the examples directory.
You can add funds to a TestNet / DevNet wallet using either the Wallet
class or the Faucet
class.
-
Adding funds using the
Wallet
class<?php use XRPL\ValueObject\Wallet; $wallet = Wallet::generate(); // Or import a wallet using ::generateFromSeed $wallet->addFunds(); // Adds 100 XRP to the wallet
-
Adding funds using the
Faucet
class<?php use XRPL\Service\Faucet; $wallet = Wallet::generate(); // Or import a wallet using ::generateFromSeed Faucet::addFunds($wallet); // Adds 100 XRP to the wallet
xrpl-php
implements two contracts to allow for seamless integration with external systems:
XRPL\Contract\Wallet
XRPL\Contract\KeyPair
The provided Wallet
and KeyPair
classes implement these contracts.
You can implement these interfaces in your own classes to allow for easy integration with xrpl-php
.
-
Getting the balance of an account
<?php use XRPL\Client\XRPLClient; $client = new XRPLClient('https://s1.ripple.com:51234'); $accountLines = $client->account->getAccountLines('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'); foreach ($accountLines->lines as $line) { $currency = $line->currency; $amount = $line->balance; // Implement your own logic }
-
Getting the last transactions of a Ledger (by hash / index)
If no ledger hash or index is passed, the latest Ledger data will be returned.
<?php $lastLedger = $client->ledger->getLedger( ledgerIndex: 93392983, transactions: true, expand: true ); foreach ($lastLedger->ledger->transactions as $transaction) { $txHash = $transaction->hash; $txAmount = $transaction->takerGets->getValue(); $txType = $transaction->TransactionType; // Implement your own logic }
-
Getting the NFTs of an account
<?php $accountNFTs = $client->account->getAccountNFTs('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'); foreach ($accountNFTs->accountNfts as $nft) { $nftId = $nft->id; $nftOwner = $nft->owner; $nftIssuer = $nft->issuer; // Implement your own logic }
-
Trading (Paths & Order Book)
<?php $bookChanges = $client->pathOrderBook->getBookChanges( ); foreach ($bookChanges->changes as $change) { $open = $change->open; $close = $change->close; $lowest = $change->low; $highest = $change->high; // More data is available in the model // Implement your own logic }
© Edouard Courty, 2025