// 2. Use in application logic async function getLatestBlock() try const blockNumber = await w3dr.request('eth_blockNumber', []); console.log(`Current Block: $parseInt(blockNumber, 16)`); return blockNumber; catch (err) console.error("Critical failure: All RPCs down", err);
/** * The main method to send RPC requests. */ public async request(method: string, params: any[]): Promise<any> const payload = jsonrpc: "2.0", id: Date.now(), method, params ;
/** * Strategy: Try fastest, if it fails, try next. * Best for write transactions (nonce management) or saving bandwidth. */ private async failoverStrategy(payload: any): Promise<any> // Iterate through sorted providers for (const provider of this.providers) if (!provider.isHealthy) continue;
Here is how a developer would integrate w3dr into their dApp.