What is MØX and how to use it

Leonardo Bonetti
9 min readFeb 16, 2022

Møx is a blockchain specialized in decentralized games, based on substrate, it is extremely robust and has native features to suit any developer who wants to create games with complex economic systems, high integrity and interoperability with other games on the network.

Entities from the MØX world

First of all, we have to understand what the entities of the møx world are

Context

The context is the simplest entity, it is basically your game, its data structure comprises only a field called owner that receives an address møx, this address is understood as the owner of the game and can create other entities below the context.

  • owner: Account that you can create the entities of your game

Actors

Actors are the entity that interacts directly with your game, they can be compared to NFTs from traditional networks, but with steroids.

Actors have the following parameters in their structure:

  • Context: The Context that this actor belongs to
  • Common Type: A numeric identifier that can be the same for multiple actors
  • Owner: Who the actor belongs to
  • Available to sale: If this actor is available for sale, any user of the møx network can sell their Actors using the network’s native tools, they don’t need to be the owner of the context for that, just the owner of the Actor
  • Price: The selling price of this Actor

Attributes

Attributes are a sub entity of Actors, they have a simple data structure that has 3 parameters:

  • Attribute ID: A hash that identifies this attribute
  • Value: a numerical value
  • Mutable: A boolean field that, if true, says the context owner can change this attribute at any time

Each Actor can have up to 200 attributes, they are used to add characteristics to your actor, such as strength points, health, if he can do something, etc.

Items

If actors can be compared to NFTs, items can be compared to fungible tokens, but with more powers.

Items have the following parameters in their structure:

  • Context: The Context that this actor belongs to
  • Total Supply: The amount of these items that exists in the network
  • Owner: The account who create this item, only context owner can create items

Actions

Actions are a sub-entity of the items, they have the power to change the attributes of the actors, they have a simple structure and easy to apply. Items can have up to 200 different actions

  • Attribute id: The id of the attribute you want to change, remembering that an attribute of the same ID can exist in several different actors, so actions are never limited to just one actor, but to an attribute that several actors can have
  • Operation: A boolean field that if true will increment the attribute value and if false it will decrement it
  • Amount: How much this action will increment or decrement the attribute

Item Balance

Item balance are another sub-entity of items, it identifies how much a møx account has a certain item and even allows you to set flags to sell the items natively on the network, even if you don’t own the context

  • Amount: The number of items you own
  • Unit Price: The price for each item
  • Available to sale: Is it available for sale or not?

How interact with network

MØX Company provides an software development kit (SDK) for this propose, this is writing in NodeJS

This SDK is a unique tool you need to work with the Møx network, It is divided into modules with very specific responsibilities to facilitate integration, but first of all you need to initialize it and connect to the node service of the network you are working on.

Let’s create a function to initialize our sdk:

In network, we define the Arpetio network, here is a list of the møx networks and what is the purpose of each one:

  • Aquarium: Network used only by møx network developers, it is extremely unstable and not recommended for common developers
  • Arpetio: A testnet that has no fees and works as a sandbox for developers who want to try out the network and its features
  • Testnet: The official møx testnet, identical to the mainnet, but the coins here have no value
  • Mainnet: The principal network of Møx

Modules

Account

The account module allows you to create and manage your Møx account, creating new key pairs, signing transactions, etc. They have the following features:

  • Create Mnemonic: Create a new random mnemonic to instantiate an account
  • Set Mnemonic: You can set your own existent mnemonic
  • Mnemonic to seed: Returns your mnemonic in a compact form, it is useful to store easily
  • Set seed: You can set your own seed
  • Enable account by mnemonic: Enable an account in the sdk using the mnemonic that was instantiated
  • Enable account by seed: Enable an account in the sdk using the seed that was instantiated
  • Disable account: Remove instantiated account
  • Public Key: Returns the public key of instantiated account
  • Get Nonce: Returns a number that is the nonce of the instantiated account
  • Sign: Assign some transaction

Let’s then create a new key pair to start using the network

Now our account is instantiated in the SDK, we can use its functions without worrying about passing our keys all the time.

Context

The context module allows performing all the functions directly linked to the context.

  • Create context: Creates a new context that will be owned by the sender
  • Transfer context: Transfer de ownership to another account

For this article, we are going to create a new game called MØX Mooners, follow the steps in the snip below to make it.

Mox Mooners is a simple combat game, where participants can buy their characters (Actors) and as they win the battles they receive Potions (Items) to increase strength, luck and health, or poisoned items, which can increase health and draw strength, etc.

The create context function returns us two data, the first of which is the Context ID, it is basically the hash of the string that we pass in the function and it will be the hash of the context in our network. The second piece of data is an UnsignedTransaction, which to propagate it to the network we use the function of the transactions module Sign And Send Transaction, it makes our life easier by automatically creating a signable payload of the data, calculating the nonce of the transaction, signing and firing to the net. Save the contextId well, we’ll need it soon.

Actor

With the Actor module we can:

  • Create Actor: Create new actor
  • Create Actor Attribute: Create new attribute for some actor
  • Remove Actor Attribute: Delete some attribute
  • Change Actor Sale Status: Here we can define if this actor is available to sale in our network and how much is this cost
  • Buy Actor: Any account can by any actor of network with available to sale status true using this function
  • Transfer Actor: You can send any actor of your ownership to another person

Our game will have 3 types of characters with different attributes, the character type will be defined in common_type, we will create 100 characters of each type and make them available for sale for 1 møx each.

The First type: Stone (111)

Here in this function we create a loop that calls the CreateStone function 100 times.

Inside Create Stone function, our first step is create a new Actor with params that we define in our business rules, so, after create Actor, we create the Strength attribute, Life Attribute, Lucky Attribute, finally we propagate the four necessary transaction to make this Actor.

Okok, if we run the code as written, we are going to do 400 transactions at once to create all the actors and their attributes, we can make the strategy more interesting if we create these actors only when a player requests the purchase of some actor.

But for now, it serves our purposes.

In order not to make this article too long, I will not replicate the process for the other actors, but if they want to implement it, the rules for them are:

The Second: Paper (112)

  • Strength: 30
  • Life: 50
  • Lucky: 100

The Third: Scissor (113)

  • Strength: 50
  • Life: 70
  • Lucky: 60

Now our players need a way to buy this actors, and it can be make using the buy function

Until now we were writing functionality that would probably stay on our backend, but now we need the player to enable their account in the SDK to buy an actor, so it’s a good idea to make this functionality present on the frontend, remember, security is everything in decentralized networks, so don’t ask your user to send his private keys to your backend or something, the møx SDK is perfectly implementable in any client side application

Items

The items module allows the following functionalities:

  • Create Item
  • Increase item supply: mint more of some existing item
  • Decrease item supply: burn items from sender
  • Create item action
  • Remove item action
  • Change item sale status: Put item for sale and define the price
  • Buy item
  • Transfer item: Send your items to another account in network
  • Consume item: You pass the item you have and some actor of your ownership and the actions of this item will be activate for the actor, in final the item is destroyed, you only can use one item per consume. If your actor has not the attribute of some action of the item, this action will be ignored

Our game will have several potions, here we will implement the poisoned health potion, which if consumed, will increase the Actor’s life and remove his strength.

Now, all of the 1000 poisoned life potions is in context owner account, he can send to anyone or anyone can buy from him.

Okay, so let’s say that some player bought or won this potion and thought it was a good idea to consume it by pointing to their Actor Stone, then he will do the following.

Storage

The last module that we will see in this article is the Storage module, it is basically like accessing the blockchain database, it makes our life easier and allows us to read any data stored on the network with the following features:

  • Get Context: Receive a context id and returns the owner
  • Get Actor: Returns the data of some actor
  • Get Actor Attributes: Returns a list of attributes that belongs to some actor
  • Get Actor Attribute: Receive a attribute id and actor id and returns the attribute data
  • Get Item: Returns an item data
  • Get Item Actions: Returns a list of item actions with his data
  • Get Item Balances: Returns a balance of some item belongs to some account, with this function you can see if someone is selling the items or not
  • Get Møx Balance: Returns a balance of møx from some account

Well, I believe that this simple dynamic presented by the game møx mooners brought clarity to how to interact with the SDK and now it’s up to your creativity to create more complex and fun dynamics that make games decentralized more than just boring activities that people do waiting get rich.

The MØX SDK has more modules, but here we go through the main ones, if you want to understand a little more about the features offered, please visit our github and go through the documentation.

To support my work and the MØX, please, share this article e follow us.

--

--

Leonardo Bonetti

Engenheiro blockchain na Sticky NFT Marketplace | Professor no IGTI MBA em Blockchain | Escritor de tecnologia | Apaixonado por metodologias de aprendizagem