Files
xrpl-dev-portal/content/tutorials/get-started/get-started.md
mDuo13 d6e06ae140 Update ripple-lib samples to 1.10.0
- Removes lodash dependecy for web version
- Uses the new generateFaucetWallet() API method
- Make 'issue a token' code capable of running in-browser or in Node.js
  without modification
2021-08-24 14:47:22 -07:00

3.4 KiB

html, parent, blurb, filters, labels
html parent blurb filters labels
get-started.html tutorials.html Get up and running with some of the resources you'll use to work with the XRP Ledger.
js_editor
Development

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 getLedger() 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.

{{currentpage.ripple_lib_tag}}

const mainnet = new ripple.RippleAPI({
  server: 'wss://s1.ripple.com'
});

(async function(api) {
  await api.connect();

  let response = await api.getLedger({
    includeTransactions: true
  });
  console.log(response);

})(mainnet);
const mainnet = new ripple.RippleAPI({
  server: 'wss://s.altnet.rippletest.net/'
});

(async function(api) {
  await api.connect();

  let response = await api.getLedger({
      includeTransactions: true
    });
  console.log(response);

})(mainnet);
const mainnet = new ripple.RippleAPI({
  server: 'wss://s1.ripple.com'
});

(async function(api) {
  await api.connect();

  let response = await api.getLedger({
      includeTransactions: true
    });
  let tx_id = response.transactionHashes[0];
  let response2 = await api.getTransaction(tx_id);
  console.log(response2);

})(mainnet);
const mainnet = new ripple.RippleAPI({
  server: 'wss://s1.ripple.com'
});

(async function(api) {
  await api.connect();

  let response = await api.getLedger({
      includeTransactions: true
    });
  console.log('Total XRP: '+api.dropsToXrp(response.totalDrops));

})(mainnet);

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 a transaction using the getTransaction() method. For the id, use one of the transactionHashes from the getLedger() response! Answer >
  • Convert the totalDrops 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 RippleAPI for JavaScript (ripple-lib) in that page's HTML. For example:

<script src="https://unpkg.com/ripple-lib@1.10.0/build/ripple-latest-min.js"></script>

Further Reading

When you're ready to move on, continue using the XRP Ledger with these resources: