Show the API playground after starting the game

Hi. Today, we're going to demonstrate what can be done with core API that is scheduled to be updated in late February. Nine Chronicles is a serverless game, so there is no central API server, but you can use the graphql interface locally by running the client. Currently, NCG transfer is only available through API, so those who have done NCG transactions will be familiar with it.

After launching the game launcher, open the Internet browser and access http://localhost:23061/ui/playground to load the graphql playground. In addition to the official client, Headless builds can be used, so when developing public services, it is recommended to use Headless, which is easy to run on a server computer.

Accessing agent and shop data from the playground

First, we will search the store information through the playground and buy the desired item. Key information in the game can be inquired through querystateQuery. First, we will obtain the player's avatar address to facilitate the inquiry. This can be queried with an agent query, and then details can be viewed through an avatar query.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/76b15215-2ffc-4720-9b83-6e834271c8c6/Untitled.png

The agent's address can be copied from the launcher's login screen or from the bottom right.

query {
  stateQuery {
    agent(address: "0xA116d45d176aeD204a7627A470e87907e57BE6CD") {
      avatarAddresses
    }
    avatar(address:"0x122a60B6a56CC0D23Aad4A07c9E724d49044eB6D") {
      actionPoint
      level
      agentAddress
    }
  }
}
{
  "data": {
    "stateQuery": {
      "agent": {
        "avatarAddresses": [
          "0x122a60B6a56CC0D23Aad4A07c9E724d49044eB6D"
        ]
      },
      "avatar": {
        "actionPoint": 100,
        "level": 158,
        "agentAddress": "0xA116d45d176aeD204a7627A470e87907e57BE6CD"
      }
    }
  },
  "extensions": {}
}

In the game, there is a difference between the properties managed by the agent and the properties managed by the avatar. For example, gold is managed per agent and equipment are managed per avatar. Since the purchase of products is a transaction between avatars, we will use our avatar address in a little while.

Ok, then let's get the store information. If you use the playground's SCHEMA tab, you can check the information of the data that can be imported, and the auto-complete function is also provided so you can conveniently check the information. In this demo, I will search for foods less than 100 Gold.

query {
  stateQuery { 
    shop {
      products(itemSubType:FOOD, maximumPrice: 100) {
        itemUsable {
          id
          itemId
        }
        price
        sellerAgentAddress
        sellerAvatarAddress
        productId
      }
    }
  }
}
{
  "data": {
    "stateQuery": {
      "shop": {
        "products": [
          {
            "itemUsable": {
              "id": 201005,
              "itemId": "d19ca62e-3504-4ca7-83db-f0041ff47706"
            },
            "price": "20 NCG",
            "sellerAgentAddress": "0x2609F8e941caB431F68Ec2772D963F5006341C7c",
            "sellerAvatarAddress": "0x16741aa2387ad785d45D154293B7dC98C3A8e084",
            "productId": "13e1de91-9271-40bb-86b7-c53140b62838"
          },
          {
            "itemUsable": {
              "id": 201011,
              "itemId": "40fb0509-7f63-4815-a51d-3a976ea17ded"
            },
            "price": "28 NCG",
            "sellerAgentAddress": "0x3a3aDe342Dd061cCb1B7b4a011d7648fb509e441",
            "sellerAvatarAddress": "0xB781D43C5258e480f202EAEd4811ee05f680F797",
            "productId": "5e699ecb-5055-4233-a229-0d309a74e387"
          }
        ]
      }
    }
  },
  "extensions": {}
}

Create a buy action and check whether the transaction id has been incorporated

By using the graphql API, you can make transactions by executing mutations. For example, let's buy this item. Before executing, you need to log in.

mutation {
  action {
    buy(
      buyerAvatarAddress:"0x122a60B6a56CC0D23Aad4A07c9E724d49044eB6D",
      sellerAgentAddress: "0x2609F8e941caB431F68Ec2772D963F5006341C7c",
      sellerAvatarAddress: "0x16741aa2387ad785d45D154293B7dC98C3A8e084",
      productId: "13e1de91-9271-40bb-86b7-c53140b62838")
  }
}
{
  "data": {
    "action": {
      "buy": "de5b3897f12b0d3f0387fc9572ea35c648a740106e2ac31e0bd138646417f2da"
    }
  },
  "extensions": {}
}

After execution is finished, you can see that the transaction id is returned by the actionbuy key as follows. All actions are not immediately executed, but a transaction is created and propagated to the network in this way, and the actual execution is completed when the transaction is incorporated into a block and connected to the chain. Therefore, you need to check the transfer status by looking up the transaction id. You must enter your own address as argument.

query {
  nodeStatus {
    stagedTxIds(address: "0xA116d45d176aeD204a7627A470e87907e57BE6CD")
  }
}
{
  "data": {
    "nodeStatus": {
      "stagedTxIds": [
        "de5b3897f12b0d3f0387fc9572ea35c648a740106e2ac31e0bd138646417f2da"
      ]
    }
  },
  "extensions": {}
}

Transaction ids that have not yet been added to the block can be checked in stagedTxIds. It will be removed when the incorporation into the block is confirmed, so if the stageTxIds list is empty as above, it can be assumed that the corresponding transaction has entered the block.

Action completion and viewing status