XRP Ledger Snap
  • 🦊Welcome
  • πŸš€Getting Started
    • Quick start
    • Manual installation
  • ℹ️Basics
    • How it works
    • Usage guide
    • Backup your account
    • Importing your account into multiple wallets
      • Import your account into Xaman Wallet
      • Importing your account into Crossmark
    • πŸ”Security
  • πŸ–₯️DEVELOPMENT
    • Getting started
    • API Reference
    • Interaction with the XRP Ledger
  • πŸ“žSUPPORT
Powered by GitBook
On this page
  • Getting account information
  • Getting Account Balance
  • Getting the available balance
  • Converting drops to XRP
  • Submitting Transactions
  • Making a Payment
  • Creating a Trustline
  • Sending a Token
  • More examples
Export as PDF
  1. DEVELOPMENT

Interaction with the XRP Ledger

PreviousAPI ReferenceNextSUPPORT

Last updated 8 months ago

This section will guide you through interacting with the XRP Ledger using the XRP Ledger Snap. You'll learn how to request account balances, submit transactions, make payments, create trustlines, and send tokens.

Before using the XRP Ledger Snap you must read first the official documentation of the XRPL.


Getting account information

Getting Account Balance

To retrieve the balance of an XRP Ledger account, you can use the following method:

const res = await provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_request',
      params: {
        command: 'account_info',
        account: 'rYourXRPAccountHere',
      },
    },
  },
})
console.log(res.account_data.Balance);
console.log(res.account_data.OwnerCount);

In the XRP Ledger you need 10 XRP to active your account.

The Balance will be returned in drops

Getting the available balance

The balance you get from the response is not the available balance that the account has to spend.

Each account has a reserve:

  • Base reserve: 10 XRP

  • Owner reserve: 2 XRP per item

So to get the available balance in drops:

To learn more visit:

Converting drops to XRP

A drop is the minimum amount valid in the XRP Ledger, each drop is equal to 0.000001 XRP.

You can easily convert drops to xrp with xrpl.js.


Submitting Transactions

Making a Payment

To send XRP from one account to another, you can submit a payment transaction:

provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_signAndSubmit',
      params: {
        TransactionType: 'Payment',
        Account: 'rYourXRPAccountHere', // The Snap's XRP account
        Destination: 'rRecipientXRPAccountHere',
        Amount: '1000000', // 1 XRP in drops
      },
    },
  },
})

This transaction sends 1 XRP from your account to the specified destination account.

Creating a Trustline

A trustline is required to hold tokens issued by other accounts on the XRP Ledger. Here’s how to create a trustline:

provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_signAndSubmit',
      params: {
        TransactionType: 'TrustSet',
        Account: 'rYourXRPAccountHere',
        LimitAmount: {
          currency: 'TOKEN', // Add the currency of the Token fe. USD
          issuer: 'rIssuerAccountHere',
          value: '1000', // Maximum amount of the token you can hold
        },
      },
    },
  },
})

This transaction establishes a trustline allowing your account to hold up to 1000 units of a specified token issued by another account.

Sending a Token

Once a trustline is established, you can send tokens to another account as follows:

provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_signAndSubmit',
      params: {
        TransactionType: 'Payment',
        Account: 'rYourXRPAccountHere',
        Destination: 'rRecipientXRPAccountHere',
        Amount: {
          currency: 'TOKEN',
          value: '10', // Number of tokens to send
          issuer: 'rIssuerAccountHere',
        },
      },
    },
  },
})

This transaction sends 10 units of the specified token from your account to the recipient's account.

To learn more about the tokens in the XRP Ledger visit:


More examples

If you need more examples about all the transactions that you can submit and how to do it visit:

available=Max(0,Balanceβˆ’10βˆ—106βˆ’2βˆ—106βˆ—OwnerCount)available = Max(0, Balance - 10*10^6-2*10^6*OwnerCount) available=Max(0,Balanceβˆ’10βˆ—106βˆ’2βˆ—106βˆ—OwnerCount)
πŸ–₯️
Home | XRPL.org
Reserves
Logo
Currency Formats
Logo
Tokens
Logo
xrpl-dev-portal/_code-samples at master Β· XRPLF/xrpl-dev-portalGitHub
Logo
Logo