Comprehensive JavaScript SDK for building Solana blockchain applications with modern architecture and type safety
93
Evaluation — 93%
↑ 1.29xAgent success when using this tile
Build a real-time account balance monitor that tracks changes to a Solana account's balance and maintains a history of balance updates.
Implement a monitoring service with the following capabilities:
Subscribe to Account Updates: Connect to a Solana cluster and subscribe to real-time updates for a specified account address.
Track Balance Changes: When the account is updated, extract the current lamport balance and store it along with a timestamp.
Maintain Update History: Keep a record of all balance updates received, including:
Query Latest Balance: Provide a method to retrieve the most recent balance.
Query Balance History: Provide a method to retrieve the complete history of balance updates.
Graceful Shutdown: Properly clean up the subscription when monitoring is stopped.
wss://api.devnet.solana.comThe monitor successfully subscribes to account updates and receives notifications when the account balance changes. @test
The monitor maintains an accurate history of balance updates with timestamps and slot numbers. @test
The monitor provides the correct latest balance after receiving multiple updates. @test
Provides WebSocket subscription capabilities for real-time Solana blockchain data.
@generates
/**
* Represents a single balance update event
*/
export interface BalanceUpdate {
/** Balance in lamports */
lamports: bigint;
/** Timestamp when the update was received */
timestamp: number;
/** Slot number of the update */
slot: bigint;
}
/**
* Account balance monitor that tracks real-time changes
*/
export class AccountBalanceMonitor {
/**
* Create a new account balance monitor
* @param rpcUrl - WebSocket RPC endpoint URL
* @param accountAddress - The account address to monitor (as a string)
*/
constructor(rpcUrl: string, accountAddress: string);
/**
* Start monitoring the account for balance changes
* This method subscribes to account notifications and begins collecting updates
*/
start(): Promise<void>;
/**
* Stop monitoring and clean up the subscription
*/
stop(): Promise<void>;
/**
* Get the most recent balance
* @returns The latest balance in lamports, or null if no updates have been received
*/
getLatestBalance(): bigint | null;
/**
* Get the complete history of balance updates
* @returns Array of balance updates in chronological order
*/
getBalanceHistory(): BalanceUpdate[];
}Install with Tessl CLI
npx tessl i tessl/npm-solana--web3-jsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10