0.1.94 • Published 7 months ago
@games-fun/sdk v0.1.94
Games.fun SDK
JavaScript SDK for integrating games with the Games.fun platform.
Installation
npm install @games-fun/sdk
# or
yarn add @games-fun/sdk
# or
pnpm add @games-fun/sdk
Quick Start
import { GamesFunSDK } from '@games-fun/sdk';
// Initialize SDK
const sdk = new GamesFunSDK({
debug: true,
gameServerUrl: "your-game-server-url",
onConnect: (connection) => {
// Handle connection established
console.log("Connected:", connection);
}
});
// Register game actions
sdk.registerActions({
purchaseItem: "Purchase in-game item",
useItem: "Use inventory item"
});
// Trigger actions
try {
const result = await sdk.triggerAction("purchaseItem", {
itemId: "123",
price: 100
});
console.log("Purchase successful:", result);
} catch (error) {
console.error("Purchase failed:", error);
}
Development Mode
For local development and testing, you can enable dev mode to simulate wallet connections and token balances:
const sdk = new GamesFunSDK({
debug: true,
gameServerUrl: "your-game-server-url",
dev: {
enabled: true // Auto-connects wallet with mock data
}
});
This will automatically:
- Connect a mock wallet
- Set initial token balances
- Enable auto-validation of actions
API Reference
GamesFunSDK
Constructor Options
interface SDKOptions {
debug?: boolean;
gameServerUrl: string;
onConnect?: (connection: Connection) => void;
onBalanceUpdate?: (connection: Connection) => void;
dev?: {
enabled?: boolean; // Auto-enabled if not in iframe
}
}
Methods
registerActions(actions: Record<string, string>)
: Register multiple game actionstriggerAction(actionName: string, params: any)
: Trigger a game actiongetConnection()
: Get current connection state
Connection State
interface Connection {
privyId: string;
gameId?: string;
token?: string;
walletAddress: string | null;
tokenBalance: string;
solBalance: string;
}
Examples
Check out the examples directory for:
Development
- Install dependencies:
pnpm install
- Build:
pnpm build
- Watch mode:
pnpm dev