NFT Collection API Example

The following example shows the necessary steps to creating an NFT collection and adding an item to a player's balance.

πŸ“˜

ERC-721

On EVM chains, this deploys an ERC-721 smart contract

Create Collection

The first step in creating an NFT (non-fungible token) is to create a Collection. This can be done by calling the Create NFT Collection endpoint.

{
  "publicMetadata": {},
  "gameId": "{{gameId}}",
  "name": "Players",
  "description": "Unique collection of game players",
  "image": "img.url",
  "symbol": "PLAYER",
  "blockchainId": "{{blockchainId}}",
  "totalSupply": "100000"
}
{
    "symbol": "PLAYER",
    "blockchainId": 7,
    "id": "c0292c0f-793f-4ba0-884c-8129c689f2c6",
    "gameId": 3000,
    "name": "Players",
    "type": "NFT",
    "description": "Unique collection of game players",
    "image": "img.url",
    "publicMetadata": {
        "name": "Players",
        "description": "Unique collection of game players",
        "image": "img.url"
    },
    "address": "0xE101b49B5fb3b7A3C846319723D73b826D94d0dA",
    "totalSupply": "100000"
}

In the response will be an id for the Collection, along with other data including an address that represents the smart contract address on-chain.

Create Item

Once the Collection is created, an Item can be created. This can be done by calling the Create Item endpoint. NFT Items will always have a totalSupply of 1.

{
  "publicMetadata": {},
  "collectionId": "c0292c0f-793f-4ba0-884c-8129c689f2c6",
  "gameId": "{{gameId}}",
  "name": "Player 1",
  "description": "The one-and-only Player 1",
  "image": "img.url",
  "blockchainId": "{{blockchainId}}"
}
{
    "blockchainId": 7,
    "currentSupply": "0",
    "publicMetadata": {
        "name": "Player 1",
        "description": "The one-and-only Player 1",
        "image": "img.url"
    },
    "collectionId": "c0292c0f-793f-4ba0-884c-8129c689f2c6",
    "gameId": 3000,
    "name": "Player 1",
    "description": "The one-and-only Player 1",
    "image": "img.url",
    "totalSupply": "1",
    "id": "9f3483f3-1ac3-4444-beac-91e8cea30d64",
    "address": "1"
}

In the response will be an id for the Item, along with other data including an address that represents the blockchain token id on-chain.

Add Item Balance

Once the Item has been created, it can be added to a Player's wallet. This is done by calling the Add Item Balance endpoint. Only an amount of 1 is allowed for this item type.

{
  "itemId": "9f3483f3-1ac3-4444-beac-91e8cea30d64",
  "playerId": "0ff81141-52d6-48d8-bda1-5d83c9ec7201",
  "amount": "1"
}
{
    "gameId": 3000,
    "playerId": "0ff81141-52d6-48d8-bda1-5d83c9ec7201",
    "itemId": "9f3483f3-1ac3-4444-beac-91e8cea30d64",
    "id": "c507f3a8-a978-43b9-9784-841b2179ede0",
    "amount": "1",
    "item": {
        "blockchainId": 7,
        "currentSupply": "1",
        "id": "9f3483f3-1ac3-4444-beac-91e8cea30d64",
        "collectionId": "c0292c0f-793f-4ba0-884c-8129c689f2c6",
        "gameId": 3000,
        "totalSupply": "1",
        "publicMetadata": {
            "name": "Player 1",
            "description": "The one-and-only Player 1",
            "image": "img.url"
        },
        "name": "Player 1",
        "description": "The one-and-only Player 1",
        "image": "img.url",
        "address": "1"
    }
}

To see all of a Player's Item Balances, call the endpoint List Item Balances.