Skip to content

bocha-io/superhack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bochamon

Fully on-chain turn-based game with multi-chain rewards. Bochamon is an Autonomous World that can be deployed in any OP rollup and its rewards can be bridged between all the supported chains by Layer-Zero.

bochamon banner

Description

This project combines Pokemon-like games and Blockchain.

While playing this game your current position on the map is stored in the blockchain and updated after every move, you can pick your Bochamons and set up your team (also registered in the blockchain) and you can fight other players (every action is also a blockchain transaction).

After winning a duel, you get rewarded in BochaCoins. These coins are deployed as an ERC20 contract in OP Mainnet and we set up a bridge to Base with the Layer-Zero. Talking with the Exchange NPC allows you to bridge the coins!

Our initial idea was to deploy it also to Base Mainnet and Zora, so you can move your BochaCoins between all the chains, but the cost of deploying to Mainnet the contracts was too high.

How it's made

The first step to build this project was deciding what lib we were going to use to create the game contracts. We already have experience using MUD so we decided to use it for this project, it also allows us to use the open-source lib Garnet to create the backend that integrates automatically with MUD.

With the idea of building the game using MUD, we deployed a Testnet for local development, we started to look for free assets for the game and set up a Unity project to have a game client.

To connect the Blockchain with Unity we needed a backend, and we created one in Go. This backend provides a WebSocket connection to the Unity client. Connecting to that Websocket the clients can read the state of the game, send transactions and register new users.

One of our goals was to make the game multi-chain so we make a quick demo with Layer-Zero connecting OP Mainnet and Base to send ERC20 between both chains, it took some time but we were able to make it work. After that, we just needed to add the new message to the backend and create the same transaction programmatically there.

At this point we have everything ready to deploy to OP Mainnet, so we create a free account at Alchemy to have a rest endpoint available, and we bridge some ETH to OP Mainnet.

The last step was deploying the contracts to OP Mainnet: here we encounter a problem, MUD's deployment scripts were breaking when connecting to OP Mainnet. We found out that the issue was that the contracts were too big to estimate the gas consumption using the rest endpoints, we "hack" the node modules folder and hardcoded the gas limit instead of using the estimation. After that change, we were able to deploy the OP Mainnet!

With everything on OP Mainnet and little time in the clock before the hackathon ends. We move a little bit on the map, we set up our Bochamons, fight a duel and use the bridge to record the video.

We realized that the costs of having that public are going to be high, so after the video was recorded we turned off the backend pointing to OP Mainnet and release a new version running on Localnet without the bridge active to have it public, so anybody can play the game.

How to play it

Controls:

  • You can move your character using WASD.
  • Interact with objects: F
  • Cancel action with: G

You can play the game now at https://superhack.bocha.io/. (It's the Testnet version)

Dependencies

We used open-source libs to build the game and read the state of the Blockchain:

  • All the solidity contracts are built using MUD.
  • Using Garnet we are able to index all the MUD transactions and it provides an in-memory database to access the information.
  • Using txbuilder we are able to create, sign and broadcast transactions.
  • Using game-backend we are able to expose all the functionality using websockets.

NOTE: the first version of the last 3 libs were created in a previous hackathon AWs-Garnet

The client was written using Unity, we connected it to the Backend's WebSocket to get the chain information and send user actions.

Mainnet info

Game:

Tokens:

Bridge:

Project Structure

  • MUD contracts: ./backend/contracts-builder/contracts
  • Go backend: ./backend
  • Unity client: ./frontend
  • Bridge contracts: ./layerzero-contracts

Configuration and Usage

To run the code locally:

  • Set up your private key in the .env file in backend/contracts-builder/contract

  • Edit the make file to support your nvm path or if you have node globally installed just remove the nvm path from the init-contracts and contracts actions.

  • Deploy the game contracts:

cd backend
make init-contracts
make contracts
  • OPTIONAL: Deploy your layer-zero contracts, they are located in the layerzero-contracts folder, the code there is just a "copy and paste" from their solidity examples. We have them in that folder to generate the ABI.

  • Configure the backend by editing the run.sh file to fit your needs.

  • Run the backend with ./run.sh inside the backend folder. It will create an indexerlogs.log file.

  • Open the frontend folder in Unity and build the project to run it.

Things missing

We wanted to implement more things but we run out of time:

  • Display ETH and Bochacoins balances in the client.
  • Validate ETH and Bochacoins balances before sending a transaction in the backend.
  • Instead of sending User actions as plain text to the server, it should be a personal ethereum message that can be validated on-chain.
  • Add music to the game.
  • Deploy the in more than one network.
  • Clean up WebSockets connections in the backend to fix a memory leak.

Assets

Bochamons

  • Tobishimi, Baobaffe, Firomenis, Crobarett design by PrincessPhoenix
  • Howliage,Mobiusk design by Magiscarf
  • Flarezael design by Lucrain
  • Sunnydra design by KajiAtsui

Map

Characters

About

Superhack entry - hackathon ethglobal 2023

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published