or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

accounts.mdclients.mdcore.mdindex.mdledger.mdmodels.mdtransactions.mdutils.mdwallets.md

accounts.mddocs/

0

# Account Management

1

2

Query account information, balances, transaction history, and verify account existence on the XRPL ledger. These functions provide essential account-related operations for building XRPL applications.

3

4

## Capabilities

5

6

### Account Existence and Information

7

8

Check if accounts exist on the ledger and retrieve basic account information.

9

10

```python { .api }

11

from xrpl import account

12

13

def does_account_exist(address: str, client, ledger_index: str = "validated") -> bool:

14

"""

15

Check if an account exists on the XRPL ledger.

16

17

Args:

18

address: The XRPL address to check

19

client: XRPL client for network communication

20

ledger_index: Ledger version to query ("validated", "current", or ledger sequence)

21

22

Returns:

23

True if account exists, False otherwise

24

"""

25

26

def get_account_root(address: str, client, ledger_index: str = "validated") -> dict[str, Union[int, str]]:

27

"""

28

Retrieve the AccountRoot ledger object for an address.

29

30

Args:

31

address: The XRPL address to query

32

client: XRPL client for network communication

33

ledger_index: Ledger version to query

34

35

Returns:

36

AccountRoot object containing account data including:

37

- Account: The account address

38

- Balance: Account balance in drops

39

- Sequence: Next transaction sequence number

40

- Flags: Account flags and settings

41

- OwnerCount: Number of objects owned by account

42

- PreviousTxnID: Hash of previous transaction

43

- PreviousTxnLgrSeq: Ledger sequence of previous transaction

44

"""

45

```

46

47

### Account Balance Operations

48

49

Query account balances and retrieve balance information.

50

51

```python { .api }

52

def get_balance(address: str, client, ledger_index: str = "validated") -> int:

53

"""

54

Get the XRP balance of an account in drops.

55

56

Args:

57

address: The XRPL address to query

58

client: XRPL client for network communication

59

ledger_index: Ledger version to query

60

61

Returns:

62

Account balance in drops (1 XRP = 1,000,000 drops)

63

64

Raises:

65

XRPLException: If account does not exist or query fails

66

"""

67

```

68

69

### Transaction Sequence Management

70

71

Manage transaction sequence numbers for reliable transaction submission.

72

73

```python { .api }

74

def get_next_valid_seq_number(address: str, client, ledger_index: str = "current") -> int:

75

"""

76

Get the next valid sequence number for submitting transactions.

77

78

Args:

79

address: The XRPL address to query

80

client: XRPL client for network communication

81

ledger_index: Ledger version to query (typically "current" for latest)

82

83

Returns:

84

Next sequence number to use for transactions

85

86

Raises:

87

XRPLException: If account does not exist or query fails

88

"""

89

```

90

91

### Transaction History

92

93

Retrieve transaction history and latest transaction information.

94

95

```python { .api }

96

def get_latest_transaction(address: str, client, ledger_index: str = "validated"):

97

"""

98

Get the most recent transaction for an account.

99

100

Args:

101

address: The XRPL address to query

102

client: XRPL client for network communication

103

ledger_index: Ledger version to query

104

105

Returns:

106

Transaction object of the most recent transaction, or None if no transactions

107

"""

108

```

109

110

## Usage Examples

111

112

### Basic Account Information

113

114

```python

115

from xrpl.clients import JsonRpcClient

116

from xrpl import account

117

118

# Connect to XRPL testnet

119

client = JsonRpcClient("https://s.altnet.rippletest.net:51234")

120

121

# Check if account exists

122

address = "rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH"

123

exists = account.does_account_exist(address, client)

124

print(f"Account exists: {exists}")

125

126

if exists:

127

# Get account balance

128

balance = account.get_balance(address, client)

129

print(f"Balance: {balance} drops ({balance / 1_000_000} XRP)")

130

131

# Get full account information

132

account_root = account.get_account_root(address, client)

133

print(f"Account data: {account_root}")

134

135

# Get next sequence number for transactions

136

next_seq = account.get_next_valid_seq_number(address, client)

137

print(f"Next sequence number: {next_seq}")

138

```

