Hints
Helpful Guidance for the GetAccountBalance Implementation
General Approach
If you're stuck, try this step-by-step approach:
Start small — Get a minimal handler working first
Add validation incrementally — One check at a time
Test frequently — Verify each addition works
Study existing handlers — Copy proven patterns
Use helper functions — Don't reinvent the wheel
Hint 1: File Structure
Your handler file should follow this structure:
// Copyright and license header
// Include necessary headers
// namespace ripple {
// Helper functions (if needed)
// Main handler function
// } // namespace rippleEssential includes:
<xrpld/rpc/Context.h>— For JsonContext<xrpld/rpc/detail/RPCHelpers.h>— For helper functions<xrpl/protocol/ErrorCodes.h>— For error codes<xrpl/protocol/jss.h>— For JSON field names
Hint 2: Handler Signature
Remember the standard signature:
Important: Function name should start with do followed by the command name in PascalCase.
Hint 3: Account Validation
Use the parseBase58 template function:
Hint 4: Ledger Lookup
The easiest way to get a ledger:
This helper automatically:
Parses
ledger_indexorledger_hashfrom paramsHandles "current", "validated", "closed"
Returns proper error if not found
Hint 5: Reading Account Data
Use the keylet system:
Hint 6: Extracting Field Values
Access account fields using type-safe getters:
Hint 7: Reserve Calculations
Get fee information from the ledger:
Hint 8: Building JSON Responses
Use the jss namespace for standard field names:
Hint 9: Converting Amounts to Strings
Use to_string() for all amount types:
Hint 10: Handler Registration
In Handlers.cpp, add this entry:
Why USER role? This is a read operation, so authenticated users should have access.
Why NEEDS_CURRENT_LEDGER? We need ledger access to query account state.
Hint 11: Error Handling Pattern
Follow this pattern for all validations:
Hint 12: Testing Setup
Your test file should start like this:
Hint 13: Common Pitfalls to Avoid
❌ Don't directly access params without checking existence first ✅ Do always check isMember() before accessing
❌ Don't assume ledger is always available ✅ Do use lookupLedger() and check the result
❌ Don't forget to dereference optional values ✅ Do use *account after parsing with parseBase58
❌ Don't return raw exception messages ✅ Do catch exceptions and return proper RPC errors
Hint 14: Debugging Tips
If your handler doesn't work:
Check compilation errors first
Missing includes?
Typos in function names?
Wrong namespace?
Add logging
Test with rippled command line
Check the handler table
Is your handler registered?
Is the command name correct (lowercase with underscores)?
Hint 15: Reference Code Locations
Look at these files for examples:
Account validation:
src/xrpld/rpc/handlers/AccountInfo.cpp:44-52
Ledger lookup:
src/xrpld/rpc/handlers/AccountInfo.cpp:54-60
Reserve calculation:
src/xrpld/rpc/handlers/AccountInfo.cpp:106-110
Response building:
src/xrpld/rpc/handlers/AccountInfo.cpp:112-145
Still Stuck?
If these hints aren't enough:
Compare with AccountInfo — Your handler is very similar
Check the test cases — They show expected behavior
Ask for help — Use the feedback form
Remember: The goal is to learn, not to finish quickly. Take your time!
Last updated

