SteemGG SDK - A Steem Blockchain Toolkit for Game Developers

@steemgg · 2019-02-24 09:12 · utopian

Introducing the SteemGG SDK


Following a few months of hardwork, our developers have finally completed the first stages of the SteemGG SDK, a toolkit for HTML5 game developers to allow them to have their games interacting with the Steem Blockchain through the SteemGG server. In particular, with the first stage, we have implemented the functionality of load and save games, score leaderboard, and getting user information.

Wiki Page: https://github.com/steemgg/steemgg-website/wiki/SteemGG-SDK Online Testing Tool: https://steemgg.github.io/steemgg-website/sdk-toolkit.html Demon: https://steemgg.com/#/game/play/53

What is SteemGG SDK


SteemGG SDK is a javascript library which game developers can leverage to interact with the SteemGG website and the Steem Blockchain, like save/retrieve the game record to the Blockchain via the SteemGG server, get leader board data, get current user information, etc.

How to get the SDK


The easiest way would be put the following tag into the index.html of your game


Or you can call

npm install steemgg-sdk

to get the steemGG sdk module installed and import the steemgg.sdk.js in your game file

How to use the SDK


After you include the sdk javascript to your game, a global variable steemGG is available. there are several APIs you can call:

steemGG.setKey()
steemGG.setGameRecord(record)
steemGG.getGameRecord()
steemGG.getLeaderBoard()
steemGG.getCurrentUser()

and a special one

steemGG.setDebugMode(true|false)

To start to use the SDK, the normal steps are as follows:

1)You must first set the API key to the sdk by calling steemGG.setKey(apiKeyOfYourGame), the key is used to encrypt and decrypt the record between client and the server to prevent user from sending fake record. You can find the API key of your game in the game editing form:

image.JPG

2)Load the existing game record for the current user by simply calling

steemGG.getGameRecord

A typical game record looks like this:

{
    "id": 3141,         <---- current game id
    "userId": "user1",  <---- current user id
    "customField": {    <---- a custom field, which developer can store any custom fields they want
        "score": 90,     <---- Note: 'score' is a special field, the value stored in
                              this field will be used to generate the leader board
        "key1": "xxx",
        "key2": "yyy",
        ...
    }
}

then initialise the game based on current user's record, if there is no existing record, it will be a empty JSON.

3)Use the steemGG.setGameRecord(record) method to store the record back to the server. A typical game record to be stored looks like this:

{
    "id": 3141,         <---- current game id
    "userId": "user1",  <---- current user id
    "customField": {    <---- a custom field, which developer can store any custom fields they want
        "score": 90,     <---- Note: 'score' is a special field, the value stored in
                              this field will be used to generate the leader board
        "key1": "xxx",
        "key2": "yyy",
        ...
    }
}

Put any data you need under the customField property of the record JSON object. Make sure you get the id and userId field set as well. Note: You can get the current user by calling steemGG.getCurrentUser

4)If your game needs a leader board, when you save the record, you can set the special property score under the customField, the value must be a Number and will be used to rank the user record.

Getting the leader board


After setting the score field, a leader board will be generated for you game automatically. You can get the leader board data for your game by calling

steemGG.getLeaderBoard()

The leader board data will be in format:

[
    "user1",
    "200",
    "user2",
    "200",
    "user3",
    "99"
]

Sample page


To make the testing easier, we have a toolkit page which you can load your game into and check whether your code is getting and setting the correct record. The sample page is here: SteemGG SDK Toolkit. When you are testing your game inside the SDK, make sure you set it to debug mode by calling:

steemGG.setDebugMode(true)

so there will be no encryption, which makes it easier to check the data your game sends. It also means you don't need to call steemGG.setKey in debug mode.

Coming next


A few new features will be coming soon which will allow the game to:

  • adjust the height of the game view
  • toggle full-screen mode
  • define more leader board fields (currently only support one based on the score field)
  • Upvoting inside the game
#utopian #blog #steemdev #gaming #development
Payout: 0.000 HBD
Votes: 55
More interactions (upvote, reblog, reply) coming soon.