Open Game SDK
OGP is the fastest way to launch, distribute, and monetize games - without middlemen.
The Open Game SDK provides a simple interface for frontend developers to integrate authentication, points management, and rewards functionality into their games. It supports built-in authentication (via Privy).
Quickstart
For the most basic integration, you only need to do the following steps:
Call init() with your game Id
Call addPoints() during gameplay to track points
Call savePoints() after a round of game play
With this setup, all OGP related UI will be handled automatically. Seamless and simple!
Example Integrations
Installation
To use the Open Game SDK in your project, you can choose one of the following methods:
Via Script Tag
Include the following script tag in your HTML file:
Alternatively, you can use a specific version of the SDK:
Once the script is loaded, the SDK becomes available as a global variable OpenGameSDK
Via NPM
The SDK is also available as an NPM package. Install it using:
Then, import it in your JavaScript code:
After installation, create an instance of the SDK as detailed in the Initialization section.
Before initializing the SDK, ensure that your index.html file's header includes:
Initialization
After installing the SDK, you need to create an instance and initialize it with your game’s configuration. This section covers the steps to set up the SDK for use.
Creating an SDK Instance
Create a new instance of the SDK with optional configuration options for UI customization and authentication preferences.
Parameters
>
ui.theme
'light' | 'dark'
'light'
Sets a light or dark theme for our default UI
ui.usePointsWidget
boolean
false
Show floating points widget
ui.useCustomUi
boolean
false
Disable all automatic modals/widgets; control UI entirely yourself
logLevel
number
2
Console logging level
Log Levels
0
VERBOSE
Most detailed logging
1
INFO
Standard information logging
2
WARN
Warning messages only
3
ERROR
Error messages only
4
DISABLE
No logging
init
Initialize the SDK with your game’s unique identifier and an optional player ID.
Parameters:
gameId(string, required) – You can find your game's ID after After adding a game in the Pre-release Onboarding AppplayerId(string, optional) – The player's unique ID. This is an optional parameter for developers that want to provide their own custom player IDs. If not set, then a login is provided for the user.
playerId Must not contain the characters # or %
Returns:
Promise<void>
Authentication
The SDK supports authentication via a built-in login interface (powered by Privy).
Built-in Login
Trigger the SDK’s default login UI.javascript
This opens the Privy login modal when useCustomAuth is set to false during instantiation.
Anon sessions
If you want to reduce friction and not ask the user to login straight away that's also an option. If you already use some sort of identifier, like fingerprint.js for example, you can set that as a playerId. The session will be setup using that and whenever the user wants to claim rewards, they will be prompted to login and have their data migrated into a fully fledged OGP user.
setPlayerId
Sets or updates the player's ID.
Parameters:
id(string, required) – The new player ID.
Returns:
void
Points
Manage player points with methods to save and retrieve them.
savePoints
Saves the player's earned points. Only accepts numbers greater than 0. Trying to save 0 or negative numbers will return a failure response. On success returns the totalPoints the user has saved for the day.
Parameters:
points(number, required) – The number of points to save.
Returns:
Promise<number | undefined>– API response with the total points saved for the day.
getPoints
Retrieves the player's current points along with the game tokens in which the points are distributed.
Parameters:
None
Returns:
Promise<PlayerPoints | undefined>– API response with points data orundefinedif the request fails.PlayerPointsstructure
Points Widget
ui.showPoints
Shows the points widget if it was opt-in during SDK instatiation via ui.usePointsWidget
Parameters:
None
ui.hidePoints
Hides the points widget
Parameters:
None
ui.addPoints
Add points to the session, which are reflected in the points widget. The points added here are merely for display purpose, if not saved, they will be lost.
Parameters:
points(number, required) – The number of points to added.
Rewards
Manage player rewards with methods for listing, claiming, and checking status.
listPlayerRewards
Fetches a list of rewards available to the player.
Parameters:
none
Returns:
Promise<PlayerRewards | undefined>– API response with player rewards data orundefinedif the request fails.PlayerRewardsstructure:
listCreatorRewards
Fetches a list of creator rewards available to the current player
Parameters:
None
Returns:
Promise<CreatorRewards | undefined>– API response with creator rewards data orundefinedif the request fails.CreatorRewardsstructure:
claimPlayerRewards
Attempts to claim available rewards for the player.
Parameters:
useRewardModal(boolean, optional) – Iftrue, displays a modal listing user rewards before confirming the claim; iffalse, directly shows the confirm claim modal.
Returns:
void
claimCreatorRewards
Attempts to claim available rewards for the game creator. Displays the creator rewards modal for the current playerId
Parameters:
None
Returns:
void
getRewardStatus
Retrieve the status of a reward claim transaction.
Parameters:
txHash(string, required) – The transaction hash.
Returns:
'pending' | 'complete' | 'failed'
getTimeUntilNextClaim
Retrieve the time until the player can claim their next reward.
Parameters:
None
Returns:
Promise<{ number }>– API response with time data (in milliseconds).
Event Callbacks
Handle SDK events with individual listeners or a catch-all approach.
onAny
Capture all SDK events with a single listener.
Parameters:
callback(function) – Receives the event name and data.
Specific Events
Handle specific events as needed:
OnReady: Fired when the SDK is initialized.
OnSessionStarted: Fired when a session begins.
OnLoginSuccess: Fired after successful login.
Full Event List:
'OnReady': SDK initialized.'SessionStarted': Session established.'SessionFailed': Session fails (e.g., missing parameters).'LoginRequest': Login process starts (built-in or viastartCustomAuth).'LoginCancelled': Login canceled (via modal orcancelCustomAuth).'LoginSuccess': Login succeeds.'LoginFailed': Authentication fails.'Logout': User logs out.'SavePointsSuccess': Points saved successfully.'SavePointsCancelled': Save points canceled.'SavePointsFailed': Points save fails.'ClaimRequest': Claim request sent.'ClaimSuccess': Claim transaction succeeds.'ClaimFailure':Claim fails (e.g., no rewards).'ClaimCancelled': Claim transaction not signed.
Unsubscribing from Events
To unsubscribe from a specific event, use ogp.off(eventName, callback). To unsubscribe from all events captured by onAny, use ogp.off('*', callback)
Error Handling
Display errors to users via the SDK’s UI.
showError
Show an error message to the user.
Parameters:
error(object, required) – Containstitleandmessage.
Demos
Our public demo GitHub is at https://github.com/OpusGameLabs/ogp-demos
Simple Game Demo (simple-game/)
simple-game/)This demo shows how to:
Initialize and configure the OpenGameSDK
Track player points in real-time using
addPoints()Save final scores using
savePoints()Handle SDK events (
OnReady,OnSessionStarted)
Claim Creator Rewards Demo (claim-creator-rewards/)
claim-creator-rewards/)This demo shows how to:
Claim creator rewards using
claimCreatorRewards()Handle async SDK operations with proper error handling
Provide user feedback during claim operations
Implement a simplified single-purpose SDK integration
\
Last updated