Creating Game Currencies

Overview

Oftentimes, successful in-game economies are powered by an in-game currency. Players use in-game currencies as the primary medium of exchange for in-game items, player to player trading and services, purchasing upgrades, and so much more.

MetaFab makes it incredibly easy to launch one or more blockchain based in-game currencies to power your game's economy.

In this guide, we're going to cover how to quickly get your first game currency launched.

Guide

Step 1: Get your Game's credentials

If you've followed the Create a MetaFab "Game" guide, you're good to go - you should have a set of Game credentials that look something like this.

{
    "id": "c77bdae7-72a1-49ef-bf88-904d39ece5a4",
    "walletId": "20af2b18-1b1a-44db-9a0d-1e9335647db8",
    "fundingWalletId": "296ca892-f861-4970-8769-3b3c6cf23547",
    "email": "[email protected]",
    "name": "NFT Worlds",
    "rpcs": {},
    "publishedKey": "game_pk_5LCUDhbDxAuRac09GmjIEfEzkGih02x17QDvwkSlsBnEOgzJ9CZkXhOSBSju4Ea4",
    "secretKey": "SECRET_KEY_REDACTED_FOR_GUIDE",
    "updatedAt": "2022-09-27T14:11:49.836Z",
    "createdAt": "2022-09-27T14:11:49.836Z",
    "wallet": {
        "id": "20af2b18-1b1a-44db-9a0d-1e9335647db8",
        "address": "0xd3D421aa9969D9825CF803b3f600472569B99Ebe"
    },
    "fundingWallet": {
        "id": "296ca892-f861-4970-8769-3b3c6cf23547",
        "address": "0x4064Eab0155A6621D30fF09E040c61C63C3CD857"
    },
    "walletDecryptKey": "bb6aebb024c3211e44a07be2c4c4a2e6c7a4241c095d446ea834664bccb1dfc2"
}

We'll need to make note of the wallet -> address, secretKey and walletDecryptKey from our account credentials.

Step 2: Deposit Native Tokens for Currency Creation

When we create our first game currency, MetaFab will automatically deploy a specialized, prebuilt ERC20 contract to the chain of our choice. To do this, we must have an adequate amount of native token in the address of our game's wallet to cover the network deployment fees.

For this deployment, we'll be deploying to the Polygon (MATIC) chain. We'll need to deposit enough $MATIC token into our game's wallet address. We'll deposit 1 $MATIC token.

You can verify the native token balance of any wallet using the GET /v1/wallets/{walletId}/balances endpoint. You simply need to provide it with the id of the wallet you want to retrieve the balances of.

Please note - your game's wallet address is different than our example above, make sure you deposit your token into the wallet address assigned to your specific game!

Step 3: Create the Game Currency

Finally, we need to make a request to the POST /v1/currencies endpoint to create our currency. You can use the network request tool on the right hand side of our docs, or your favorite tools for interacting with REST APIs - like Postman, networking libraries, MetaFab's SDKs, etc.

In this example, we're going to create a game currency called $WRLD for our game NFT Worlds. We'll use the following argument values for the request, but you can use whatever values you'd like.

  • name: WRLD
  • symbol: WRLD (Don't include a $, just the ticker symbol you'd like assigned to your game currency)
  • supplyCap: 0 (A supply cap of 0 means that this game currency does not have a maximum token supply that can exist)
  • chain: MATIC

Additionally, we'll supply our game's secretKey for the X-Authorization header and the walletDecryptKey for the X-Wallet-Decrypt-Key header.

After we successfully make the API request to create our game currency, we'll receive a response with a Currency object that looks something like this.

{
  "id": "543711df-085d-4ac8-86e1-7f6eb97cbaf0",
  "gameId": "c77bdae7-72a1-49ef-bf88-904d39ece5a4",
  "contractId": "33b924c6-6fee-4515-a685-bf3a6451e455",
  "name": "WRLD",
  "symbol": "WRLD",
  "supplyCap": 0,
  "updatedAt": "2022-09-27T14:43:17.186Z",
  "createdAt": "2022-09-27T14:43:17.186Z",
  "contract": {
    "id": "33b924c6-6fee-4515-a685-bf3a6451e455",
    "gameId": "c77bdae7-72a1-49ef-bf88-904d39ece5a4",
    "chain": "MATIC",
    "abi": [ ...REDACTED FOR LENGTH ],
    "type": "ERC20_Game_Currency",
    "address": "0x7400C59c17CEBBD3AB607C180Dbe3d10DD6e428d",
    "updatedAt": "2022-09-27T14:43:17.187Z",
    "createdAt": "2022-09-27T14:43:17.186Z",
    "transactions": [
      {
        "id": "5af620f6-398a-437d-b50f-9c28395780b4",
        "contractId": "33b924c6-6fee-4515-a685-bf3a6451e455",
        "walletId": "20af2b18-1b1a-44db-9a0d-1e9335647db8",
        "function": "create",
        "args": [
          "WRLD",
          "WRLD",
          {
            "hex": "0x00",
            "type": "BigNumber"
          },
          "0xd501120feEe803ea5d8B81b9C9e95eC056d076f4"
        ],
        "hash": "0x3f7f8cca8042e19fdf6dc9778b172b9d4adcd1111720f211881ea087182c9d31",
        "updatedAt": "2022-09-27T14:43:17.187Z",
        "createdAt": "2022-09-27T14:43:17.186Z"
      }
    ]
  }
}

We can verify that our game currency has been deployed to the Polygon chain by taking the hash value from contract -> transaction[0] -> hash in our response object and searching it on Polygonscan. For example: https://polygonscan.com/tx/0x3f7f8cca8042e19fdf6dc9778b172b9d4adcd1111720f211881ea087182c9d31

Step 4: Done!

You've successfully deployed your first game currency that your players can now trade with, earn and more! Use MetaFab's Currency related API endpoints to interact with your newly created currency.

We'll cover how your players can interact with your game currency(s) in the next guide.

You can create as many currency types as you like and implement them as you see fit for your game. For example, you may want to create a game currency for your game's different resource types (Wood, Metal, Water, etc) or perhaps different tiers of currency such as Gold, Silver, Copper - the choice is yours!

πŸ“˜

Consideration: Cross-Chain Currency Bridging

MetaFab supports out of the box bridging for your game currencies between the Ethereum and Polygon networks, with future bridging support to other chains like Binance Smart Chain and more in the future.

Bridging your game currencies between chains is out of the scope of this guide. Head over to our Discord to get details on how to bridge your game currencies.