Back to all Developer Hub

Store User Data on Dragon 1 Guide - Cere Games SDK Integration Guide

Introduction

This guide demonstrates how to integrate the Cere Games SDK into your game, enabling you to store user data, such as game scores and leaderboards, on Dragon 1 - the first data cluster in Cere's Decentralized Data Cloud (DDC). By following this tutorial, you'll learn how to upgrade your existing game with web3 features, including decentralized leaderboards and score tracking.

Prerequisites

Before you begin, make sure you have:

  • Basic knowledge of Node.js and JavaScript
  • An existing browser-based game (we'll use the open-source TowerGame as an example)
  • A unique Game ID for your project
  • Node.js and npm installed on your machine

Integration Steps

Install the Cere Games SDK

Install the SDK using npm by running the following command in your project directory:

npm install @cere/games-sdk

Initialize the Cere Games SDK

Create a new file called games-sdk.js in your project root and add the following code:

const { GamesSDK } = require("@cere/games-sdk");

window.CereGamesSdk = new GamesSDK({
  gameId: '0xTowerGame', // Replace with your unique Game ID
  gameInfo: {
    name: '0xTowerGame',
    tags: ['towergame', 'web3', 'gamer'],
    url: window.location.href,
    logoUrl: "http://..." // Add your game's logo URL
  },
  onReady: (sdk) => {
    window.gamesSdkPreloader = sdk.showPreloader({
      onStart:() => {
        document.getElementById('start')?.click();
      }
    });
  },
});

window.CereGamesSdk.init();

Make sure to replace '0xTowerGame' with your unique Game ID and update the gameInfo object with your game's details.

Launch the Pre-loader Modal

In your main game file (e.g., index.html), add the following code to launch the pre-loader modal when the game assets are loaded:

function hideLoading() {
  if (domReady && canvasReady) {
    // Your existing code here
    window.gamesSdkPreloader.setReady();
  }
}

This will display the Cere Games pre-loader modal once your game is ready to start.

Save Scores & Show the Leaderboard

Integrate score saving and leaderboard display in your game logic. For example, when a player's game ends:

setGameFailed: function (f) {
  // Your existing game over logic
  window.CereGamesSdk.saveScore(score).then(() => {
    window.CereGamesSdk.showLeaderboard({
      onPlayAgain: () => {
        // Restart the game
        window.location.href = window.location.href + '?s=' + (+new Date());
      }
    });
  });
}

This code saves the player's score to Dragon 1 and then displays the leaderboard.

Deploy Your Game to Dragon 1

To upload your game to DDC and leverage decentralized storage for user data:

  1. Prepare a zip archive of your game assets: npm run buildzip -r yourgame-v1.zip ./your-game-directory/
  2. Upload the archive using Freeport:
    • Open Freeport Creation Suite
    • Connect your wallet (e.g., MetaMask)
    • Enter the Game admin panel
    • Click "Add game"
    • Fill in the game information and upload your zip file
    • Sign the transaction with your wallet
  3. Configure Game Properties in Freeport

Setting Up and Managing Tournaments

After uploading your game to Dragon 1, you gain the ability to create and manage tournaments for your players. This feature allows you to organize competitive events and engage your player base.

Creating a Tournament

You can create a tournament in two ways:

1. During the game upload process:

  1. At the second step of the upload wizard, click on the Setup tournaments button

2. From the game list page:

  1. Click on the Setup tournament leaderboards button in the drop-down list for your game.

After selecting either option, you'll be directed to the tournament creation page:

  1. Fill in all the required fields for your tournament, such as:
    • Tournament name
    • Description
    • Start and end dates
    • Any special rules or conditions
  2. Click the Create tournament button

Viewing and Editing Tournaments

After successfully creating a tournament:

  1. You can view all created tournaments on the tournament list page.
  2. To edit a tournament:
    • Click the edit button in the tournament's row.
    • A pre-filled form will open where you can modify the tournament details.
    • Click the Save changes button to update the tournament.

Tournament Status

Tournaments have two status types:

  1. Active: For tournaments that haven't occurred yet.
  2. Past: For tournaments that have already taken place.

For tournaments with the "Past" status, you have the option to upload the results.

Downloading Tournament Results

To download the results of all tournaments:

  1. Go to the page with the list of games.
  2. Click on the Download all tournament results button.

This feature allows you to analyze player performance across multiple tournaments and track long-term player engagement.

Local Testing

After uploading your game and configuring properties in Freeport, you can test your game locally:

npm start

This will start a local server, and your game should open in a new browser window. You'll be able to test the Cere Games SDK integration, including the pre-loader modal, score saving, and leaderboard display.

Feature Roadmap

Stay tuned for upcoming features that will enhance your game's capabilities:

  • Rewards Configuration Wizard: Set up NFT or token rewards for tournament winners or players meeting certain conditions.
  • Welcome Banner Configuration Wizard: Customize the welcome message and image displayed in the pre-loader modal.

Conclusion

By integrating the Cere Games SDK, you've successfully enabled your game to store user data (scores and leaderboards) on Dragon 1, leveraging the power of decentralized storage. This integration provides a seamless way to add web3 features to your existing games, enhancing the user experience with decentralized leaderboards and score tracking.

The tournament feature allows you to create engaging competitive events for your players, further increasing player retention and providing valuable user data that is securely stored on Dragon 1.

Remember to regularly check for updates and new features in the Cere Games SDK to continually improve your game's web3 capabilities and player experience.

Meet the Cere Community!

For further assistance or to connect with other developers, join the Cere Network community on Telegram or Discord.

If you have any feedback or encounter any bugs, please let us know at https://cere.network/feedback.

Remember, DDC is continually evolving, so always refer to the official documentation for the most up-to-date information and best practices.

The game developer has the ability to arrange tournaments for their players.

After uploading your game, it becomes possible to add tournaments, this can be done in several ways:

  • at the second step, click on the Setup tournaments button
  • by clicking on the Setup tournament leaderboards button in the drop-down list on the game list page

Next, you get to the page with the creation of tournaments, where you need to fill in all the required fields and click the Create tournament button.

After successfully creating a tournament, you will be able to view all created tournaments and edit them if necessary.

You can edit the tournament by clicking on the edit button in the line. A pre-filled tournament form will open, where you can change the values of the required fields. You can save the changes by clicking on the Save changes button.

If the tournament has’t passed yet it will have the Active status. If the tournament has already passed, then it will be with the Past status.

For tournaments with the Past status, it is possible to upload the results

You can download the results of all tournaments on the page with the list of games by clicking on the Download all tournament results button

Get Started