sui-game-sdk
v0.0.2
Published
The ultimate SDK for building games on SUI. Session Keys, Spawning, & Sync.
Downloads
169
Maintainers
Readme
SUI Game SDK
The ultimate SDK for building games on SUI. Includes Session Keys, Asset Spawning, and Game State Synchronization.
Features
1. Session Manager
Eliminate wallet popups during gameplay.
- Generate ephemeral Ed25519 keys locally
- Export/Import session state
- Sign transactions seamlessly
2. Asset Spawner
Simplified API for minting game objects using Move calls.
- Fluent
spawn(recipient, attributes)API - Auto-formats vector arguments for attributes
3. Game State Sync
React to on-chain game events in real-time.
- Poll for specific Move events
- Subscription-based handler pattern
Installation
npm install sui-game-sdkQuick Start
import { SessionManager, AssetSpawner, GameStateSync } from 'sui-game-sdk';
import { SuiClient } from '@mysten/sui/client';
const client = new SuiClient({ url: 'https://fullnode.testnet.sui.io' });
// 1. Create Session
const session = new SessionManager(client);
console.log('Session Address:', session.sessionAddress);
// 2. Spawn Asset
const spawner = new AssetSpawner(client, {
packageId: '0x...',
module: 'hero',
function: 'mint_hero',
adminCapId: '0x...'
});
// 3. Listen to Events
const sync = new GameStateSync(client);
sync.subscribe('0x...::hero::LevelUpEvent', (event) => {
console.log('Level Up!', event.parsedJson);
});
sync.startPolling('0x...');Starter Templates
Kickstart your game development with our ready-to-use starter templates:
Generate a Starter
npx sui-game-sdk initYou'll be prompted to choose from:
1. TypeScript (Web/Node)
Full-featured starter with all SDK components. Perfect for web games or backend services.
- Uses SessionManager, AssetSpawner, GameStateSync
- Includes sample "Sui Quest" game
- Move contract included
2. Next.js (Web App)
Modern React web application with beautiful UI.
- Direct SDK integration
- Real-time event streaming
- Tailwind CSS + glassmorphic design
- Production-ready structure
3. Unity (C# Scripts)
Game engine integration for Unity developers.
- Simulates SDK patterns in C#
- HTTP/RPC blockchain communication
- Organized Assets folder structure
- Compatible with Unity 2021.3+
4. Godot (GDScript)
Game engine integration for Godot developers.
- Simulates SDK patterns in GDScript
- HTTP/RPC blockchain communication
- Standard Godot 4 project structure
- Signals for event handling
Starter Features
All starters include:
- Sample "Sui Quest" game (Mint Hero, Slay Boar, Level Up)
- Move smart contract (
hero.move) - Deployment scripts
- Comprehensive README
- SDK integration examples
How Starters Use the SDK
- TypeScript & Next.js: Direct SDK imports (
import { SessionManager } from 'sui-game-sdk') - Unity & Godot: Simulate SDK concepts using native languages (C#/GDScript)
For detailed SDK usage comparison, see SDK_USAGE.md
Documentation
- SDK Usage Guide - How each starter uses the SDK
- TypeScript Starter
- Next.js Starter
- Unity Starter
- Godot Starter
Example: Building a Simple RPG
import { SessionManager, GameStateSync } from 'sui-game-sdk';
import { Transaction } from '@mysten/sui/transactions';
// Setup
const client = new SuiClient({ url: 'https://fullnode.testnet.sui.io' });
const session = new SessionManager(client);
// Execute game action
const tx = new Transaction();
tx.moveCall({
target: `${PACKAGE_ID}::hero::slay_boar`,
arguments: [tx.object(heroId)]
});
const result = await session.executeSessionTx(tx);
console.log('Action completed:', result.digest);
// Listen for results
const sync = new GameStateSync(client);
sync.subscribe(`${PACKAGE_ID}::hero::AttackEvent`, (event) => {
console.log('Damage dealt:', event.parsedJson.damage_dealt);
});
sync.startPolling(PACKAGE_ID);Development
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm testLicense
MIT
