DEX
Est. 2018 Decentralised (Uniswap Labs, NYC)

Uniswap

Uniswap is the largest decentralised exchange by cumulative trading volume — a permission-less AMM protocol on Ethereum and 10+ chains where anyone can swap tokens, provide liquidity, and now route orders through Uniswap X's intent-based system, with no accounts, no KYC, and no counterparty.

Uniswap is the protocol that proved permissionless token swapping could work at scale without order books, market makers, or accounts. Its Automated Market Maker model — where liquidity pools replace traditional order books and prices are determined algorithmically by the ratio of assets in the pool — has been forked and adapted by hundreds of DEXes across every major blockchain. But the original remains dominant: Uniswap V2 and V3 combined process $1–3 trillion in annual volume across Ethereum and its L2 deployments, making Uniswap a higher-volume trading venue than many traditional stock exchanges. For developers, traders, and liquidity providers, Uniswap is the foundational DeFi primitive — understanding how to interact with it programmatically is essential knowledge for anyone building in the crypto space.

Swapping Tokens on Uniswap

Uniswap's swap interface (app.uniswap.org) is the simplest entry point: connect a Web3 wallet (MetaMask, Coinbase Wallet, or any WalletConnect-compatible wallet), select the input and output tokens and amount, review the price impact and fees, and confirm the transaction. For any token pair with sufficient liquidity, the swap executes atomically: you send tokens in, you receive tokens out, in a single Ethereum transaction. Key parameters to understand: Slippage tolerance — the maximum price movement you'll accept between quote and execution (0.1–0.5% for stable pairs, 0.5–3% for volatile pairs). If price moves more than your slippage tolerance during the transaction, it reverts. Price impact — how much your trade moves the pool's price. Large trades relative to pool liquidity have high price impact; if impact exceeds 2–3%, consider splitting the trade across multiple transactions. Gas fees — Ethereum mainnet swaps cost $1–20 in gas depending on gas price and swap complexity; Uniswap on L2s (Arbitrum, Base, Optimism) cost $0.01–0.10 per swap.

Providing Liquidity on V3: Concentrated Ranges

Uniswap V3 liquidity provision requires selecting a price range for your capital. The narrower the range, the higher the fee earnings per dollar when the price is within range — but the more frequently you need to rebalance as price moves. The practical approach for passive LPs: use wide ranges (e.g., ±50% around current price) that rarely go out of range, accepting lower capital efficiency in exchange for lower management overhead. For active LPs or bots, narrow ranges (±1–5%) with automated rebalancing maximise fee income but require active management infrastructure. Position management tools (Arrakis Finance, Gamma Strategies, Ichi Vault) offer automated V3 range management, rebalancing positions when price drifts outside the set range.

Integrating with Uniswap Programmatically: SDK and Smart Contracts

Uniswap provides official SDKs and smart contracts for programmatic integration. There are two main approaches:

Option A — The Uniswap V3 SDK (TypeScript/JavaScript). Install: npm install @uniswap/v3-sdk @uniswap/sdk-core ethers. The SDK provides TypeScript classes for constructing swap routes, computing prices, and building transaction calldata. Basic swap workflow:
1. Create a Token object for each asset (chain ID, address, decimals, symbol).
2. Fetch the pool state (slot0, liquidity, ticks) from the V3 pool contract.
3. Create a Pool object with the fetched state.
4. Use Trade.bestTradeExactIn() or Route to compute the optimal path.
5. Use SwapRouter.swapCallParameters() to get the encoded calldata.
6. Sign and broadcast the transaction with your ethers.js or viem signer. The SDK abstracts the on-chain math and ABI encoding, making it the recommended approach for new integrators.

Option B — Direct Smart Contract Interaction (Python with web3.py or ethers). Uniswap V3 core contracts:

  • SwapRouter02 (0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45 on Ethereum mainnet) — the primary entry point for swaps.
  • Quoter V2 (0x61fFE014bA17989E743c5F6cB21bF9697530B21e) — call quoteExactInputSingle() off-chain to get the expected output amount before executing.
  • Factory (0x1F98431c8aD98523631AE4a59f267346ea31F984) — get pool addresses by calling getPool(token0, token1, fee).
In Python with web3.py:
from web3 import Web3; w3 = Web3(Web3.HTTPProvider(RPC_URL))
Load the SwapRouter ABI, create the contract object, call exactInputSingle() with the swap parameters (tokenIn, tokenOut, fee, recipient, amountIn, amountOutMinimum, sqrtPriceLimitX96) as a signed transaction.
Set amountOutMinimum using the Quoter result minus your slippage tolerance to protect against sandwich attacks.

MEV protection tip: Uniswap V3 swaps on Ethereum mainnet are vulnerable to sandwich attacks if broadcast to the public mempool. Use private RPC endpoints (Flashbots Protect, MEV Blocker) to route transactions directly to validators without mempool exposure. On L2s (Arbitrum, Base), sandwich MEV is significantly reduced due to the centralised sequencer model.

Uniswap X: Intent-Based Swapping

Uniswap X is an intent-based swap protocol where users sign an off-chain "order" (swap intent with parameters: input token/amount, minimum output, deadline) instead of submitting a transaction. Off-chain "fillers" (MEV searchers, market makers) compete to fill the order at the best price across all liquidity sources. The filler submits the on-chain transaction, paying gas themselves and earning the spread. Benefits for traders: gas costs are often covered by fillers; sandwich MEV is eliminated (fillers compete for the spread, not against you); best-execution across all Uniswap pools and external liquidity sources. Uniswap X is accessible via the Uniswap interface automatically or through the @uniswap/uniswapx-sdk npm package for programmatic order submission.

Who Uniswap Is Best For

Uniswap suits: anyone swapping tokens on Ethereum or its major L2s who wants the deepest liquidity and lowest slippage; DeFi developers building applications that need on-chain token exchange (Uniswap is the most widely integrated DEX in smart contract composability); liquidity providers seeking fee income from the most liquid markets; and bots performing arbitrage between Uniswap and centralised exchanges. Uniswap is not suited for: large off-chain institutional trades (CEX OTC desks offer better pricing for $1M+ trades); cross-chain swaps (use cross-chain bridge/DEX aggregators); or users requiring fiat on/off ramps.

Uniswap V4 Hooks

Uniswap V4 introduces hooks — developer-defined smart contracts that execute code at specific points in the swap lifecycle (before/after swaps, before/after liquidity changes). Hooks enable customizable pool behavior without forking Uniswap's core contracts: a hook can implement dynamic fee tiers, TWAMM (time-weighted average market maker for large order execution), automatic compounding of fees back into the liquidity position, or KYC gating for compliant pool access. This hooks architecture transforms Uniswap V4 from a fixed-function AMM into a programmable swap infrastructure layer that can host virtually any AMM design variation.

Uniswap V4's singleton contract model (all pools in one contract) dramatically reduces gas costs for multi-hop swaps and flash loans compared to V3's factory-per-pool architecture. The singleton also enables flash accounting — assets are netted across an entire transaction rather than settled at each hop — making complex multi-pool strategies dramatically cheaper. Uniswap continues to dominate Ethereum DEX volume; competing DEXs include Curve Finance for stablecoin swaps, Balancer for multi-token pools, and SushiSwap for multi-chain trading. Use our crypto tools and DennTech blog for Uniswap ecosystem updates.