Use this file to discover all available pages before exploring further.
⚠️ Developer Preview
The Gx402 SDK is still in active development.
Some features may not function as expected, and APIs are subject to change.
For production use, please wait for the stable release.
This tutorial will guide you through integrating the Gx402 SDK into an existing game project, covering the essential steps to get x402 functionality working.
import { Gx402SDK } from '@Gx402/web-sdk';// Initialize early in your game startupconst Gx402 = new Gx402SDK({ apiKey: 'YOUR_API_KEY_HERE', environment: 'development', // Change to 'production' for live builds enableRealtimeSync: true, debug: true // Set to false in production});// Wait for initializationawait Gx402.init();console.log('Gx402 SDK initialized successfully');
// Authenticate the user when they start playingasync function authenticateUser(userId, authData) { try { await Gx402.authenticate(userId, authData); console.log('User authenticated successfully'); // Now you can use user-specific x402 features return true; } catch (error) { console.error('Authentication failed:', error); return false; }}// Example usageconst isAuthenticated = await authenticateUser('user-123', 'auth-token');
// Process game data with x402 functionalityasync function processGameData(gameEvent) { try { const x402Result = await Gx402.processX402Data({ event: gameEvent.type, data: gameEvent.payload, timestamp: Date.now(), playerId: getCurrentPlayerId() }); // Apply x402 enhancements to your game return applyX402Enhancements(gameEvent, x402Result); } catch (error) { console.error('x402 processing failed:', error); // Fallback to normal game processing return gameEvent.payload; }}// Example: Process player movementasync function processPlayerMovement(movementData) { const x402EnhancedData = await processGameData({ type: 'player-move', payload: movementData }); // Update player position with x402-enhanced data updatePlayerPosition(x402EnhancedData);}
// Global error handler for Gx402 operationsGx402.on('error', (error) => { console.error('Gx402 error occurred:', error); // Log to your analytics logError(error); // Implement fallback behavior switch (error.type) { case 'NETWORK_ERROR': handleNetworkError(error); break; case 'AUTH_ERROR': reauthenticateUser(); break; case 'SYNC_ERROR': queueSyncOperation(error.operation); break; default: console.warn('Unknown error type, continuing operation'); }});// Function to handle network errorsfunction handleNetworkError(error) { // Queue operations for retry when network is available const offlineQueue = new Queue(); // Listen for connection status window.addEventListener('online', () => { retryQueuedOperations(); });}// Function to retry queued operationsasync function retryQueuedOperations() { while (!offlineQueue.isEmpty()) { const operation = offlineQueue.dequeue(); try { await operation(); } catch (error) { // Re-queue if still failing offlineQueue.enqueue(operation); } }}