Pattern 1: Derive a bounded outcome in the callback
Use the deliveredrandomNumber to derive the game-specific result only after the callback arrives.
Pattern 2: Track requests per user or session
Map the returnedrequestId to the state you need for settlement.
requestRandomNumber returns.
Pattern 3: Keep callback checks at the top
Fail fast before you touch application logic.Pattern 4: Separate pending state from settled state
Model the request as pending until the callback succeeds. Your app and frontend can then render a clear in-progress state instead of assuming synchronous completion. This is especially useful when:- a player can create multiple requests over time
- you need to reconcile requests from emitted events
- you want to retry UI polling or indexing until the callback lands
Choosing a pattern
Simple game outcome
Use a single mapping from
requestId to a compact pending struct.Session-based app
Track both
requestId -> session and user -> latest requestId so your frontend can reconcile state quickly.Related pages
Integration pattern
Start from the minimal consumer before adding extra state.
Request lifecycle
Understand why pending state matters for asynchronous settlement.
Coordinator reference
Check the request interface and fee call while adapting these patterns.