PLYR GAMING UNIVERSE
  • API Endpoint
  • API Quickstart
  • API REFERENCE
    • Users
      • Authentication
        • PLYR[ID]
          • Login
          • Login and Approve
          • Logout
        • InstantPlayPass
          • RegisterIPP
          • RevealClaimingCode
          • VerifyClaimingCode
        • PLYR[CONNECT]
      • Check Session JWT
      • Get Basic User Info
      • Get Avatar
    • Game room
      • Create Game Room
      • Join Game Room
      • Pay Game Room
      • Earn Game Room
      • Leave Game Room
      • End Game Room
      • Helpers
        • Is Joined Game Room
        • Join and Pay
        • Earn and Leave
        • Create, Join and Pay
        • Earn, Leave and End
    • Assets
      • Tokens ( ERC-20 )
        • Get PLYR L1 Token List
        • Get User Token Balance
        • Get User Token Allowance
        • Approve User Token Spending
        • Revoke User Token Allowance
        • In-Game Chips
          • Create Chip
          • Mint Chip
          • Burn Chip
          • Transfer Chip
          • Get Chip Balance
          • Get Chip Info
      • NFTs ( ERC-721 )
        • Create NFT
        • Mint NFT
        • Transfer NFT
        • Burn NFT
        • Get NFT Balance
        • List NFTs
        • Check NFT Holding
        • Get NFT Credit
        • Get NFT Info
        • Get Zoo Genes
        • Official PLYR NFTs
          • Get User Zoo Genes
          • Get User Zoo Boosters
          • Get User Zoo Elixirs
      • Badge
        • Create Badge
        • Mint Badge
        • Remove Badge
        • Burn Badge
        • List Badges
        • Get Badge Info
    • Misc
      • Get Session JWT Public Key
      • Verify JWT Locally
      • Activity Logs
      • Get Task Message Status
Powered by GitBook
On this page
  • Prerequisite
  • Basic to Call our API
  • Base Headers
  • Header Requirements
  • HMAC Signature Generation
  • Example 1: GET Method API without Body Payload.
  • Example 2: POST Method API with Body Payload.

API Quickstart

Things to know before using an API

PreviousAPI EndpointNextUsers

Last updated 4 months ago

Prerequisite

  • You need to signup PLYR[ID] first on both and . This PLYR[ID] gonna be a "Developer account and Game ID". Please set a name to be related with your game name.

  • API KEY and SECRET KEY — After you signup the PLYR[ID]. You can request us to generate API KEY Pair.

Basic to Call our API

We use "Timestamp + Body Payload" and signs with SECRET KEY as a HMAC (SHA256) signature. You need to include custom header apikey, signature, timestamp every time to call our API.

Base Headers

Every API request must include these base headers:

{
    apikey: string; // Your API key obtained from the developer portal
    signature: string; // HMAC signature of the request
    timestamp: string; // Current timestamp in milliseconds (Date.now().toString())
}

Header Requirements

Format Requirements:

- Headers are case-sensitive
- Values must be strings
- Timestamp must be in milliseconds

HMAC Signature Generation

// Example signature generation
const timestamp = Date.now().toString();
const payload = JSON.stringify(requestBody);
const message = timestamp + payload;
const signature = crypto.createHmac('sha256', secretKey).update(message).digest('hex');

Always keep your API key and secret key secure. Never expose them in client-side code or public repositories.

Example 1: GET Method API without Body Payload.

Let see the example of "userInfo" API endpoint.

// Generate HMAC signature from timestamp + body //
const crypto = require('crypto');
const axios = require("axios");

const APIKEY = ''; // your api key
const SECRETKEY = ''; // you api secret key 

function generateHmacSignature(timestamp, body, secretkey) {
  const bodyString = JSON.stringify(body);
  const data = timestamp + bodyString;
  return crypto
    .createHmac('sha256', secretkey)
    .update(data)
    .digest('hex');
}

const timestamp = Date.now().toString();
const apiEndpoint = 'https://api-testnet.plyr.network/api';
const searchText = 'cyptofennec'; // PLYR[ID]
let hmac = generateHmacSignature(timestamp, {}, SECRETKEY); // If API required body payload (POST method) just pass the object //
let ret = await axios.get(
            apiEndpoint + "/api/user/info/" + searchTxt + '/',
            {
                headers: {
                    apikey: APIKEY,
                    signature: hmac,
                    timestamp: timestamp,
                },
            }
        );
console.log("ret data",ret.data);
{
  plyrId: "cyptofennec",
  mirrorAddress: "0x4eaf4CE71c42758b2D4B4C23E543e1D98c8dE9C6",
  primaryAddress: "0x6Ab499c8E2f3CBc9C99034b6e2912149212bE770",
  chainId: 62831,
  avatar: "https://ipfs.plyr.network/ipfs/QmfMhXz8vqBDMHVVstnK8tykmhAN6oXv5xZunC3SXR1NWL",
  createdAt: "2024-08-05T12:48:30.429Z",
  ippClaimed: false,
  isIPP: false
}

Example 2: POST Method API with Body Payload.

Let see the example of "getAvatars" API endpoint.

// Generate HMAC signature from timestamp + body //
const crypto = require('crypto');
const axios = require("axios");

const APIKEY = ''; // your api key
const SECRETKEY = ''; // you api secret key 

function generateHmacSignature(timestamp, body, secretkey) {
  const bodyString = JSON.stringify(body);
  const data = timestamp + bodyString;
  return crypto
    .createHmac('sha256', secretkey)
    .update(data)
    .digest('hex');
}

const timestamp = Date.now().toString();
const apiEndpoint = 'https://api-testnet.plyr.network/api';
let body = {
    plyrIds: ['fennec2', 'cyptofennec']
}
let hmac = generateHmacSignature(timestamp, body, SECRETKEY);
let ret = await axios.post(
            apiEndpoint + "/api/user/avatars",
            body,
            {
                headers: {
                    apikey: APIKEY,
                    signature: hmac,
                    timestamp: timestamp,
                },
            }
        );
console.log("ret data",ret.data);
{
  avatars: [
    {
      plyrId: "cyptofennec",
      avatar: "https://ipfs.plyr.network/ipfs/QmfMhXz8vqBDMHVVstnK8tykmhAN6oXv5xZunC3SXR1NWL"
    },
    {
      plyrId: "fennec2",
      avatar: "https://ipfs.plyr.network/ipfs/QmYHv8HJ6SDGbGkMDwfVfXehpNNGvPrB8W2dXnd26CpPYL"
    }
  ]
}
Mainnet
Testnet