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-reactv4 - 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 >= 20
- 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:
const walletManager = new WalletManager({
wallets: [WalletId.DEFLY, WalletId.PERA, WalletId.LUTE],
defaultNetwork: 'mainnet',
options: {
resetNetwork: true,
},
});You can customize which wallets are available by modifying this configuration.
- 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