DEV Community

Marlon
Marlon

Posted on

XRPL: Console log the ledger index

Tools needed:

  • Node.js
  • NPM
  • VS Code

Create a new repository, initialize NPM, and install the XRPL.js package:

mkdir helloWorld
cd helloWorld
npm init
npm i xrpl
Enter fullscreen mode Exit fullscreen mode

Create a new app.js file in the repository:

touch app.js
Enter fullscreen mode Exit fullscreen mode

Open the file and paste this code into it:

// Pull the XRPL package into the file
const XRPL = require('xrpl');

// Create an async function to console log of the ledger index
const displayLastLedgerIndex = async () => {
  // Connect to the XRPL client via a desired network
  const client = new XRPL.Client('wss://xrplcluster.com');
  await client.connect();

  // Request XRPL client information
  const ledgerInfo = await client.request({
    command: 'ledger',
    ledger_index: 'validated',
  });

  // Console log the ledger index
  console.log(`Hello World, from the XRPL. The last index was: ${ledgerInfo.result.ledger_index}`);

  // Disconnect from the XRPL client
  await client.disconnect();
};

// Call the async function
displayLastLedgerIndex();
Enter fullscreen mode Exit fullscreen mode

Now, run this code:

node app.js
Enter fullscreen mode Exit fullscreen mode

There you have it! We've both made our step in interacting with the XRPL. Please like and share if you found this information valuable.

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

Sentry image

Make it make sense

Only the context you need to fix your broken code with Sentry.

Start debugging →

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay