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

Create a new app.js file in the repository:

touch app.js

Open the file …


This content originally appeared on DEV Community and was authored by Marlon

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

Create a new app.js file in the repository:

touch app.js

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();

Now, run this code:

node app.js

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.


This content originally appeared on DEV Community and was authored by Marlon


Print Share Comment Cite Upload Translate Updates
APA

Marlon | Sciencx (2024-09-15T03:08:19+00:00) XRPL: Console log the ledger index. Retrieved from https://www.scien.cx/2024/09/15/xrpl-console-log-the-ledger-index/

MLA
" » XRPL: Console log the ledger index." Marlon | Sciencx - Sunday September 15, 2024, https://www.scien.cx/2024/09/15/xrpl-console-log-the-ledger-index/
HARVARD
Marlon | Sciencx Sunday September 15, 2024 » XRPL: Console log the ledger index., viewed ,<https://www.scien.cx/2024/09/15/xrpl-console-log-the-ledger-index/>
VANCOUVER
Marlon | Sciencx - » XRPL: Console log the ledger index. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/15/xrpl-console-log-the-ledger-index/
CHICAGO
" » XRPL: Console log the ledger index." Marlon | Sciencx - Accessed . https://www.scien.cx/2024/09/15/xrpl-console-log-the-ledger-index/
IEEE
" » XRPL: Console log the ledger index." Marlon | Sciencx [Online]. Available: https://www.scien.cx/2024/09/15/xrpl-console-log-the-ledger-index/. [Accessed: ]
rf:citation
» XRPL: Console log the ledger index | Marlon | Sciencx | https://www.scien.cx/2024/09/15/xrpl-console-log-the-ledger-index/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.