TDD: Infrastructure — Security, State, Testing, Deployment
Documents security, state management, testing, and deployment decisions for an XRPL devnet dApp built with Next.js.
What this file does
Documents security, state management, testing, and deployment decisions for an XRPL devnet dApp built with Next.js.
When to use it
- Starting a new XRPL devnet project and need a security and error-handling template
- Designing state management for nested React contexts with dependency ordering
- Planning a manual end-to-end test flow for XRPL token operations
- Deploying a client-side XRPL app on Vercel without server secrets
Assumes this stack
TDD: Infrastructure — Security, State, Testing, Deployment
1. Security Considerations
Wallet Key Handling
- All wallets are devnet-only, ephemeral, generated in-browser via faucet
- No private keys stored in
.envor persisted to disk - Wallet objects (seed, privateKey, address) live only in React Context state
- Page refresh = wallets lost (by design for devnet demo)
Input Validation
validateAddress(address)— regex check for XRPL r-address formatvalidateAmount(amount)— positive finite numbervalidateTicker(ticker)— 1-10 uppercase alphanumericvalidateAssetScale(scale)— integer 0-15validateTransferFee(fee)— integer 0-50000validateMetadataSize(size)— ≤1024 bytes
XSS Prevention
- React's built-in JSX escaping handles output encoding
- No
dangerouslySetInnerHTMLused anywhere - All user inputs are typed (number fields, controlled inputs)
2. Error Handling
Error Classes
XRPLConnectionError— network connectivity failuresTransactionError— XRPL transaction result codes (tec*, tem*, tef*)ValidationError— input validation failures with optional field name
XRPL Error Code Mapping
Human-readable messages for common codes:
tecUNFUNDED→ "Account does not have enough XRP..."tecNO_AUTH→ "Holder is not authorized..."tecFROZEN→ "This token is currently frozen/locked..."tefPAST_SEQ→ "Transaction sequence is in the past..."temDISABLED→ "This feature is not enabled..."
Transaction Status Pattern
Every transaction goes through: idle → submitting → success | error
useTransaction()hook manages this lifecycleTransactionStatuscomponent renders appropriate feedbackexecute(fn, message)wraps any async tx function
3. State Management Architecture
XRPLProvider (connection + client)
└── WalletProvider (issuer, protocol, shareholders)
└── TokenProvider (mptIssuanceId, metadata, holders)
└── App pages
- Contexts are nested in dependency order
- Each context exports both Provider component and accessor hook
- Hooks throw if used outside their provider
4. Environment Configuration
.env.local
NEXT_PUBLIC_XRPL_WSS=wss://s.devnet.rippletest.net:51233
NEXT_PUBLIC_XRPL_FAUCET=https://faucet.devnet.rippletest.net/accounts
NEXT_PUBLIC_NETWORK=devnet
- All values are public (NEXT_PUBLIC_ prefix) — no secrets
- Constants in
src/lib/constants.tsfor code access
5. Testing Strategy
Manual Test Script (src/test/manual-test-flow.ts)
End-to-end flow on devnet:
- Connect to devnet
- Fund 3 wallets (issuer, protocol, shareholder)
- Create MPT issuance with all flags
- Authorize + send MPTs to protocol
- Create escrow → finish escrow
- Verify shareholder holds tokens
- Test lock/unlock
- Test clawback
- Test cashflow distribution
What to Test
- Flag dependency cascading (UI logic)
- Metadata size validation (≤1024 bytes)
- Transaction error handling (simulate failures)
- Wallet generation flow
- Multi-step transaction sequences (correct ordering)
6. Performance Considerations
- Singleton client — one WebSocket connection, reused across all operations
- Sequential distributions — avoid sequence number conflicts in batch payments
- Paginated queries —
getMPTHoldersuses marker-based pagination - No polling — holders/state refreshed on-demand (button click)
7. Deployment
- Vercel-ready — standard Next.js App Router project
- No server-side secrets needed
next.config.jshandles webpack fallbacks for xrpl.js Node.js dependencies- All XRPL operations run client-side (browser)
8. Devnet Considerations
- Devnet resets periodically — all accounts and tokens are wiped
- Faucet rate limits: ~10 requests/minute per IP
- All XLS-33 and XLS-85 amendments active on devnet
- Network latency: expect 3-5 second transaction confirmation times
- Custom IOU used instead of RLUSD (not available on devnet)
9. File Inventory
Context Providers (src/context/)
XRPLContext.tsx— client connection lifecycleWalletContext.tsx— wallet generation + storageTokenContext.tsx— current token stateAppProviders.tsx— nested provider wrapper
Hooks (src/hooks/)
useXRPL.ts— access XRPL client + statususeWallet.ts— access wallet state + generatorsuseToken.ts— access token state + settersuseTransaction.ts— transaction submission state machine
Utils (src/utils/)
errors.ts— error classes + XRPL error code mappingvalidation.ts— input validation helpersformat.ts— display formatting (XRP, addresses, timestamps)
What's inside
9 sections covering security, error handling, state architecture, environment config, testing, performance, deployment, devnet notes, and file inventory.
Change this for your project
- Replace
wss://s.devnet.rippletest.net:51233with your XRPL WebSocket endpoint - Replace
https://faucet.devnet.rippletest.net/accountswith your faucet URL - Replace
NEXT_PUBLIC_NETWORK=devnetwith your network name
Where it goes
Save in docs/ or the repository root. Gives agents and new contributors a map of the codebase.
Worth borrowing
- Transaction lifecycle state machine (idle → submitting → success | error) with a reusable hook
- Nested React contexts in dependency order, each exporting both provider and accessor hook
- Human-readable error code mapping for XRPL transaction result codes
Related Documents
PCB Design Sources for Industry-Scale Testing
Lists GitHub repos and communities where you can download real PCB designs for testing optimization at scale.
Design Document: BharatSeva AI
Describes a 10-agent AWS system that helps India's informal workers access government schemes via voice-first, serverless architecture.
OpenClaw Enterprise Transformation Plan
Transforms a single-user AI agent into a dual-mode platform supporting both viral open-source and Fortune 500 enterprise deployments through phased security, IAM, audit, multi-tenancy, and Kubernetes features.
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Documents the Qwen-Image and Qwen-Image-Edit models, covering architecture, training, benchmarks, ComfyUI setup, and prompting techniques for local GGUF deployment.