What is ripple-lib vs xrpl.js?
Last updated:
ripple-lib and xrpl.js are JavaScript libraries for XRP Ledger development, but they represent different generations of the official SDK. Understanding their differences is crucial for choosing the right library for your project and planning migration strategies.
Historical Context
ripple-lib (RippleAPI) was the original JavaScript library for XRPL, first released in 2014. It served the community for nearly 8 years and powered thousands of applications. However, as XRPL evolved with new features like NFTs, AMMs, and Hooks, the library's architecture made it increasingly difficult to maintain and extend.
xrpl.js is the modern replacement, first released in 2020 and officially recommended since 2022. It represents a complete rewrite with improved architecture, TypeScript support, modern JavaScript patterns, and better documentation. Ripple officially deprecated ripple-lib in 2022 and now focuses all development efforts on xrpl.js.
Key Differences
Architecture and Design
ripple-lib uses a class-based approach with the RippleAPI class as the main entry point. It follows older callback and promise patterns. The codebase predates modern JavaScript features like async/await.
```javascript // ripple-lib (deprecated) const RippleAPI = require('ripple-lib').RippleAPI; const api = new RippleAPI({ server: 'wss://s1.ripple.com' });
api.connect().then(() => { return api.getAccountInfo('rN7n7otQDd6FczFgLdlqtyMVrn3qHwuSJ1') }).then(info => { console.log(info); }).catch(error => { console.error(error); }); ```
xrpl.js uses a modern, functional approach with first-class TypeScript support. It embraces async/await patterns and provides a cleaner, more intuitive API.
```javascript // xrpl.js (current) const xrpl = require('xrpl');
async function main() { const client = new xrpl.Client('wss://s1.ripple.com'); await client.connect(); const response = await client.request({ command: 'account_info', account: 'rN7n7otQDd6FczFgLdlqtyMVrn3qHwuSJ1', ledger_index: 'validated' }); console.log(response.result.account_data); await client.disconnect(); }
main(); ```
TypeScript Support
ripple-lib has limited TypeScript support through community-maintained type definitions that are often incomplete or outdated.
xrpl.js is written in TypeScript from the ground up, providing excellent IDE autocomplete, type checking, and inline documentation. Every transaction type, request format, and response structure is fully typed.
```typescript // xrpl.js with TypeScript import { Client, Payment, Wallet } from 'xrpl';
const client = new Client('wss://s.altnet.rippletest.net:51233'); const wallet = Wallet.generate();
const payment: Payment = { TransactionType: 'Payment', Account: wallet.address, Destination: 'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY', Amount: xrpl.xrpToDrops('10') }; // TypeScript will catch any errors in the transaction structure ```
Feature Support
ripple-lib supports core XRPL features up to approximately 2020: basic payments, DEX trading, issued currencies, escrows, payment channels, and checks. It does NOT support NFTs (XLS-20), AMM, Hooks, or newer amendments.
xrpl.js supports all current XRPL features including NFTs with NFTokenMint, NFTokenBurn, NFTokenCreateOffer, and NFTokenAcceptOffer. It also supports AMM with AMMCreate, AMMDeposit, and AMMWithdraw, Clawback transactions, Did transactions, and all future amendments through regular updates.
Transaction Submission
ripple-lib uses a high-level abstraction that sometimes hides important details:
```javascript // ripple-lib const payment = { source: { address: 'rN7n7otQDd6FczFgLdlqtyMVrn3qHwuSJ1', maxAmount: { value: '10', currency: 'XRP' } }, destination: { address: 'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY', amount: { value: '10', currency: 'XRP' } } };
const prepared = await api.preparePayment(address, payment); const signed = api.sign(prepared.txJSON, secret); const result = await api.submit(signed.signedTransaction); ```
xrpl.js provides more control and transparency:
```javascript // xrpl.js const payment = { TransactionType: 'Payment', Account: wallet.address, Destination: 'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY', Amount: xrpl.xrpToDrops('10') };
const prepared = await client.autofill(payment); const signed = wallet.sign(prepared); const result = await client.submitAndWait(signed.tx_blob); ```
Wallet Management
ripple-lib handles wallets through API methods with limited functionality.
xrpl.js provides a dedicated Wallet class with comprehensive features:
```javascript // Generate new wallet const wallet = xrpl.Wallet.generate();
// From seed const wallet2 = xrpl.Wallet.fromSeed('sEdV...');
// From secret const wallet3 = xrpl.Wallet.fromSecret('shqN...');
// From entropy const wallet4 = xrpl.Wallet.fromEntropy('00000000000000000000000000000000'); ```
Performance and Bundle Size
ripple-lib has a larger bundle size (approximately 1.5MB minified) due to legacy code and dependencies.
xrpl.js is more lightweight (approximately 500KB minified) with tree-shaking support, resulting in faster load times for web applications.
Migration Guide
If you're currently using ripple-lib, here's how to migrate:
1. Install xrpl.js: `npm install xrpl` 2. Replace RippleAPI with Client 3. Update connection patterns to async/await 4. Convert high-level payment objects to transaction JSON 5. Update response handling to use result structure 6. Test thoroughly on testnet before deploying
Which Should You Use?
Use xrpl.js for all new projects. It's actively maintained, supports all XRPL features, has better documentation, provides TypeScript support, and has an active community.
Migrate from ripple-lib if you're on an existing project, especially if you need NFT support, want TypeScript benefits, require modern XRPL features, or want long-term maintenance and security updates.
Community and Support
xrpl.js has active development on GitHub (XRPL-Labs/xrpl.js), comprehensive documentation at js.xrpl.org, active Discord support channels, and regular updates for new XRPL features.
ripple-lib is no longer actively maintained, receives no new features, has deprecated documentation, and will not support future XRPL amendments.
Conclusion
ripple-lib served the XRPL community well but is now deprecated. xrpl.js is the official, modern library that all developers should use for XRPL integration. The migration effort is worthwhile for the improved developer experience, full feature support, and long-term viability.