XRPL

The XRP Ledger is a decentralized cryptographic ledger powered by a network of peer-to-peer servers. It is fast, energy efficient, and reliable, with low transaction costs. XRP is the native cryptocurrency of the XRP Ledger, used to facilitate transactions on the network.

Core Concepts

  1. Accounts: XRPL Accounts

  2. Transactions: Transaction Basics

  3. Consensus: XRPL Consensus

  4. Fees: XRPL Fees

Setting up your wallet

To interact with the XRP Ledger, you need a wallet. You can use various wallet solutions, such as:

For development purposes, you can generate a test wallet using the XRPL Faucet.

Creating the SDK Instance

Import the SDK and create a new instance:

import { XRPL } from "@kynesyslabs/demosdk/xm-websdk"

const rpc_url = "wss://s.altnet.rippletest.net:51233"
const with_reconnect = false

const instance = new XRPL(rpc_url)

await instance.connect(with_reconnect)

The with_reconnect parameter is optional and defaults to true. It is used to specify whether the SDK should attempt to reconnect to the XRPL if the web socket connection is lost.

Connecting your wallet

To perform transactions, connect your wallet to the SDK:

await instance.connectWallet("sEd7rBGm5kxzauR...")

You can view the address of your connected wallet using the getAddress method:

const address = instance.getAddress()
console.log(`Address: ${address}`)

Getting balance

To get the balance of an account:

const balance = await instance.getBalance("rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe")
console.log(`Balance: ${balance} XRP`)

Token transfer

To create a transaction to transfer XRP, use the preparePay method:

const signedTx = await instance.preparePay(
    "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
    "10",
)

The signedTx object contains the signed transaction that can be used in a DEMOS transaction.

Multiple transfers

To prepare multiple transfers at once, use the preparePays method:

const transfers = [
    { address: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe", amount: "10" },
    { address: "rUCzEr6jrEyMpjhs4wSdQdz4g8Y382NxfM", amount: "20" },
]
const signedTxs = await instance.preparePays(transfers)

Signing Messages

const message = "Hello, world!"

// Signing
const signature = await instance.signMessage(message)

// Verifying signature
const verified = await instance.verifyMessage(
    message,
    signature,
    instance.wallet.publicKey,
)
expect(verified).toBe(true)

Advanced Usage

The DEMOS XRPL SDK is built on top of the XRPL JS Library, and provides a limited set of methods to interact with the XRP Ledger.

For more advanced use cases, you can access the underlying API to have more control over the transactions and interactions with the blockchain.

Here is a list of the objects you can access:

Method
Description

instance.provider

The Client instance from the xrpl library

instance.wallet

The Wallet instance for the connected account

instance.signTransaction(s)

Sign one or multiple transactions

xrplGetLastSequence

Get the last sequence number for an address

API Reference

https://kynesyslabs.github.io/demosdk-api-ref/classes/xmwebsdk.XRPL.html

Resources

Last updated