To build our Azura Chain and make it EVM-compatible on Cosmos Network, we will develop the custom EVM module in our project, since Cosmos SDK does not provide EVM modules by default. Azura Chain allows users to deploy Ethereum-compatible smart contracts on Azura Chain for smooth execution without modification.
This figure shows the technical architecture of Azura. It helps explain how Azura works and functions technically.
At the top layer, it shows that Azura will utilizes some Cosmos SDK standard modules, such as Auth
, Bank
, Distribution
, Governance
, NFT
, Staking
, IBC
, etc. Moreover, some custom modules will be developed by Azura like EVM
and other gaming modules as needed. These modules interface with the ABCI layer, which facilitates communication between the application logic and the consensus engine. At the bottom layer, the Tendermint Consensus (CometBFT) mechanism ensures consensus across the blockchain network.
Here are the summarized steps to build Azura Chain on Cosmos:
The key features and supports of Azura Chain are summarized as follows:
Azura Chain features a set of modules for functionality, leveraging both its own and Cosmos SDK modules. The modules utilized or created by Azura Chain are listed below.
Module | Description | Key Features |
---|---|---|
Auth | Manages account, transaction authentication / authorization | * Secure identity management * Transaction validation |
Bank | Handles basic token operations | * Transfers between accounts * Minting, burning, supply |
Governance | Enables on-chain governance mechanism | * Proposal submission * Voting and decision-making |
NFT | Supports creation, management, transfer of NFT | * Essential for applications requiring unique digital asset representation |
Staking | Implements Proof-of-Stake consensus mechanism | * Allows validators to stake tokens and earn rewards |
Distribution | Manages the distribution of staking rewards | * Fair and transparent reward allocation to validators / delegators |
IBC | Enables interoperability between different blockchains | * Cross-chain token transfers * Inter-chain communications |
EVM | Enables Ethereum compatibility on Cosmos Nework | * EVM-compatible smart contracts deployment & interaction support |
Here are the gaming custom modules provided by Azura. For more details about these modules, please refer to the Azura Custom Gaming Modules section.
Gaming Module | Description |
---|---|
Player Profiles | Stores player statistics, achievements, and rankings |
Matchmaking | System for finding and creating multiplayer game matches |
Asset Management | NFT-like functionality for in-game assets supporting minting, burning, and transfers |
Game State Management | Efficient storage and retrieval of game states, including saving and loading game progress |
Random Number Generation | Integrates a Verifiable Random Function (VRF) and transparent randomness |
Governance Integration | Enables on-chain governance of game parameters and rules |
State Channels | Off-chain gameplay with periodic on-chain settlements |
Interoperability | Uses IBC to support cross-chain asset transfers and game interactions |
Gas Optimization | Features to optimize gas costs for frequent game actions |
AI Integration | Provides hooks to integrate AI services for NPC behavior, dynamic difficulty adjustment, etc. |
To follow the specific structure of Cosmos SDK modules, Azura should create new modules within the x
directory in the repository. In Cosmos SDK-based projects, including Azura, the x
directory is a convention for organizing and naming directories that contain custom modules. It helps distinguish between the SDK's core modules and those added by Azura for specific functionalities.
Inside the x
directory, each custom module typically has its own directory named after the module. These custom modules can introduce new features, manage application-specific states, handle custom messages, and define unique application logic (i.e., game logic) beyond the standard Cosmos SDK modules. In a new module's directory, there are several default subdirectories, such as client
, keeper
, module
, types
, and more.
Azura will implement various components for a custom module:
client
: Manages user interactions with the Azura Chain node through multiple interfaces: CLI, REST API, and gRPC.keeper
: Defines methods for accessing and modifying the module's state, serving as an interface between state and game logic.module
: Integrates the custom module into the Cosmos SDK application, defining routes, handlers, and overall module structure.simulation
: Simulates tests to evaluate module behavior under various conditions.types
: Contains definitions for data structures used throughout the module, including messages, queries, states, and parameters.docs
: Contains documents describing the module's design, functionality, and usage.This diagram outlines a simplified interaction flow of a custom module in the Cosmos SDK for Azura, demonstrating how a game message is processed from different interfaces to handling the response.
Client
component.Client
then forwards the message to the Module
for routing and handling, based on the defined messge type.Module
interacts with the Keeper
, which carries out the necessary game logic and state transition rules using the received message.Keeper
back through the Module
and Client
to the original user interfaces.To explain this more practically, a simplified implementation example is presented in the next section: Gaming Logic Implementation on Azure Chain.
After creating and defining a new custom module, additional steps are required after the implementation, such as:
app/app.go
, which is the main entry point for defining and configuring the Cosmos SDK application.cmd/azurad/cmd/commands.go
for interacting with the module (azurad
is the abbreviation for Azura Daemon, which is a customized Azura CLI).proto
if the new module defines new message types, queries, or state structures.Note that the app/ibc.go
file handles the setup and configuration of IBC module within the application.
At the implementation level, there are two approaches to executing game logic on Azura Chain. One approach is to define the logic directly on the chain, while the other is to deploy EVM-compatible smart contracts as the logic on the chain. To easily understand the implementation of game logic on Azura Chain, consider the example of a simple custom module for gaming called Game State (module named gamestate
) presented in the following subsections.
As mentioned earlier, the directory x/gamestate/types
defines the messages, queries, states, and parameters used by the module. In messages.go
, we define the messages and parameters needed for the game.
where ModuleName
and StoreKey
are constants used to identify the module and its storage key in the Cosmos SDK. GameState
struct represents the core data of a game state, containing a PlayerID
(string) and a Score
(integer). MsgSaveGame
struct defines the message structure for saving a game state. It mirrors the GameState
structure and is used as the input for transactions to save game states.
As mentioned earlier, the directory x/gamestate/keeper
handles game logic and state transition rules. It manages the game state, including the ID and score of the player, as defined in keeper.go
.
where Keeper
struct manages the module's state storage, holding a storeKey
for accessing the module's storage. NewKeeper
is a constructor for creating a new Keeper
instance. SetGameState
stores a GameState
in the module's storage. It serializes the state to JSON format and uses the PlayerID
as the key. GetGameState
retrieves a GameState
from storage using the PlayerID
. It deserializes the JSON data and returns the state indicating whether the state was found.
After we have defined the messages, parameters and keeper, the next step involves setting up a message handler. This handler will be responsible for processing the message MsgSaveGame
in module.go
.
where NewHandler
creates a new handler function for processing module messages. It uses a switch statement to route different message types to their respective handlers. handleMsgSaveGame
is the specific handler for MsgSaveGame
messages. It creates a GameState
from the message and uses the Keeper
to save it, which the function SetGameState
executes the logic of Game State in keeper.go
.
This approach is quite different from the Cosmos SDK module-based implementation when using smart contracts. The game logic included in the contract defines, stores, and retrieves the game state. Here is a simplified smart contract example of GameState
module.
After implementing and compiling this Solidity smart contract, we can proceed by deploying them to the Azura Chain. The deployment and interaction process will follow the same steps and methods on Ethereum.