コンテンツへスキップ
最終更新:

Calculate Account Reserves

This tutorial demonstrates how to look up and calculate the reserve requirements for an XRP Ledger account. Reserves are the minimum amount of XRP an account must hold based on its activity on the ledger.

Goals

By the end of this tutorial, you should be able to:

  • Look up an account's current base and incremental reserve values.
  • Determine an account's owner reserve.
  • Calculate an account's total reserve requirement.

Prerequisites

To complete this tutorial, you need:

  • A basic understanding of the XRP Ledger.
  • An XRP Ledger client library set up.

Source Code

You can find this tutorial's example source code in the code samples section of this website's repository.

Steps

1. Install dependencies

Install dependencies for your language from the code sample folder.

npm install xrpl

2. Set up client

Import the XRPL library and create a client connection.

// Set up client ----------------------

import xrpl from 'xrpl'

const client = new xrpl.Client('wss://xrplcluster.com')
await client.connect()

3. Look up reserve values

Retrieve the base and incremental reserve values using the server_info or server_state method. This example uses server_state to return reserve values as integer drops, avoiding floating-point precision issues.

// Look up reserve values ----------------------

const serverState = await client.request({ command: 'server_state' })
const validatedLedger = serverState.result.state.validated_ledger

const baseReserveDrops = validatedLedger.reserve_base
const reserveIncDrops = validatedLedger.reserve_inc

console.log(`Base reserve: ${xrpl.dropsToXrp(baseReserveDrops)} XRP`)
console.log(`Incremental reserve: ${xrpl.dropsToXrp(reserveIncDrops)} XRP`)

4. Look up owner count

Call account_info and take account_data.OwnerCount to retrieve an account's total number of objects.

// Look up owner count ----------------------

const address = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn' // replace with any address
const accountInfo = await client.request({ command: 'account_info', account: address })
const ownerCount = accountInfo.result.account_data.OwnerCount

5. Calculate total reserve

Once you have the owner count, you can calculate the account's total reserve. The total reserve is the base reserve plus the incremental reserve multiplied by the owner count.

// Calculate total reserve ----------------------

const totalReserveDrops = baseReserveDrops + (ownerCount * reserveIncDrops)
console.log(`Owner count: ${ownerCount}`)
console.log(`Total reserve: ${xrpl.dropsToXrp(totalReserveDrops)} XRP`)

await client.disconnect()

See Also

Concepts:

Tutorials:

References: