Skip to main content

What We’re Building

A React (Next.js) app that connects Dynamic’s embedded wallets to Kalshi-style prediction markets on Solana, allowing users to:
  • Browse active prediction markets with real-time prices
  • Buy Yes/No outcome shares on markets using SOL
  • View and manage portfolio positions
  • Sell positions and redeem winning outcomes
  • Deposit funds via multiple methods (QR, cross-chain swap)
If you want to take a quick look at the final code, check out the GitHub repository.

Key Components

  • Dynamic JS SDK Embedded Wallets - Non-custodial Solana wallets with seamless auth
  • DFlow - Order execution protocol for Kalshi markets on Solana
  • Solana Network - All trades execute on Solana mainnet

Building the Application

Project setup

Scaffold a Next.js project with create-next-app. This recipe uses the Dynamic JS SDK (@dynamic-labs-sdk/client + @dynamic-labs-sdk/solana) for authentication and embedded Solana wallet management.
Dashboard: Under Chains & Networks, enable Solana. Under Sign-in Methods and Wallets, enable what your flow needs (including Embedded wallets). Under SecurityAllowed Origins, add your origin (for example http://localhost:3000).

Install Dependencies

Add the Dynamic JS SDK and Solana dependencies:

Configure Environment

Create a .env.local file with your Dynamic environment ID:
.env.local

Initialize Dynamic Client

Create src/lib/dynamic.ts to initialize the Dynamic client with the Solana extension:
src/lib/dynamic.ts
The addSolanaExtension() call registers Solana wallet support and must be called immediately after creating the client.

Configure Providers

Set up a wallet context using the JS SDK. Create src/lib/providers.tsx:
src/lib/providers.tsx

Build the Auth Button

Create a custom DynamicButton component at src/components/dynamic/DynamicButton.tsx. This handles Google OAuth, email OTP, and external Solana wallet connection:
src/components/dynamic/DynamicButton.tsx

Create the Trading Hook

Build the Kalshi trading hook that handles Solana transactions. Create src/lib/hooks/useKalshiTrading.ts:
src/lib/hooks/useKalshiTrading.ts
The key pattern for Solana signing in the JS SDK:
  1. Use getActiveNetworkData from @dynamic-labs-sdk/client to get network configuration for the wallet
  2. Use getSolanaConnection from @dynamic-labs-sdk/solana to get a Connection instance
  3. Use signTransaction from @dynamic-labs-sdk/solana to sign transactions with the embedded wallet

Create the Layout

Update src/app/layout.tsx to include the Roboto font and providers:
src/app/layout.tsx

Run the Application

Start the development server:
The application will be available at http://localhost:3000.

How Trading Works

When a user places a trade on Kalshi through this app:
  1. Authentication: The user signs in via Google, email OTP, or external Solana wallet using the custom DynamicButton
  2. Wallet Provisioning: After auth, a Solana embedded wallet is automatically created via createWaasWalletAccounts({ chains: ["SOL"] })
  3. Connection: getActiveNetworkData retrieves the RPC configuration, and getSolanaConnection creates a web3.js Connection
  4. Order Preparation: The app fetches a swap transaction from the DFlow API
  5. Transaction Signing: signTransaction from @dynamic-labs-sdk/solana signs the transaction with the embedded wallet
  6. Broadcast: The signed transaction is sent to the Solana network via the Connection
  7. Confirmation: The app polls for confirmation and shows success/error feedback

Conclusion

If you want to take a look at the full source code, check out the GitHub repository. This integration demonstrates how Dynamic’s JS SDK enables seamless Solana wallet management for prediction markets. The signTransaction function from @dynamic-labs-sdk/solana provides a clean interface for signing transactions with embedded wallets, while getSolanaConnection handles network connectivity.

Additional Resources

Last modified on May 21, 2026