AI Integration Guide
A simple guide for integrating the OpenGameSDK into HTML/JavaScript games. Get your game connected to OGP in minutes!
After login,
ogp.playerIdis the player's Privy ID. Use it as the canonical user key in your game/backend.
🚀 Quick Start - It's This Easy
// 1. Initialize
const ogp = new OpenGameSDK({ ui: { usePointsWidget: true } });
ogp.init({ gameId: 'YOUR_GAME_ID' });
// 2. Add points during gameplay (display only)
ogp.addPoints(10);
// 3. Save when game ends - auto-logs in if needed!
await ogp.savePoints(totalScore);That's it! The SDK handles authentication automatically when you call savePoints().
💡 Key Concepts
Auto-Login
savePoints() automatically prompts login if user isn't authenticated
Points Widget
Built-in UI shows player's points - no extra work needed
Privy Auth
Secure authentication handled by SDK
One Save Per Session
Call savePoints() once when game ends
1) Install
Add two lines to your HTML <head>:
2) Initialize
Simple Rules:
Create one SDK instance per page
Register event handlers before calling
initWait for
OnReadybefore enabling gameplay
3) Identity & Login
✨ Auto-Login: The Easy Way
You don't need to handle login manually! When you call savePoints(), the SDK automatically prompts the user to log in if they aren't already authenticated.
This means you can:
Let players start playing immediately
Only prompt for login when they want to save progress
Keep your code simple
Manual Login (Optional)
If you prefer to prompt login earlier (e.g., for multiplayer features):
After login, ogp.playerId contains the user's Privy ID - use this as their unique identifier.
4) Scoring & Saving
The Simple Pattern
Best Practice: Save Only Improvements
To prevent duplicate rewards, only save the difference when players beat their best:
Game Type Examples
Key Rules:
addPoints()for display during gameplaysavePoints()once when session endsSave improvements, not absolute scores
5) Rewards & Claims
6) UI Helpers
7) Events
Register these before calling init:
8) Complete Example
9) Integration Checklist
API Reference
Methods
init({ gameId })
Initialize SDK with your game ID
addPoints(amount)
Update points display during gameplay
savePoints(score)
Save score to server (auto-login if needed)
getPoints()
Get player's current points
claimRewards(showModal?)
Open claim rewards flow
listPlayerRewards()
Fetch player's available rewards
getTimeUntilNextClaim()
Seconds until next claim available
login()
Manually trigger login modal
logout()
Clear user session
showError({ title, message })
Display error modal to user
UI Namespace
ui.showPoints()
Show the points widget
ui.hidePoints()
Hide the points widget
ui.setTheme(theme)
Set "light" or "dark" theme
Events
OnReady
SDK initialized and ready
SessionStarted
Player session established
SessionFailed
Session failed (API error, missing params)
LoginRequest
Login flow started
LoginSuccess
User successfully logged in
LoginFailed
Login failed
LoginCancelled
User closed login modal
Logout
User logged out
SavePointsSuccess
Points saved to server
SavePointsFailed
Failed to save points
SavePointsCancelled
User cancelled save
ClaimRequest
Claim transaction requested
ClaimSuccess
Claim transaction sent
ClaimFailure
Claim failed
ClaimCancelled
User cancelled claim
Constructor Options
That's everything you need! The SDK handles the complexity—you just call savePoints() and let auto-login do its thing. 🎮
Last updated