Wallet Developers
Add Play & Earn anywhere. Reward your users top tokens.

Step 1: Check if a token has games available
Before displaying a "Play & Earn" button, check whether a given token has games with rewards using /market/getTokenHasGames
API Request Example
async function checkTokenHasGames(tokenAddress: string, network: string): Promise<boolean> {
const response = await fetch(`https://api.dev.opengameprotocol.com/embed/getTokenHasGames?tokenAddress=${tokenAddress}&network=${network}`);
const data = await response.json();
// Example response:
// {
// "data": {
// "hasGames": true
// }
// }
return data.data.hasGames;
}
Implementation Example
const tokenAddress = "6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN"; // Replace with actual token address
const network = "Solana";
checkTokenHasGames(tokenAddress, network).then((hasGames) => {
if (hasGames) {
console.log("Show 'Play & Earn' button");
// Update UI to display "Play & Earn" button
} else {
console.log("No games available for this token");
}
});
Step 2: Fetch available games for a token
When the "Play & Earn" button is tapped, retrieve the list of games that have rewards staked with the token using /market/listTokenGames
API Request Example
async function listTokenGames(tokenAddress: string, network: string): Promise<any[]> {
const response = await fetch(`https://api.dev.opengameprotocol.com/embed/listTokenGames?tokenAddress=${tokenAddress}&network=${network}`);
const data = await response.json();
// Example response:
// {
// "data": {
// "items": [
// {
// "name": "Example Game",
// "description": "An example description",
// "image": "https://cdn.opengameprotocol.com/ogp.png",
// "gameUrl": "https://cdn.opengameprotocol.com/example.html",
// "platform": "web",
// "createdAt": "2025-02-20T12:00:00Z"
// }
// ],
// "total": 1
// }
// }
return data.data.items; // Array of games with available rewards
}
Implementation Example
const tokenAddress = "6p6xgHyF7AeE6TZkSmFsko444wqoP15icUSqi2jfGiPN"; // Replace with actual token address
const network = "Solana";
listTokenGames(tokenAddress, network).then((games) => {
if (games.length > 0) {
console.log("Available games:", games);
// Render list of games for user selection
// Example: Navigate to the top game
const topGame = games[0];
console.log("Navigating to:", topGame.name, topGame.url);
} else {
console.log("No reward-based games available for this token");
}
});
Last updated