Subscription using eth_subscribe (coming later - HIP-694)
For production environments, it's highly recommended to use a paid Mirror Node provider for commercial and high-traffic purposes. While Hedera's public mirror node offers free REST API and JSON API endpoints, they have global rate limits. These are best suited for development or low rate usage scenarios.
Polling Sync Events for all Pools
⛽ No gas cost
Whenever the reserve values for a pool contract are updated, either due to liquidity changes or a swap, a Sync event is emitted from the contract, containing the updated reserve values for the token pair. The following code demonstrates how to listen for Sync events for all pools using REST API or JSON RPC.
Listening to 'Sync' events without specifying an address in the filter data will return logs for all pools on SaucerSwap, as well as other DEXs on Hedera that share the same 'topic0' hash signature for the 'Sync' event. To identify and filter specific pools, extract the pool's EVM address from the log.
import*as ethers from'ethers'; //V6//load ABI data containing the Sync eventconstinterfaces=newethers.Interface(abi);let params =`timestamp=gte:${unixFrom}×tamp=lte:${unixTo}`; params +=`&topic0=${interfaces.getEvent('Sync')!.topicHash}`;consturl=`${config.mirrorNodeBaseUrl}/api/v1/contracts/results/logs?${params}`; constresponse=awaitaxios.get(url);constlogs=response.data.logs;for (constlogof logs) {const {reserve0,reserve1} =interfaces.decodeEventLog('Sync',log.data);console.log(`Pair: ${log.address}, reserve0: ${reserve0}, reserve1: ${reserve1}`);}
Polling Sync Events for a Pool
⛽ No gas cost
Whenever the reserve values for a pool contract are updated, either due to liquidity changes or a swap, a Sync event is emitted from the contract, containing the updated reserve values for the token pair. The following code demonstrates how to listen for Sync events for a specific pool using REST API or JSON RPC.