A simple React application demonstrating basic Haystack Router SDK integration with Vite and @txnlab/use-wallet-react for wallet management.
- Multiple wallet support (Pera, Defly, Lute)
- Modern wallet UI with
@txnlab/use-wallet-reactv5 - Get swap quotes from Haystack Router API
- Execute swaps with slippage protection
- Display quote details and routing information
- Haystack Router API Key - A free tier key is included in
.env.example(60 requests/min). For production rate limits, request a key from support@txnlab.dev. - Node.js >= 22
- pnpm 10.20.0 or later
- Install dependencies from the repository root:
pnpm install- Create a
.envfile in this directory:
cp .env.example .env- The
.envfile comes pre-configured with the free tier API key. For production use, replace it with your dedicated key.
Run the development server:
pnpm devThe app will be available at http://localhost:5173
Build for production:
pnpm buildPreview the production build:
pnpm preview- Choose a wallet from the available options (Pera, Defly, or Lute)
- Click to connect your chosen wallet
- If you have multiple accounts, select the active account from the dropdown
- Select the assets you want to swap
- Enter the amount and slippage tolerance
- Click "Get Quote" to fetch a quote from Haystack Router
- Review the quote details (output amount, price impact, routing)
- Click "Execute Swap" to perform the swap
The example is configured with multiple wallet providers in src/main.tsx:
import { defly } from '@txnlab/use-wallet-defly'
import { pera } from '@txnlab/use-wallet-pera'
import { lute } from '@galaxypay/use-wallet-lute'
const walletManager = new WalletManager({
wallets: [defly(), pera(), lute()],
defaultNetwork: 'mainnet',
});Each wallet comes from its own adapter package. To change which wallets are available, add or remove adapter packages and update this list.
- This example uses mainnet (real assets!)
- Make sure you have sufficient ALGO/assets in your account
- The SDK automatically handles app and asset opt-ins when needed
- Slippage is set to 1% by default but can be adjusted