This directory contains complete example implementations demonstrating how to integrate the Haystack Router SDK into different types of applications.
A simple React application demonstrating basic Haystack Router SDK integration.
Key Features:
- React 18 with TypeScript and Vite
- Multiple wallet support (Pera, Defly, Lute)
- Complete swap interface with quote display
An advanced React application showcasing TanStack Query (React Query) integration.
Key Features:
- Automatic quote fetching with 500ms debounce
- Real-time quote updates (refreshes every 15 seconds)
useQueryhook for quotes,useMutationhook for swaps- Optimistic UI updates and improved UX
- Demonstrates modern data fetching patterns
A command-line tool for executing swaps without a web interface.
Key Features:
- Custom signer implementation using algosdk
- Environment variable configuration
- Detailed console output and progress tracking
- No browser or wallet provider required
- Can be used for backend, automation and scripting
All examples use the local SDK package via pnpm workspaces. This means changes to the SDK are immediately reflected in the examples.
- Haystack Router API Key - A free tier key is included in the
.env.examplefiles (60 requests/min). For production rate limits, request a key from support@txnlab.dev. - algosdk 3.0.0 or later (peer dependency)
- Node.js >= 20
- pnpm 10.20.0 or later
From the repository root:
pnpm installThis installs dependencies for all packages and examples.
Build the SDK first:
pnpm buildThen run any example:
# React
cd examples/react
pnpm dev
# React Query
cd examples/react-query
pnpm dev
# Node.js CLI
cd examples/node-cli
pnpm devEach example includes a .env.example file with the free tier API key pre-configured. Create a .env file in the example directory:
VITE_HAYSTACK_ROUTER_API_KEY=1b72df7e-1131-4449-8ce1-29b79dd3f51e # Free tier (60 requests/min)HAYSTACK_ROUTER_API_KEY=1b72df7e-1131-4449-8ce1-29b79dd3f51e # Free tier (60 requests/min)
ACCOUNT_MNEMONIC="your 25 word mnemonic phrase"The monorepo structure enables a smooth development workflow:
- Make SDK changes in
packages/haystack/src/ - Rebuild the SDK:
pnpm build(from root) - Test immediately in any example (changes are reflected automatically)