This guide will help you migrate from the deprecated @txnlab/deflex package to the new @txnlab/haystack-router package.
The Deflex Order Router SDK has been rebranded to Haystack Router. All functionality remains identical—only naming has changed. This migration involves updating package names, import statements, and class/type names in your code.
npm uninstall @txnlab/deflex
npm install @txnlab/haystack-routerOr with pnpm:
pnpm remove @txnlab/deflex
pnpm add @txnlab/haystack-router// Before
import { DeflexClient, DeflexQuote } from '@txnlab/deflex'
// After
import { RouterClient, SwapQuote } from '@txnlab/haystack-router'// Before
const deflex = new DeflexClient({
apiKey: 'your-api-key'
})
// After
const router = new RouterClient({
apiKey: '1b72df7e-1131-4449-8ce1-29b79dd3f51e' // Free tier (60 requests/min)
})// Before
const quote = await deflex.newQuote({
address: activeAddress,
fromAssetId: 0,
toAssetId: 31566704,
amount: 1_000_000
})
const swap = await deflex.newSwap({
quote,
address: activeAddress,
signer: transactionSigner
})
// After
const quote = await router.newQuote({
address: activeAddress,
fromAssetId: 0,
toAssetId: 31566704,
amount: 1_000_000
})
const swap = await router.newSwap({
quote,
address: activeAddress,
signer: transactionSigner
})- Old:
@txnlab/deflex - New:
@txnlab/haystack-router
- Old:
DeflexClient - New:
RouterClient
| Old Type | New Type | Purpose |
|---|---|---|
DeflexConfig |
Config |
Configuration object |
DeflexConfigParams |
ConfigParams |
Configuration parameters |
DeflexQuote |
SwapQuote |
Quote response type |
DeflexTransaction |
SwapTransaction |
Transaction type |
DeflexSignature |
Signature |
Signature type |
- API Endpoint: Automatically updated to
https://hayrouter.txnlab.dev/api - Repository: Moved to
github.com/TxnLab/haystack-js - Variable Naming Convention:
deflex→router(in examples and documentation)
For quick migration across your codebase, use these find/replace patterns in your IDE:
-
Package name:
- Find:
@txnlab/deflex - Replace:
@txnlab/haystack-router
- Find:
-
Main client class:
- Find:
DeflexClient - Replace:
RouterClient
- Find:
-
Configuration types:
-
Find:
DeflexConfig -
Replace:
Config -
Find:
DeflexConfigParams -
Replace:
ConfigParams
-
-
Swap types:
-
Find:
DeflexQuote -
Replace:
SwapQuote -
Find:
DeflexTransaction -
Replace:
SwapTransaction
-
-
Other types:
- Find:
DeflexSignature - Replace:
Signature
- Find:
If you're using the conventional deflex variable name:
// Find pattern: const deflex = new
// Replace: const router = new
// Find pattern: deflex.
// Replace: router.Important: Be careful with case-sensitive replacements and review changes before committing.
If you're using environment variables for API keys:
# Before
DEFLEX_API_KEY=your-api-key
VITE_DEFLEX_API_KEY=your-api-key
# After
HAYSTACK_ROUTER_API_KEY=1b72df7e-1131-4449-8ce1-29b79dd3f51e
VITE_HAYSTACK_ROUTER_API_KEY=1b72df7e-1131-4449-8ce1-29b79dd3f51eImportant: This migration involves naming changes only. All functionality, features, and APIs remain identical:
- Same methods and parameters
- Same behavior and responses
- Same middleware system
- Same swap routing capabilities
- Same DEX aggregation logic
Your existing integration will work exactly the same way after updating the names.
The new SwapTransaction type provides better clarity and avoids potential naming collisions with the algosdk.Transaction type:
import { Transaction } from 'algosdk'
import { SwapTransaction } from '@txnlab/haystack-router'
// Clear distinction between algosdk transactions and swap transactions// Before
import { DeflexClient, type DeflexQuote } from '@txnlab/deflex'
import { useState } from 'react'
function SwapComponent() {
const [quote, setQuote] = useState<DeflexQuote | null>(null)
const deflex = new DeflexClient({
apiKey: import.meta.env.VITE_DEFLEX_API_KEY
})
const fetchQuote = async () => {
const result = await deflex.newQuote({...})
setQuote(result)
}
// ...
}
// After
import { RouterClient, type SwapQuote } from '@txnlab/haystack-router'
import { useState } from 'react'
function SwapComponent() {
const [quote, setQuote] = useState<SwapQuote | null>(null)
const router = new RouterClient({
apiKey: import.meta.env.VITE_HAYSTACK_ROUTER_API_KEY
})
const fetchQuote = async () => {
const result = await router.newQuote({...})
setQuote(result)
}
// ...
}// Before
import { DeflexClient } from '@txnlab/deflex'
import algosdk from 'algosdk'
const deflex = new DeflexClient({
apiKey: process.env.DEFLEX_API_KEY || ''
})
const quote = await deflex.newQuote({
address: account.addr,
fromAssetId: 0,
toAssetId: 31566704,
amount: 1_000_000
})
// After
import { RouterClient } from '@txnlab/haystack-router'
import algosdk from 'algosdk'
const router = new RouterClient({
apiKey: process.env.HAYSTACK_ROUTER_API_KEY || ''
})
const quote = await router.newQuote({
address: account.addr,
fromAssetId: 0,
toAssetId: 31566704,
amount: 1_000_000
})Middleware code requires minimal changes:
// Before
import { SwapMiddleware, type DeflexQuote } from '@txnlab/deflex'
class MyMiddleware implements SwapMiddleware {
async modifyQuoteParams(params) {
return params
}
}
// After
import { SwapMiddleware, type SwapQuote } from '@txnlab/haystack-router'
class MyMiddleware implements SwapMiddleware {
async modifyQuoteParams(params) {
return params
}
}If you encounter any issues during migration:
- GitHub Issues: github.com/TxnLab/haystack-js/issues
- Documentation: github.com/TxnLab/haystack-js
- Email: support@txnlab.dev
- Current:
@txnlab/deflexv1.9.0 is the final version with deprecation notices - Recommended: Migrate to
@txnlab/haystack-routerv2.0.0+ as soon as convenient - Future: No further updates will be published to
@txnlab/deflex
Thank you for using Haystack Router! We're committed to providing the best DEX aggregation experience on Algorand.