# uniswap-v4 > Swap tokens and read pool state on Uniswap V4 (Base, Ethereum). Use when the agent needs to swap ERC20 tokens or ETH via Uniswap V4, get pool info (price, tick, liquidity, fees), find available pools for a token pair, set up Permit2 approvals for the Universal Router, or execute exact-input swaps. Supports Base and Ethereum mainnet. Requires `cast` (Foundry CLI) and Python 3. Write operations need a private key. - Author: Connie - Repository: consensus-hq/uniswap-v4-skill - Version: 20260208210024 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-09 - Source: https://github.com/consensus-hq/uniswap-v4-skill - Web: https://mule.run/skillshub/@@consensus-hq/uniswap-v4-skill~uniswap-v4:20260208210024 --- --- name: uniswap-v4 description: Swap tokens and read pool state on Uniswap V4 (Base, Ethereum). Use when the agent needs to swap ERC20 tokens or ETH via Uniswap V4, get pool info (price, tick, liquidity, fees), find available pools for a token pair, set up Permit2 approvals for the Universal Router, or execute exact-input swaps. Supports Base and Ethereum mainnet. Requires `cast` (Foundry CLI) and Python 3. Write operations need a private key. --- # Uniswap V4 Skill Swap tokens and read pool state on Uniswap V4 via Foundry's `cast` CLI and the Universal Router. ## Prerequisites - `cast` (Foundry CLI) in PATH — install: `curl -L https://foundry.paradigm.xyz | bash && foundryup` - Python 3.6+ - For swaps: a private key with token balance ## Commands ### Read Pool Info (free, no gas) ```bash SKILL_DIR="" $SKILL_DIR/scripts/pool-info.sh --token0 ETH --token1 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 --chain base ``` Returns JSON: pool ID, sqrtPriceX96, tick, liquidity, fees, token symbols/decimals. Specify `--fee` and `--tick-spacing` for a specific pool, or omit to auto-detect the best pool. ### Find All Pools for a Pair (free) ```bash $SKILL_DIR/scripts/quote.sh --token0 ETH --token1 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 --chain base ``` Returns all V4 pools for the pair across fee tiers (500, 3000, 10000, 100, dynamic). ### Set Up Token Approvals (write, ~100K gas) Before swapping ERC20 tokens (not needed for ETH): ```bash $SKILL_DIR/scripts/approve.sh --token 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 --chain base --private-key $PRIVATE_KEY ``` Sets up the two-step Permit2 flow: ERC20 → Permit2, then Permit2 → Universal Router. ### Execute Swap (write, ~300-350K gas) ```bash $SKILL_DIR/scripts/swap.sh \ --token-in ETH \ --token-out 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 \ --amount 10000000000000000 \ --slippage 50 \ --chain base \ --private-key $PRIVATE_KEY ``` Options: `--slippage ` (default 50 = 0.5%), `--recipient `, `--json`. ## Token Input - `ETH` or `eth` → native ETH (address(0) in V4) - Contract address → ERC20 token - Common Base tokens in `references/addresses.md` ## Supported Chains - **Base** (default) — PoolManager: `0x498581fF718922c3f8e6A244956aF099B2652b2b` - **Ethereum** — PoolManager: `0x000000000004444c5dc75cB358380D2e3dE08A90` ## V4 Architecture Notes - Singleton PoolManager holds all pools in one contract - State read via `extsload` (no public getters) - Swaps: Universal Router → PoolManager with V4_SWAP command - Approvals: ERC20 → Permit2 → Universal Router (two-step) - Pool ID: `keccak256(abi.encode(currency0, currency1, fee, tickSpacing, hooks))` - Currency ordering: `currency0 < currency1` by address. ETH = address(0) - See `references/v4-encoding.md` for full encoding reference