@sodax/sdk in a Next.js project, from project creation to using the SDK features.
Prerequisites
- Node.js 18+ installed
- npm, yarn, or pnpm package manager
- Basic knowledge of Next.js and TypeScript
Step 1: Create Your Project
First, create a new Next.js project with TypeScript:Step 2: Install @sodax/sdk
Install the SODAX SDK and its peer dependencies:Step 3: Create Sodax Instance
Create a Sodax instance provider. Createproviders/SodaxProvider.tsx:
app/layout.tsx to include the SodaxProvider:
SodaxProvider.tsx is a 'use client' module, so everything in it ships to the browser. Do not pass
it an apiKey — renaming SODAX_API_KEY to NEXT_PUBLIC_SODAX_API_KEY publishes the key in your bundle.
Keep keyed calls in a Server Action or Route Handler, or proxy them — see API key good practices.
Step 4: Start Your Build Process
Start the development server:http://localhost:3000.
Step 5: Start Using @sodax/sdk
Now you can use the SODAX SDK in your components. Here’s an example of how to use it:TypeScript Configuration
Make sure yourtsconfig.json includes the necessary paths for the @ alias:
Next Steps
Now that you have@sodax/sdk set up in your Next.js project, you can:
- Explore Solver Features: Check out the Swaps documentation for cross-chain swaps
- Explore Money Market Features: Check out the Money Market documentation for lending and borrowing
- Set up Wallet Integration: Implement wallet providers for the chains you want to support
- Add Error Handling: Implement proper error handling for SDK operations
- Add Loading States: Add loading indicators for async operations
Troubleshooting
Common Issues
-
TypeScript Errors: Make sure you have the latest version of TypeScript and that your
tsconfig.jsonis properly configured. - Import Errors: Ensure all imports are using the correct paths and that the packages are properly installed.
Next.js 16 + Turbopack: “module factory is not available”
Building a Next 16 app that imports@sodax/sdk used to crash at SSR prerender with:
@stacks/transactions (reproducible with a bare import { Cl } from '@stacks/transactions' in a
fresh Next 16 app, no SODAX code involved), @stacks/connect, and
@injectivelabs/wallet-ledger.
No workaround is needed on the consumer side. Those dependencies are isolated inside
@sodax/libs, which
sits at the bottom of the dependency chain and re-exports each one through its own pre-bundled
subpath. @sodax/sdk, @sodax/wallet-sdk-core and @sodax/wallet-sdk-react consume those subpaths,
so the published dist contains no top-level import that triggers the cycle.
If you hit this error, upgrade the @sodax/* packages first. A runnable regression app for the
fix — server component, client component and an automated build check — lives at
apps/example-next-js-16.
One consumer-side requirement remains: the Injective wallet path declares
libsodium-wrappers-sumo as an optional peer dependency, so install it in your app if you enable
Injective wallet support.
Getting Help
If you encounter any issues:- Check the main SDK documentation
- Review the Swaps documentation for swap-related features
- Review the Money Market documentation for lending/borrowing features
- Open an issue on the GitHub repository
- Join the Discord community for support