Gaming sdk
Overview

Overview

xRaise wallet allows games to integrate blockchain to the gameplay.

Solution includes integrated wallet where users can create account without leaving the browser.

xRaise wallet supports background sessions so user can play without interruptions for transaction signing

Quick setup

Installation

Install xRaise Wallet connector package

npm i xraise-gaming-sdk

Usage

Smart contracts

Games are required to launch NFTs for your game entities like inventory items, skins, achevements. These smartcontracts are typical and can be based on ready-made ones. Read more about game smartcontracts deployment

Integration

Ask user to connect the wallet

  // GAME_CONTRACT_1_ADDRESS calls will not require confirmations during session
  await gamingSdk.user.connect({
    sessionContracts: [GAME_CONTRACT_1_ADDRESS] 
  });

Dealing with inventory

Request user inventory items

  const userInventory = await gamingSdk.user.current.inventory.get([CATEGORY_NFT_ID]);
  const userInventory = await gamingSdk.user.current.inventory.get([CATEGORY_NFT_ID_1, CATEGORY_NFT_ID_2]);
 
  await gamingSdk.user.current.inventory.watch([CATEGORY_NFT_ID], (newItems) => {...});
  await gamingSdk.user.current.inventory.watch([CATEGORY_NFT_ID_1, CATEGORY_NFT_ID_2], (newItems) => {...});

Add user items

  const userInventory = await gamingSdk.user.inventory.get();
 
  await gamingSdk.user.inventory.mint(NFT_ADDRESS, 1);
  await gamingSdk.user.inventory.mint(SKIN_ADDRESS, 1);
  await gamingSdk.user.inventory.mint(LOOTBOX_ADDRESS, 1);
 
  await gamingSdk.user.inventory.burn(NFT_ADDRESS, 1);

Dealing with achevements

  const achevements = await gamingSdk.user.current.achevements.get(ACHIEVEMENT_CATEGORY_NFT_ADDRESS);
  await gamingSdk.user.current.achevements.watch((achevementNftAddress) => {...});
 
  await gamingSdk.user.achevements.mint(userAddress, ACHIEVEMENT_NFT_ADDRESS);

Managing score

  const score = await gamingSdk.user.current.score.get(user_id, RESOURCE_NFT_ADDRESS);

Opening lootboxes

  const newItems = await gamingSdk.user.current.lootbox.open(LOOTBOX_NFT_ADDRESS);

Managing subscriptions aka auto payments

  const newSubscription = await gamingSdk.user.current.subscription.create(SUBSCRIPTION_NFT_ADDRESS, SubscriptionPeriod.Month);
  const subscription = await gamingSdk.user.current.subscription.get(SUBSCRIPTION_NFT_ADDRESS);
  await gamingSdk.user.current.subscription.watch(SUBSCRIPTION_NFT_ADDRESS, (newSubscription) => {...});
 
  const subscription = await gamingSdk.user.subscription.get(userAddress, SUBSCRIPTION_NFT_ADDRESS);

Dealing with token streams

  const newTokenStream = await gamingSdk.user.current.token_stream.create(TOKEN_ADDRESS, CONTROLLER_ADDRESS, { limit: parseUnits("3.0") });
  const userTokenStreams = await gamingSdk.user.current.token_stream.get(streamId);
  await gamingSdk.user.current.token_stream.stop(streamId);
  await gamingSdk.user.current.token_stream.watch((newStream) => {...});
  const subscription = await gamingSdk.user.subscription.get(userAddress, SUBSCRIPTION_NFT_ADDRESS);

Calling smartcontracts

Custom smartcontracts can be used by extracting ethers.js provider for users

  const provider = await gamingSdk.user.current.provider();
  const contract = new ethers.Contract(contractAddress, abi, provider);