Realtime Tracking
Track VRF events in realtime using WebSocket subscriptions
Realtime Event Tracking
Get instant notifications when VRF results are ready using WebSocket subscriptions powered by RISE's shred architecture.
Overview
VRF results arrive via events emitted by your contract. RISE Chain's shred-based architecture delivers these events in realtime through WebSocket subscriptions, eliminating the need for polling and providing instant updates when randomness is ready.
Watching Events
For complete details on realtime event tracking with WebSockets and shred subscriptions, see the Watching Events guide. The same patterns apply to VRF events.
Quick Example
Here's how to watch for VRF completion events:
import { createPublicClient, webSocket } from 'viem';
import { riseTestnet } from 'viem/chains';
const client = createPublicClient({
chain: riseTestnet,
transport: webSocket('wss://testnet.riselabs.xyz/ws')
});
const vrfAbi = [
{
type: 'event',
name: 'DiceRollCompleted',
inputs: [
{ name: 'player', type: 'address', indexed: true },
{ name: 'requestId', type: 'uint256', indexed: true },
{ name: 'result', type: 'uint256' },
{ name: 'currentStreak', type: 'uint256' },
{ name: 'topStreak', type: 'uint256' }
]
}
] as const;
// Watch for VRF completion events
client.watchContractEvent({
abi: vrfAbi,
address: '0x...', // Your VRF consumer contract
eventName: 'DiceRollCompleted',
onLogs: (logs) => {
logs.forEach((log) => {
console.log('Random result:', log.args.result);
console.log('Streak:', log.args.currentStreak);
// Update your UI here
updateUI(log.args.result);
});
}
});Key Differences for VRF
When watching VRF events, you'll typically want to track:
- Request Events: Know when a randomness request is made
- Completion Events: Get notified instantly when VRF fulfills the request (usually 3-5ms)
- Request IDs: Match requests to their results
The event watching patterns are identical to those used for shreds. For advanced patterns like multi-contract monitoring, React hooks, reconnection handling, and more, refer to the Watching Events guide linked above.