139

140

### Account Setup Verification

141

142

```python

143

from xrpl.clients import JsonRpcClient

144

from xrpl import account

145

146

def verify_account_setup(address: str, client) -> dict:

147

"""Verify account is properly set up and get key information."""

148

149

if not account.does_account_exist(address, client):

150

return {

151

"exists": False,

152

"error": "Account does not exist on the ledger"

153

}

154

155

try:

156

balance = account.get_balance(address, client)

157

account_root = account.get_account_root(address, client)

158

next_seq = account.get_next_valid_seq_number(address, client)

159

160

return {

161

"exists": True,

162

"balance_drops": balance,

163

"balance_xrp": balance / 1_000_000,

164

"sequence": account_root.get("Sequence", 0),

165

"next_sequence": next_seq,

166

"owner_count": account_root.get("OwnerCount", 0),

167

"flags": account_root.get("Flags", 0),

168

"account_data": account_root

169

}

170

171

except Exception as e:

172

return {

173

"exists": True,

174

"error": f"Failed to retrieve account information: {str(e)}"

175

}

176

177

# Usage

178

client = JsonRpcClient("https://s.altnet.rippletest.net:51234")

179

account_info = verify_account_setup("rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH", client)

180

print(account_info)

181

```

182

183

### Monitoring Account Changes

184

185

```python

186

from xrpl.clients import JsonRpcClient

187

from xrpl import account

188

import time

189

190

def monitor_account_balance(address: str, client, interval: int = 10):

191

"""Monitor account balance changes over time."""

192

193

print(f"Monitoring balance for {address}")

194

previous_balance = None

195

196

while True:

197

try:

198

current_balance = account.get_balance(address, client)

199

200

if previous_balance is not None and current_balance != previous_balance:

201

change = current_balance - previous_balance

202

print(f"Balance changed: {change:+} drops (new balance: {current_balance} drops)")

203

else:

204

print(f"Current balance: {current_balance} drops ({current_balance / 1_000_000:.6f} XRP)")

205

206

previous_balance = current_balance

207

time.sleep(interval)

208

209

except KeyboardInterrupt:

210

print("Monitoring stopped")

211

break

212

except Exception as e:

213

print(f"Error monitoring account: {e}")

214

time.sleep(interval)

215

216

# Usage

217

client = JsonRpcClient("https://s.altnet.rippletest.net:51234")

218

monitor_account_balance("rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH", client)

219

```

220

221

### Asynchronous Account Operations

222

223

```python

224

import asyncio

225

from xrpl.asyncio.clients import AsyncJsonRpcClient

226

from xrpl.asyncio import account

227

228

async def get_account_info_async(address: str, client):

229

"""Get account information asynchronously."""

230

231

exists = await account.does_account_exist(address, client)

232

if not exists:

233

return {"exists": False}

234

235

# Run multiple queries concurrently

236

balance_task = account.get_balance(address, client)

237

account_root_task = account.get_account_root(address, client)

238

next_seq_task = account.get_next_valid_seq_number(address, client)

239

240

balance, account_root, next_seq = await asyncio.gather(

241

balance_task, account_root_task, next_seq_task

242

)

243

244

return {

245

"exists": True,

246

"balance": balance,

247

"account_root": account_root,

248

"next_sequence": next_seq

249

}

250

251

async def main():

252

client = AsyncJsonRpcClient("https://s.altnet.rippletest.net:51234")

253

254

try:

255

account_info = await get_account_info_async("rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH", client)

256

print(account_info)

257

finally:

258

await client.close()

259

260

# Run async example

261

asyncio.run(main())

262

```