Get your own node endpoint todayStart for free and get your app to production levels immediately. No credit card required.You can sign up with your GitHub, X, Google, or Microsoft account.
- Query token prices from Uniswap V2-style pools on Monad
- Calculate prices from liquidity pool reserves
- Handle token decimals correctly
- Monitor price changes in real-time
- Both JavaScript and Python implementations
Prerequisites
- Chainstack account with a Monad node endpoint
- Node.js v16+ or Python 3.8+
- Basic understanding of AMM mechanics
Overview
Monad’s 1-second finality makes it ideal for DeFi applications where price accuracy matters:- Near real-time prices: Query prices that are at most 1 second old
- Reliable data: No reorganizations mean prices are immediately trustworthy
- High throughput: DEXs can handle high trading volume without congestion
Understanding AMM pricing
Uniswap V2 pools use the constant product formula:x= reserve of token Ay= reserve of token Bk= constant (product of reserves)
This is the “spot price” before any trade. Actual trade prices include slippage based on trade size relative to pool liquidity.
Key contract addresses
For this tutorial, you’ll need:| Contract | Address | Description |
|---|---|---|
| WMON | 0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701 | Wrapped MON |
Query Uniswap V2 pool prices
Uniswap V2 Pair ABI
The minimal ABI needed to query prices:JavaScript price fetcher
fetch-price.js
Python price fetcher
fetch_price.py
Monitor price changes
Build a real-time price monitor:JavaScript price monitor
monitor-price.js
Python price monitor
monitor_price.py
Calculate price impact
Estimate the price impact of a trade before executing:price-impact.js
Working with WMON
WMON (Wrapped MON) is essential for DEX trading since most pools pair tokens against WMON rather than native MON.Wrap MON to WMON
wrap-mon.js
Monad-specific notes
Why Monad excels for DEX price fetching:
- 1-second freshness: Prices are at most 1 second old, crucial for arbitrage and trading bots
- Immediate finality: No need to wait for confirmations. The price you see is the price you get.
- High throughput: DEXs can handle more trades per second, leading to more liquid markets
- No reorg risk: Price data is reliable immediately. No worrying about chain reorganizations invalidating trades.
Next steps
Now that you can fetch DEX prices on Monad, you can:- Build trading bots that react to price changes
- Create price aggregators across multiple DEXs
- Implement arbitrage detection systems
- Build portfolio tracking dashboards
- Create price alerts and notifications