Introduction
Learn how to integrate your games with Upside.win using the Upside SDK. Handle game logic in your backend while Upside manages WIN token rewards.
Overview
Integrating with Upside.win is simple. Your game runs in an iframe on our platform, receives player authentication via JWT, and interacts with the Upside backend through our SDK for bet placement and payout processing.
Key principle: Your backend handles game logic and state (cards, winners, outcomes), while Upside handles all WIN token transactions.
Integration Flow
Game Loads in Iframe
Players launch your game, which loads inside an iframe on upside.win. Your game receives: - JWT token for the player - Player authentication context - Access to the Upside SDK
Frontend: Receive JWT
Wrap your game with ParentProvider from the Upside SDK to receive the JWT.
javascriptimport { ParentProvider } from "@b3dotfun/upside-sdk"; export default function GameApp() { return ( <ParentProvider> <YourGameComponent /> </ParentProvider> ); }
Backend: Place Bet
When a player starts playing, your backend calls placeBet to lock in their wager.
javascript{ createB3Client } from "@b3dotfun/upside-sdk/server"; const b3Client = createB3Client(); const betResult = await b3Client.placeBet( "coin-flip", // gameType "100000000000000000" // betAmount in wei (1 token = 10^18 wei) );
Backend: Handle Game Logic
Your backend: - Determines game outcome (coin lands on heads/tails) - Stores game state in your database - Calculates payout amount - Prepares outcome data (player choice, result, outcome)
Backend: Process Payout
When game ends, send the result to Upside to credit the player's WIN balance.
javascriptconst payoutResult = await b3Client.processPayout( "coin-flip", // gameType sessionId, // unique game session ID payoutAmount, // WIN tokens to award (0 if loss) // gameData { playerChoice: "heads", result: "heads", outcome: "win" } );
Frontend: Show Result
Your game displays the outcome to the player.
The Upside platform automatically:
- Updates the player's WIN balance
- Adds the win/loss to leaderboards
- Sends notifications
Installation
bashnpm install @b3dotfun/upside-sdk # or pnpm add @b3dotfun/upside-sdk # or bun install @b3dotfun/upside-sdk