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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.