Getting Started

The Hydrex SDK is a TypeScript library for interacting with the Hydrex concentrated-liquidity AMM on Base. It handles pool math, route finding, calldata encoding, and contract interactions.


1

Installation

Install the SDK via npm or yarn. The package is published to the npm registry as @hydrexfi/hydrex-sdk.

bash
npm install @hydrexfi/hydrex-sdk
# or
yarn add @hydrexfi/hydrex-sdk
2

Supported Networks

The SDK supports Base mainnet and Base Sepolia testnet. Use the ChainId enum to reference the correct chain throughout your code.

NetworkChain IDStatus
Base8453Mainnet
Base Sepolia84532Testnet

ChainId enum

Use ChainId.Base and ChainId.BaseSepolia throughout the SDK instead of raw integers to keep your code type-safe and readable.
3

Quick Start

The example below demonstrates the core flow: define tokens, build a route, create a trade, and encode calldata to send to the swap router.

typescript
import {
  Token,
  Pool,
  Route,
  Trade,
  TradeType,
  SwapRouter,
  NonfungiblePositionManager,
  ChainId,
  WNATIVE,
  Percent,
  CurrencyAmount,
} from '@hydrexfi/hydrex-sdk';

// 1. Define tokens
const USDC = new Token(
  ChainId.Base,
  '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
  6,
  'USDC',
  'USD Coin'
);
const WETH = WNATIVE[ChainId.Base];

// 2. Build a route and trade
const route = new Route([pool], USDC, WETH);
const trade = Trade.createUncheckedTrade({
  route,
  inputAmount: CurrencyAmount.fromRawAmount(USDC, '1000000'), // 1 USDC
  outputAmount: CurrencyAmount.fromRawAmount(WETH, estimatedOutput),
  tradeType: TradeType.EXACT_INPUT,
});

// 3. Get calldata
const { calldata, value } = SwapRouter.swapCallParameters(trade, {
  slippageTolerance: new Percent(50, 10_000), // 0.5%
  recipient: '0xYourWallet',
  deadline: Math.floor(Date.now() / 1000) + 1200,
});

// 4. Send to SWAP_ROUTER_ADDRESSES[ChainId.Base]
4

Injected Contract Reads

The SDK uses an injected read pattern — you provide a ReadContractFunction bound to any web3 library. This works with viem, ethers, wagmi, or any custom client.

typescript
import { createPublicClient, http } from 'viem';
import { base } from 'viem/chains';
import type { ReadContractFunction } from '@hydrexfi/hydrex-sdk';

const client = createPublicClient({ chain: base, transport: http() });

const readContract: ReadContractFunction = ({ functionName, args }) =>
  client.readContract({ address: contractAddress, abi, functionName, args });

Why injected reads?

This pattern keeps the SDK library-agnostic. Your application controls the RPC connection, caching, and batching strategy — the SDK just describes what to call.

Next Steps

Hydrex

Hydrex is an Omni-Liquidity MetaDEX built on Base for Base, designed to bring new users onchain.

Paragraph

© 2026 Hydrex. All rights reserved.