npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cere/games-sdk

v0.7.3

Published

Cere Games SDK to integrate games with CERE infrastructure

Downloads

50

Readme

Cere Games SDK

Cere Games SDK is an NPM package which allows a game developer to easily integrate with CERE infrastructure & DDC interaction. The SDK provides methods to fetch/update player score, display UI components based on game settings.

Installation

Using NPM:

npm install @cere/games-sdk --save

Using yarn:

yarn add @cere/games-sdk

API

GamesSDK

The constructor creates uninitialized SDK instance

import { GamesSdk } from '@cere/games-sdk';

const gamesSdk = new GamesSdk({
  env: 'dev',
  gameId: 'tower-game',
  gameInfo: {
    name: 'Tower Game',
    tags: ['towergame', 'web3', 'gamer'],
    url: window.location.href,
    logoUrl: 'http://...',
  },
  onReady: () => {
    console.log('The SDK is ready!');
  },

  onWalletDisconnect: () => {
    console.log('The Wallet has been disconnected');
  },
});

Parameters

  • env - the SDK environment. Can be one of the following:
    • local - loads all its dependencies from local environment (localhost)
    • dev - loads all its dependencies from the development environment
    • stage - loads all its dependencies from the stage environment
    • prod - loads all its dependencies from the production environment
  • gameId - unique game identifier
  • gameInfo - additional information about the game
    • name - name of the game
    • tags - list of tags
    • url - public game URL
    • logoUrl - URL to the game's logo image
  • onReady - a callback called when the SDK is initialized and ready for interactions
  • onWalletDisconnect - a callback called when the Wallet is disconnected by player

wallet

Pre-configured Cere Wallet instance

// Get wallet accounts
const accounts = await gamesSdk.wallet.getAccounts();

console.log('Connected wallet accounts', accounts);

// Transfer tokens
const txHash = await gamesSdk.wallet.transfer({
  token: 'CERE',
  to: '...',
  amount: 10,
});

console.log('Connected wallet accounts', accounts);

init()

This method initializes the SDK. It also performs the following tasks:

  • Registers UI elements (Web Components)
  • Configures and initializes Cere Wallet
  • Calls onReady callback
await gamesSdk.init();

showPreloader()

This method shows Preloader modal window which covers entire screen.

const preloader = gamesSdk.showPreloader({
  onStart: () => {
    // Start the game
  },
});

Parameters

  • onStart - a callback which is called when player requests to start the game by clicking on Start button

The method returns a preloader modal instance of the following type:

type Preloader = {
  readonly isOpen: boolean;
  open: () => void;
  close: () => void;
  setReady: (isReady: boolean) => void;
};

When the game logic should call setReady method when its assets are fully loaded. It will enable Start button in the preloader modal.

function onGameAssetsLoaded() {
  preloader.setReady();
}

showLeaderboard()

This method shows Leaderboard modal which covers entire screen.

const modal = gamesSdk.showLeaderboard({
  onPlayAgain: () => {
    // Re-start the game
  },

  onBeforeLoad: () => {
    // Check if the wallet is connected or save unsaved player score
  },
});

Parameters

  • onPlayAgain - a callback which is called when player requests to play the game again by clicking on Play Again button
  • onBeforeLoad - a callback which is called right before the leaderboard data is requested

The method returns a modal instance with the following type:

type Modal = {
  readonly isOpen: boolean;
  open: () => void;
  close: () => void;
};

showConnectWallet()

This method shows Connect Wallet modal which covers entire screen. The modal asks the player to connect their Cere Wallet.

const modal = gamesSdk.showConnectWallet({
  score: 20,
  onConnect: () => {
    // The wallet is connected
  },
});

Parameters

  • score - current player score to be shown on Wallet Connect UI
  • onConnect - a callback which is called when player connects their wallet
  • onComplete - a callback which is called wallet connect is completed and the modal is closed

The method returns a modal instance with the following type:

type Modal = {
  readonly isOpen: boolean;
  open: () => void;
  close: () => void;
};

saveScore()

This method shows saves the player score to DDC.

await gamesSdk.saveScore(500);

Parameters

  • score - the player current score