<aside> šŸ“œ TABLE OF CONTENTS

1. šŸ“˜ Introduction to XRP Ledger

2. šŸ”‘ XRP Ledger Basics

3. šŸ’» Interacting with XRP Ledger

4. šŸ—ļø Building dApps on XRPL with React

5. šŸ”— EVM Sidechain Integration for XRPL

6. šŸ› ļø Non-EVM Development

7. šŸ“š Resources and References

</aside>

http://quiz.xrplsea.org

Development Environment Setup (Node.js Focus) šŸ› ļø

Setting Up Your Development Environment šŸ’»


To begin developing on the XRP Ledger (XRPL) using Node.js, you'll need to set up your environment. Start by installing Node.js from nodejs.org. Once installed, verify your installation by opening a terminal and running:

node --version
npm --version

These commands should display the versions of Node.js and npm installed on your system.

Next, create a new directory for your XRPL project and initialize it with npm:

mkdir xrpl-project
cd xrpl-project
npm init -y

Now, install the xrpl library, which provides tools for interacting with the XRP Ledger:

npm install xrpl

šŸ’” Tip: Consider using a version control system like Git to track changes in your project. Initialize a Git repository with git init in your project directory.

Creating a Testnet Account šŸ”‘


To experiment with the XRPL without using real funds, you'll need a testnet account. Here's a script to create one using the xrpl library:

const xrpl = require("xrpl")

async function createTestnetAccount() {
  const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233")
  await client.connect()

  try {
    const fund_result = await client.fundWallet()
    const test_wallet = fund_result.wallet

    console.log("šŸŽ‰ New account created!")
    console.log("šŸ“ Address:", test_wallet.address)
    console.log("šŸ” Secret:", test_wallet.seed)
    console.log("šŸ’° Balance:", xrpl.dropsToXrp(fund_result.balance), "XRP")
  } catch (err) {
    console.error("Error creating account:", err)
  } finally {
    await client.disconnect()
  }
}

createTestnetAccount()

Save this as create_account.js and run it with node create_account.js. This script connects to the XRPL Testnet, creates a new account, funds it with test XRP, and displays the account details.

āš ļø Important: Never use testnet accounts or secrets for real transactions. They are for testing only!

Exploring the XRPL with Websocket API šŸ”


The XRPL provides a powerful JSON-RPC API for interacting with the ledger. Here's an example of how to use it to retrieve account information:

const WebSocket = require('ws')

function getAccountInfo(address) {
  return new Promise((resolve, reject) => {
    const ws = new WebSocket('wss://s1.ripple.com')

    ws.on('open', function open() {
      const request = {
        command: 'account_info',
        account: address,
        strict: true,
        ledger_index: 'current',
        queue: true
      }

      ws.send(JSON.stringify(request))
    })

    ws.on('message', function incoming(data) {
      const response = JSON.parse(data)
      ws.close()
      resolve(response)
    })

    ws.on('error', function error(err) {
      reject(err)
    })
  })
}

async function displayAccountInfo(address) {
  try {
    const info = await getAccountInfo(address)
    console.log('šŸ“Š Account Info:', JSON.stringify(info.result, null, 2))
  } catch (err) {
    console.error('āŒ Error fetching account info:', err)
  }
}

// Example usage
displayAccountInfo('rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn')

This script establishes a WebSocket connection to a public XRPL node and requests information about a specific account. It demonstrates the basic structure of an API call, including specifying the command and parameters.

šŸ” Explore Further: Try modifying this script to use different API methods like tx to retrieve transaction information or ledger to get ledger data.

Putting It All Together: A Simple XRPL App šŸš€


Let's create a simple application that combines account creation and information retrieval:

const xrpl = require("xrpl")
const WebSocket = require('ws')

async function createAndExploreAccount() {
  const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233")
  await client.connect()

  try {
    // Create account
    const fund_result = await client.fundWallet()
    const test_wallet = fund_result.wallet

    console.log("šŸŽ‰ New account created!")
    console.log("šŸ“ Address:", test_wallet.address)
    console.log("šŸ” Secret:", test_wallet.seed)
    console.log("šŸ’° Initial Balance:", xrpl.dropsToXrp(fund_result.balance), "XRP")

    // Fetch account info
    const accountInfo = await client.request({
      command: "account_info",
      account: test_wallet.address,
      ledger_index: "validated"
    })

    console.log("\\\\nšŸ“Š Account Info:")
    console.log(JSON.stringify(accountInfo.result, null, 2))

  } catch (err) {
    console.error("āŒ Error:", err)
  } finally {
    await client.disconnect()
  }
}

createAndExploreAccount()

This script creates a new testnet account and then immediately fetches and displays its information using the XRPL API.

šŸŒŸ Next Steps: Try expanding this application to perform other actions like sending test transactions or creating trust lines.

By mastering these basics, you'll be well-equipped to start building more complex applications on the XRP Ledger. Remember to always refer to the official XRPL documentation for the most up-to-date information and best practices.