Polls the Soroban RPC for contract events and dispatches them to registered handlers.
All polling happens in a setInterval loop. Call destroy() to stop it and release all listeners.
setInterval
destroy()
const sub = new EventSubscriber({ contractId: 'C...', rpcUrl: 'https://soroban-testnet.stellar.org', pollingIntervalMs: 3000,});const unsub = sub.on('CAddressFunded', (evt) => { console.log('Funded', evt.target, 'amount', evt.amount);});// Later…unsub(); // stop this specific listenersub.destroy(); // stop polling entirely Copy
const sub = new EventSubscriber({ contractId: 'C...', rpcUrl: 'https://soroban-testnet.stellar.org', pollingIntervalMs: 3000,});const unsub = sub.on('CAddressFunded', (evt) => { console.log('Funded', evt.target, 'amount', evt.amount);});// Later…unsub(); // stop this specific listenersub.destroy(); // stop polling entirely
Tear down the subscriber: stop the polling loop and remove all listeners. After calling destroy() this instance cannot be reused.
Total number of registered callbacks across all event names.
Remove all listeners for a specific event name.
Register a listener for a specific event name or '*' for all events.
'*'
Starts the polling loop on the first call.
An unsubscribe function — call it to remove this listener.
Manually trigger a single poll. Useful in tests or for on-demand refresh.
Polls the Soroban RPC for contract events and dispatches them to registered handlers.
All polling happens in a
setIntervalloop. Calldestroy()to stop it and release all listeners.Example