Get Started
The XRP Ledger is always online and entirely public. Anyone can access it directly from a web browser with source code like what's on this page.
The following example gets the latest ledger version and a list of transactions that were newly-validated in that ledger version, using the ledger method. Try running it as-is, or change the code and see what happens.
Tip: If you can, open your browser's Developer Tools by pressing F12. The "Console" tab provides a native JavaScript console and can give insight into what code is running on any webpage.
async function main() {
const api = new xrpl.Client('wss://xrplcluster.com');
await api.connect();
let response = await api.request({
"command": "ledger",
"ledger_index": "validated",
"transactions": true
});
console.log(response);
}
main();
async function main() {
const api = new xrpl.Client('wss://s.altnet.rippletest.net/');
await api.connect();
let response = await api.request({
"command": "ledger",
"ledger_index": "validated",
"transactions": true
});
console.log(response);
}
main();
async function main() {
const api = new xrpl.Client('wss://xrplcluster.com');
await api.connect();
let response = await api.request({
"command": "ledger",
"ledger_index": "validated",
"transactions": true
});
let tx_id = response.result.ledger.transactions[0];
let response2 = await api.request({
"command": "tx",
"transaction": tx_id
});
console.log(response2);
}
main();
async function main() {
const api = new xrpl.Client('wss://xrplcluster.com');
await api.connect();
let response = await api.request({
"command": "ledger",
"ledger_index": "validated",
"transactions": true
});
console.log('Total XRP: '+xrpl.dropsToXrp(response.result.ledger.total_coins));
}
main();
Suggestions
Try editing the code above to do something different:
- Connect to the Testnet public server at
wss://s.altnet.rippletest.net/
instead. Answer - Look up the details of one of the ledger's transaction using the tx method. Answer
- Convert the
total_coins
from the response to decimal XRP. Answer
Setup Steps
This page has the necessary prerequisites already loaded, but you can access the XRP Ledger from any webpage if you load xrpl.js in that page's HTML. For example:
<script src="https://unpkg.com/xrpl@2.0.0/build/xrpl-latest-min.js"></script>
Further Reading
When you're ready to move on, continue using the XRP Ledger with these resources:
- Send XRP to send your first transaction.
- Understand the Concepts behind the XRP Ledger's design.
- Install
rippled
to participate in the network. - Get Testnet XRP to try sending and receiving payments.