Skip to content

Universal Router SDK

Build transaction calldata for the PancakeSwap Universal Router. Encodes multi-step swap commands across V2, V3, and Infinity pools — including Permit2 transfers — into a single contract call.

Installation

npm install @pancakeswap/universal-router-sdk

Quick start

import { PancakeSwapUniversalRouter, getUniversalRouterAddress, UniversalRouterVersion } from '@pancakeswap/universal-router-sdk'
import { ChainId } from '@pancakeswap/chains'
import { Percent } from '@pancakeswap/swap-sdk-core'
 
// After getting a trade from SmartRouter:
const { calldata, value } = PancakeSwapUniversalRouter.swapERC20CallParameters(trade, {
  slippageTolerance: new Percent(50, 10000), // 0.5%
  recipient: '0xYOUR_ADDRESS',
  deadlineOrPreviousBlockhash: Math.floor(Date.now() / 1000) + 60 * 20,
  inputTokenPermit: permit2Signature, // optional — from @pancakeswap/permit2-sdk
})
 
const routerAddress = getUniversalRouterAddress(ChainId.BSC)

PancakeSwapUniversalRouter

Main class for encoding Universal Router command batches.

MethodSignatureDescription
swapERC20CallParameters(trades, options) → { calldata: Hex, value: string }Build calldata for one or more ERC-20 swaps via the Universal Router
swapNativeCurrencyCallParameters(trades, options) → { calldata: Hex, value: string }Build calldata for swaps where the input is native currency (ETH/BNB)

swapERC20CallParameters options

OptionTypeDescription
slippageTolerancePercentMaximum acceptable slippage
recipientstringAddress to receive output tokens
deadlineOrPreviousBlockhashnumber | stringDeadline (timestamp) or previous blockhash for flash-bot protection
inputTokenPermitobject | undefinedPermit2 signature for the input token; skips a separate approval tx
fee{ feeOptions }Optional protocol fee configuration

inputTokenPermit shape

// For AllowanceTransfer (EIP-712 signature)
{
  v: number
  r: string
  s: string
  amount: bigint
  expiration: number
  nonce: number
  spender: string
  sigDeadline: bigint
}

Functions

FunctionSignatureDescription
getUniversalRouterAddress(chainId: ChainId, version?: UniversalRouterVersion) → stringGet the deployed Universal Router address for a chain

Constants

ExportDescription
UNIVERSAL_ROUTER_ADDRESSRecord<ChainId, string> — addresses for the default router version
UniversalRouterVersionEnum of deployed router versions (V1, V2)

Universal Router addresses

See Universal Router addresses for the full list.