♠️
RACE Protocol
NFT PresaleDiscord
  • ❤️Official Docs & Links
  • ⏳Progress Overview
  • RACE Protocol
    • 🏗️System Architecture
      • Components
      • On-chain Accounts
      • Synchronization
      • Randomization
      • Payment
    • 🎲Game Development
      • Game Handler
      • Effect
      • Event Handling
      • Race API
        • Arweave Integration
      • Race JS SDK
        • Installation and Setup
        • Key Components
          • AppClient
          • SubClient
          • Events
          • Game Context
          • Decryption Cache
        • Advanced Features
          • Getting Revealed Knowledge
          • Exiting and Detaching
          • Submitting Messages
          • Sub-game Interaction
        • Best Practices
        • API Reference
        • Troubleshooting
    • 🧪Testing
      • Race Test Kit
      • Unit Testing
      • Integration Testing
      • Additional Considerations
    • 🧱Modules & Features
      • Encryption Methods
      • Command-line Tools
      • Configuration Options
      • Blockchain Transport Implementations
    • 📃Smart Contract
      • Solana Program
    • 🔦Examples and Use Cases
      • Draw Card Game
      • Raffle Game
      • Other Examples
  • RACE Games
    • ♠️RACE Poker app
      • 🎮Start playing in minutes
        • 💰Cash and sit-n-go
        • 🏆Tournaments
      • 🎨Workshop
        • 🏆Create cash games
        • 🏨Create tourneys
      • 💡Concept introduction
      • 🏗️System architecture
      • 👾Game Flow
      • 🎲Cards shuffling
      • ☎️Communication
      • 🔐Key sharing/decryption
      • 💱Cash flow structure
    • ⚡Solfast
      • 🎲Game modes
  • RACE RESEARCH
    • 👾No-Code Development
      • Brainstorming
      • Implementation Approach
      • Project Status
    • 0️⃣Zero-Knowledge Proofs
      • Brainstorming
      • Integration steps
        • Verifiable Randomness Generation
        • Private Game State Updates
        • Verifiable Settlements
        • Private Player Actions
      • Project Status
    • 🛡️Security Audit Report
      • Executive summary
        • Introduction to Race Protocol
        • Audit Methodology
      • Findings
        • Smart Contract Security
        • WebAssembly Security
        • Client-side Security (Race SDK)
        • Server-side Security
        • Randomization and Encryption
        • On-chain Account Management
        • Synchronization Mechanisms
        • Payment Handling
      • Recommendations
      • Conclusion
  • RACE DAO
    • 😎About
    • 🫂Community
    • 🖼️NFT Collection [!]
Powered by GitBook
On this page
  • Installing the RACE JS SDK
  • Importing and Initializing the SDK
  • Configuration Options
  1. RACE Protocol
  2. Game Development
  3. Race JS SDK

Installation and Setup

Installing the RACE JS SDK

You can install the RACE JS SDK using either npm or yarn:

Using npm:

npm install @race-foundation/sdk-core

Using yarn:

yarn add @race-foundation/sdk-core

This will install the core SDK package, which provides the essential functionalities for interacting with Race Protocol games. Depending on the blockchain network you are targeting, you may also need to install the corresponding transport implementation package (e.g., @race-foundation/sdk-solana for Solana).

Importing and Initializing the SDK

Once installed, you can import the necessary classes and functions from the SDK into your client application:

// TypeScript code
import { AppClient } from '@race-foundation/sdk-core';

To initialize the SDK, you need to create an AppClient instance. This requires providing the following information:

  • gameAddr: The address of the Race game you want to connect to.

  • transport: An instance of the appropriate transport implementation (e.g., SolanaTransport).

  • wallet: An instance of a wallet adapter that will be used to sign transactions (e.g., PhantomWalletAdapter).

  • onEvent: A callback function that will be invoked whenever a game event occurs. This function receives the game context snapshot, the current handler state, and the event object as arguments.

Here's an example of initializing the SDK with a Solana transport and a Phantom wallet:

// TypeScript code
import { SolanaTransport } from '@race-foundation/sdk-solana';
import { PhantomWalletAdapter } from '@race-foundation/sdk-solana';

const gameAddr = '...'; // Replace with your game address

const transport = new SolanaTransport('https://api.devnet.solana.com'); // Replace with your Solana endpoint
const wallet = new PhantomWalletAdapter({ skipPreflight: true }); // Configure wallet options

const appClient = await AppClient.initialize({
  gameAddr,
  transport,
  wallet,
  onEvent: (context, state, event) => {
    // Handle game events here
  },
});

Configuration Options

When initializing the RACE JS SDK, you may need to provide additional configuration options depending on your specific setup and requirements. Some common options include:

  • chain: This specifies the blockchain network you are targeting (e.g., "solana", "facade"). This option is typically used by the transport implementation to determine how to interact with the blockchain.

  • endpoint: This defines the endpoint URL for the Transactor server. This is necessary for the SDK to establish a connection and communicate with the game server.

  • storage: Optionally, you can provide an instance of a storage adapter (e.g., local storage) that will be used by the SDK to cache data like game bundles and player profiles.

Refer to the API reference and documentation for the specific transport implementation you are using for details on additional configuration options that may be available.

By following these steps and providing the necessary configuration options, you can successfully install and set up the RACE JS SDK in your client application, enabling you to interact with Race Protocol games and leverage its functionalities.

PreviousRace JS SDKNextKey Components

Last updated 1 year ago

🎲