xrpl-client in the browser
by WietseWind
HTML
<script src="https://cdn.jsdelivr.net/npm/xrpl-client/dist/browser.min.js"></script>
<h1>Mainnet <code id="node1"></code></h1>
<pre id="ledger1">Loading, connecting...</pre>
<h1>Xahau <code id="node2"></code></h1>
<pre id="ledger2">Loading, connecting...</pre>
<h1>Xahau Testnet <code id="node3"></code></h1>
<pre id="ledger3">Loading, connecting...</pre>
JavaScript
const { XrplClient } = require('xrpl-client')
const $ = el => document.getElementById(el)
const client1 = new XrplClient([ 'wss://xrplcluster.com', 'wss://s2.ripple.com' ])
client1.send({ command: 'server_info' }).then(info => $('node1').innerText = info.info.hostid)
client1.send({ command: 'subscribe', streams: ['ledger'] })
client1.on('ledger', function _l (ledger) { $('ledger1').innerText = JSON.stringify(ledger, null, 2) })
const client2 = new XrplClient([ 'wss://xahau.network' ])
client2.send({ command: 'server_info' }).then(info => $('node2').innerText = info.info.hostid)
client2.send({ command: 'subscribe', streams: ['ledger'] })
client2.on('ledger', function _l (ledger) { $('ledger2').innerText = JSON.stringify(ledger, null, 2) })
const client3 = new XrplClient([ 'wss://xahau-test.net' ])
client3.send({ command: 'server_info' }).then(info => $('node3').innerText = info.info.hostid)
client3.send({ command: 'subscribe', streams: ['ledger'] })
client3.on('ledger', function _l (ledger) { $('ledger3').innerText = JSON.stringify(ledger, null, 2) })