The Convergence of Blockchain and Gaming

An Open Source Tool for Connecting Conflux Network and Gaming

Conflux Network
Published in
8 min readNov 19, 2020

--

Written by Conflux Network’s Research Engineer Aaron Lu

Blockchain and gaming is a rapidly evolving space. The days of Cryptokitties in 2017 have evolved into the creation of metaverses or battle-royale games where assets are tracked on a blockchain’s immutable ledger with non-fungible tokens (NFTs). While the blockchain gaming space has seen an explosion of growth with over $2.1 million in trading volume (as of November 17, 2020), it is only a small sliver of the gaming industry that is valued at $155 billion and includes established giants such as League of Legends and Minecraft.

Bringing blockchain to the rest of the gaming industry is a monumental task that faces two major obstacles — speed and complexity. Speed, specifically blockchain transaction speed, is vital for integrating with modern games. Users should be able to trade and purchase assets quickly without needing to wait minutes for transactions to confirm. Complexity is another roadblock for connecting in-game assets with NFTs. To integrate blockchain-based assets, a developer must first set up all the necessary components — user key management solutions, a deployed smart contract, create all of the necessary functions for interacting with the blockchain, and create a marketplace for exchanging goods.

Conflux Network can meet the transaction throughput that modern games demand with 3000+ transactions per second while using Proof-of-Work (PoW) that has been proven secure at a large scale and over many years. This ensures that games can process interactions with near-instantaneous transactions on Conflux Network while also guaranteeing players’ asset security.

The following addresses the complexity of integrating game assets with blockchain-based NFTs by proposing a potential concept model and the necessary code-based components to integrate.

A PoC Model for Gaming

While game development is complex, this simplified model hopes to explore the idea of integrating blockchain networks like Conflux Network and token standards like ERC-721 (NFTs) for tracking unique game assets. This has the potential to unlock assets that are interoperable between different games because all asset records are recorded on a public blockchain that can be understood as a “global database”. At the simplest level, a badge from Fortnite could be displayed on an island in Animal Crossing. Blockchain forms a bridge that allows game assets to be used in any game that developers choose to integrate with.

A simple proof of concept model for integrating a game with an NFT smart contract on Conflux Network. The game would need modification to track a player’s address and retrieve asset IDs from the blockchain through middleware functions in various programming languages.

For a simple integration, the game would need to add in a few additional components. On the frontend, players would need to be able to input their Conflux Network address and associate it with their profiles. On the backend, there would need to be a relational database connecting the asset ID and the various asset characteristics such as images, sprites, etc. Additionally, the backend needs to be able to call two functions — one to mint, the other to get a list of user assets. The mint function would be used to assign a brand new game asset to a user’s address. The “get assets” function would return a list of IDs for the game to render for each user.

The middleware layer is a package for the corresponding backend programming language. The package facilitates the “mint” and “get information” functions by sending transactions to the blockchain or returning information from the smart contract on the blockchain. This layer abstracts the necessary setup of interacting with a contract into a simplified interface that can just be plugged into an existing back-end. While simple in concept, this layer is critical to the developer experience of blockchain technology and there is still much work to be done in creating better toolkits, packages, and workflows.

On the blockchain, an ERC-721 contract is deployed to maintain a ledger of various assets for the game. This smart contract is then accessible by any marketplace built on Conflux Network like Tspace. There are multiple benefits to having a third-party marketplace. First, this reduces the workload for game developers and allows them to focus on the game’s development while a third-party focuses on marketplace experience. Another benefit is that users can use third-party marketplaces to purchase and trade assets from games across various platforms and ecosystems. Even though assets are not traded directly in the game, developers can still monetize their assets through selling assets or even adding smart contract functionality to add a transaction fee to each asset transfer that can be used to fund further game development.

Since assets are tracked on the blockchain (or what can be viewed as a global database), assets no longer need to be constrained to a single game. This allows assets from popular games to move fluidly from game to game, and can provide an additional avenue for Indie games to gain more exposure. For example, if an asset can only be won on a lesser-known game, and then it is used in a generally popular game, the lesser-known game can attract new players trying to collect the asset. Blockchain-backed assets can allow games to engage with a broader audience with assets that have the potential to be used in other games.

Tools Explanation

While the game and marketplace development will be customized to capture players and users, the middleware layer can be developed in an open-source manner. The goal of the following tool is to address one of the biggest issues facing blockchain technology: usability. Blockchain has incredible potential, and the goal of this code is to make integrating blockchain into games as easy as possible.

The repository can be found at Conflux-Network-Global/sponsored-erc721 and is divided into three main components — the smart contract, deployment scripts, and packages. The smart contract shown below uses the OpenZeppelin ERC-721 implementation with a slight modification to expose the safeMint function. By using the OpenZeppelin implementation, the NFT smart contract has a basic level of security through audits on the base implementation and can be easily customized with a new name.

pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract NFTBase is ERC721 {
address private owner;

constructor() ERC721("MyCollectible", "MCO") public {
owner = msg.sender;
}

//exposing the safe mint functionality
function safeMint(address to, uint256 tokenId) public {
require(msg.sender == owner, "NFTBase: Only owner can mint");
_safeMint(to, tokenId);
}

function safeMint(address to, uint256 tokenId, bytes calldata _data) public {
require(msg.sender == owner, "NFTBase: Only owner can mint");
_safeMint(to, tokenId, _data);
}

}

The deployment scripts allow developers to easily deploy their smart contracts to Conflux Network and set up transaction sponsorship if they choose to do so. Transaction sponsorship is a unique Conflux Network mechanism that allows users to have their transaction fees covered to further reduce the complexity of using the blockchain. Additionally, there are scripts that can check the sponsorship status of a contract and user.

The final components of the repository are packages for specific languages. Currently, there are Javascript and Go packages for interacting with a deployed smart contract. The examples shown below can be found in the repository as well.

For Javascript, the package can be installed with `npm install @aalu1418/sponsored-erc721` or `yarn add @aalu1418/sponsored-erc721` and it follows a very simple interface for setting up the instance and then minting a new NFT or querying a list of NFTs owned by an address.

const NFT = require("@aalu1418/sponsored-erc721")

const main = async () => {
const nft = new NFT("http://test.confluxrpc.org", "0x8aa092e0660c59eab456efdbd39ae8d158e9a95b");

const tx = await nft.mint("0x18e33e342b0f3fFE0b0193950FE9F2e0378a81Ee", 1);
console.log("Mint TX hash:", tx.transactionHash);

const list = await nft.getAssets("0x18e33e342b0f3fFE0b0193950FE9F2e0378a81Ee")
console.log("Assets:", list);

}

main().catch(e => console.log(e))

For Go, the package can be installed with `go get github.com/Conflux-Network-Global/sponsored-erc721/golang` and similar to the Javascript package, it also follows a very simple interface of setup, minting, and querying.

package main

import (
"fmt"
nft "github.com/Conflux-Network-Global/sponsored-erc721/golang"
)

func main() {
NFT, err := nft.New("http://test.confluxrpc.org", "0x8aa092e0660c59eab456efdbd39ae8d158e9a95b", "test")
if err != nil {
fmt.Println(err)
return
}

txhash, err := NFT.Mint("0x18e33e342b0f3fFE0b0193950FE9F2e0378a81Ee", "2")
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Mint TX hash:", txhash)

ids, err := NFT.GetAssets("0x18e33e342b0f3fFE0b0193950FE9F2e0378a81Ee")
if err != nil {
fmt.Println(err)
return
}
fmt.Println("NFT IDs:", ids)
}

Both packages simplify the interface of interacting with an NFT smart contract on Conflux Network. A developer no longer needs to configure packages to read environment variables, import an ABI for the smart contract, or figure out how to get the full list of assets for a user from the blockchain. All of those functions are neatly packaged to simplify the process of integrating NFTs into video games.

Continued Work

This initial PoC and pair of packages is only the starting point to make it as easy as possible for game developers to integrate with on-chain assets on Conflux Network. Additional contributions could involve:

  • Support for more languages like Python, C++, Swift, Java, .NET, etc
  • Modules for easily integrating wallet providers into games
  • Integrating other token standards beyond ERC-721 like ERC-20, ERC-777, ERC-1155
  • Feedback on usability
  • Steam/PC or console support

The convergence of blockchain and gaming holds a huge amount of potential for unlocking new ways to expand audiences and monetize game assets to fund further development. The previously described package is the beginning of a solution to make blockchain integration in gaming as simple as possible. Conflux Network acts as the other piece of the puzzle by providing high transaction speeds without compromising on security to ensure players’ assets are safe and secure but usable in face-paced gaming environments.

About Conflux Network

The only state-endorsed public, permissionless blockchain project in China, Conflux Network is an open-source, layer-1 blockchain protocol delivering heightened scalability, security, and extensibility for the next generation of open commerce, decentralized applications, financial services, and Web 3.0. Conflux Network is overseen by a global team of world-class engineers and innovative computer scientists, led by Turing Award recipient Dr. Andrew Yao. Fostering entrepreneurship and innovation, Conflux elevates startups and organizations across industries and continents to generate decentralized marketplaces and digital assets for meaningful business and social impact. Founded in 2018, Conflux has raised $35 million in capital from prominent investors including Sequoia China, Metastable, Baidu Ventures, F2Pool, Huobi, IMO Ventures, and the Shanghai Municipal Science and Technology Commission.

Join our hackathon! REGISTER HERE

--

--

Conflux Network

Conflux is a PoW + PoS hybrid first layer consensus blockchain for dApps that require speed at scale, without sacrificing decentralization.