ecourty/xrpl-php
Composer 安装命令:
composer require ecourty/xrpl-php
包简介
A PHP library to interact with an XRP Ledger Node.
README 文档
README
A PHP library to interact with an XRP Ledger Node.
Table of Contents
Features
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.
Installation
Install the package using Composer:
composer require ecourty/xrpl-php
Usage
XRP Ledger Communication
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
XRP Ledger Wallet Management
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);
Submitting a transaction to the XRP Ledger
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:
FeeSequenceLastLedgerSequence
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
Code examples can be found in the examples directory.
Adding funds on a TestNet / DevNet wallet
You can add funds to a TestNet / DevNet wallet using either the Wallet class or the Faucet class.
-
Adding funds using the
Walletclass<?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
Faucetclass<?php use XRPL\Service\Faucet; $wallet = Wallet::generate(); // Or import a wallet using ::generateFromSeed Faucet::addFunds($wallet); // Adds 100 XRP to the wallet
Contracts
xrpl-php implements two contracts to allow for seamless integration with external systems:
XRPL\Contract\WalletXRPL\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.
Examples
-
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
ecourty/xrpl-php 适用场景与选型建议
ecourty/xrpl-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.85k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「json-rpc」 「ripple」 「xrp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ecourty/xrpl-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ecourty/xrpl-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ecourty/xrpl-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 JSON-RPC server implementation
The bundle for easy using json-rpc api on your project
Bitcoin and Altcoin Payment Gateway for Magento 2 via CoinGate
PHP SDK / Client for the XRP Ledger
A simple Odoo JSON-RPC client you can understand
JSON RPC 2.0 for Yii2 API with CRUD+ actions
统计信息
- 总下载量: 7.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-11