0.1.94 • Published 7 months ago

@games-fun/sdk v0.1.94

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

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 actions
  • triggerAction(actionName: string, params: any): Trigger a game action
  • getConnection(): 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

  1. Install dependencies:
pnpm install
  1. Build:
pnpm build
  1. Watch mode:
pnpm dev
0.1.94

7 months ago

0.1.93

7 months ago

0.1.92

7 months ago

0.1.91

7 months ago

0.1.9

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago