Skip to main content
This guide will walk you through setting up @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:
Navigate to your project directory:

Step 2: Install @sodax/sdk

Install the SODAX SDK and its peer dependencies:

Step 3: Create Sodax Instance

Create a Sodax instance provider. Create providers/SodaxProvider.tsx:
Update your 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:
Your Next.js application should now be running on 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 your tsconfig.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:
  1. Explore Solver Features: Check out the Swaps documentation for cross-chain swaps
  2. Explore Money Market Features: Check out the Money Market documentation for lending and borrowing
  3. Set up Wallet Integration: Implement wallet providers for the chains you want to support
  4. Add Error Handling: Implement proper error handling for SDK operations
  5. Add Loading States: Add loading indicators for async operations

Troubleshooting

Common Issues

  1. TypeScript Errors: Make sure you have the latest version of TypeScript and that your tsconfig.json is properly configured.
  2. 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:
The cause was upstream Turbopack scope-hoisting bugs in three transitive dependencies — @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: