This repository contains the Deflex SDK and example implementations for integrating Deflex Order Router into your applications.
TypeScript/JavaScript SDK for Deflex Order Router - smart order routing and DEX aggregation on Algorand.
- Documentation: packages/deflex/README.md
- npm: @txnlab/deflex
The examples directory contains complete working implementations:
Simple React application demonstrating basic Deflex SDK integration.
- React 18 with TypeScript and Vite
- Multiple wallet support (Defly, Pera, Lute, WalletConnect)
- Complete swap UI with quote display
- Fast development with HMR
Advanced React application showcasing TanStack Query integration.
- Automatic quote fetching with debouncing
- Real-time quote updates (refreshes every 15 seconds)
- Optimistic UI updates with mutations
- Demonstrates modern data fetching patterns
Command-line tool for executing swaps without a browser.
- Custom signer implementation
- Environment variable configuration
- Detailed console output
- Perfect for automation and scripts
This is a pnpm workspace monorepo. All packages and examples share dependencies and can reference each other.
- Deflex API Key - Request an API key by emailing [email protected]
- Node.js >= 20
- pnpm 10.18.3 or later
Install all dependencies:
pnpm installBuild the SDK package:
pnpm buildEach example can be run independently. Navigate to the example directory and follow its README:
# React
cd examples/react
pnpm dev
# React Query
cd examples/react-query
pnpm dev
# Node.js CLI
cd examples/node-cli
pnpm devInstall the SDK in your project:
npm install @txnlab/deflexBasic usage:
import { DeflexClient } from '@txnlab/deflex';
import { useWallet } from '@txnlab/use-wallet-react';
const { activeAddress, transactionSigner } = useWallet();
// Initialize client
const deflex = new DeflexClient({
apiKey: 'your-api-key',
});
// Get quote
const quote = await deflex.newQuote({
fromASAID: 0, // ALGO
toASAID: 31566704, // USDC
amount: 1_000_000, // 1 ALGO
address: activeAddress,
});
// Execute swap
const swap = await deflex.newSwap({
quote,
address: activeAddress,
signer: transactionSigner,
slippage: 1, // 1%
});
const result = await swap.execute();Run SDK tests:
pnpm testRun tests with coverage:
pnpm test:coverageRoot-level scripts:
pnpm build- Build the SDK packagepnpm test- Run SDK testspnpm test:watch- Run tests in watch modepnpm test:coverage- Run tests with coveragepnpm lint- Lint SDK codepnpm format- Check code formattingpnpm format:fix- Fix code formattingpnpm typecheck- Type check SDKpnpm ci- Run all CI checks (build, lint, format, test)pnpm release- Release a new version
- SDK Documentation: packages/deflex/README.md
- Examples Guide: examples/README.md
- Deflex API Docs: https://txnlab.gitbook.io/deflex-api
Contributions are welcome! The monorepo structure makes it easy to:
- Make changes to the SDK in
packages/deflex/ - Test changes immediately in any example project
- Examples automatically use the local SDK via workspace protocol
All examples reference the SDK using "@txnlab/deflex": "workspace:*" in their package.json.
MIT - see LICENSE for details
Built by TxnLab