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.
Installation
Install the SDK via npm or yarn. The package is published to the npm registry as @hydrexfi/hydrex-sdk.
npm install @hydrexfi/hydrex-sdk
# or
yarn add @hydrexfi/hydrex-sdkSupported Networks
The SDK supports Base mainnet and Base Sepolia testnet. Use the ChainId enum to reference the correct chain throughout your code.
| Network | Chain ID | Status |
|---|---|---|
| Base | 8453 | Mainnet |
| Base Sepolia | 84532 | Testnet |
ChainId enum
ChainId.Base and ChainId.BaseSepolia throughout the SDK instead of raw integers to keep your code type-safe and readable.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.
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]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.
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?