Wallet Address
// Connect wallet and initialize SDK
const accounts = await window.ethereum.request({
method: 'eth_requestAccounts'
});
await sdk.initContracts(window.ethereum);
await sdk.auth.login({ walletAddress: accounts[0] });
Watch an ad to earn XP tokens! Rewards are claimable on-chain.
// Request and show a rewarded ad
const session = await sdk.ads.requestAd({
placementId: 'main-reward'
});
const receipt = await sdk.ads.show(session.id);
console.log('Earned:', receipt.rewardAmount, 'XP');
Claim your earned XP as real tokens on Immutable zkEVM.
// Claim XP on-chain (requires watching ad)
const result = await sdk.claimXPWithAd(pendingXP, {
placementId: 'xp_claim'
});
console.log('TX Hash:', result.txHash);
console.log('Explorer:', result.explorerUrl);
Track progress and submit scores to the leaderboard.
// Track game progress events
await sdk.progress.trackEvent({
type: 'LEVEL_COMPLETE',
value: 1,
metadata: {
level: 5,
score: 12500,
timeTaken: 180
}
});
// Submit score to leaderboard
const result = await sdk.leaderboards.submit({
boardId: 'high-scores',
score: 9500
});
console.log('Rank:', result.rank);
Add the SDK to your HTML5 game in minutes.
<script src="/xp-sdk.browser.js"></script>
// Initialize SDK when your game loads
const sdk = await window.XPSDK.init({
gameId: 'your-game-id',
env: 'production', // or 'testnet'
debug: true
});
// Listen for SDK events
sdk.on('auth:login', (player) => {
console.log('Player:', player.id);
});
sdk.on('adComplete', (session, receipt) => {
console.log('Reward:', receipt.rewardAmount);
});