diff --git a/packages/txm/lib/BlockMonitor.ts b/packages/txm/lib/BlockMonitor.ts index eccbe8f23a..15e0061d6e 100644 --- a/packages/txm/lib/BlockMonitor.ts +++ b/packages/txm/lib/BlockMonitor.ts @@ -20,6 +20,11 @@ export class BlockMonitor { this.txmgr.viemClient.watchBlocks({ onBlock: this.onNewBlock.bind(this), + ...(this.txmgr.transportProtocol === "http" + ? { + pollingInterval: this.txmgr.pollingInterval, + } + : {}), }) } diff --git a/packages/txm/lib/TransactionManager.ts b/packages/txm/lib/TransactionManager.ts index 1f70d69adb..9ebb39cfca 100644 --- a/packages/txm/lib/TransactionManager.ts +++ b/packages/txm/lib/TransactionManager.ts @@ -63,6 +63,12 @@ export type TransactionManagerConfig = { * Defaults to false. */ allowDebug?: boolean + + /** + * Specifies the polling interval in milliseconds. + * Defaults to 1/2 of the block time. + */ + pollingInterval?: number } /** The private key of the account used for signing transactions. */ privateKey: Hex @@ -159,6 +165,8 @@ export class TransactionManager { public readonly rpcAllowDebug: boolean public readonly blockTime: bigint public readonly finalizedTransactionPurgeTime: number + public readonly pollingInterval: number + public readonly transportProtocol: "http" | "websocket" public started: boolean @@ -171,12 +179,14 @@ export class TransactionManager { throw protocol.error } + this.transportProtocol = protocol.value + const retries = _config.rpc.retries || 2 const retryDelay = _config.rpc.retryDelay || 50 const timeout = _config.rpc.timeout || 500 let transport: ViemTransport - if (protocol.value === "http") { + if (this.transportProtocol === "http") { transport = viemHttpTransport(_config.rpc.url, { timeout, retryCount: retries, @@ -250,6 +260,8 @@ export class TransactionManager { this.blockTime = _config.blockTime || 2n this.finalizedTransactionPurgeTime = _config.finalizedTransactionPurgeTime || 2 * 60 * 1000 + this.pollingInterval = _config.rpc.pollingInterval || (Number(this.blockTime) * 1000) / 2 + this.started = false }