project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4
project screenshot 5
project screenshot 6

Superwalk

A fun & competitive step tracker game where you can walk, use items or bribe other players to win.

Superwalk

Created At

Superhack 2024

Winner of

Blockscout - Use Blockscout Block Explorer!

Prize Pool

Pyth - Most Innovative use of Pyth pull oracle (Entropy)

Project Description

Superwalk is the Android game you'd get if you would mix Fitbit with Mario Party. It works just like a regular step tracker, but includes a turn-based competition where you (mostly) walk to climb in the leaderboard, but you can also use items or bribe other players to get a higher score.

The game is turn-based, with 1 turn lasting 60 minute. During a turn, every players 's step count is automatically recorded. When a turn starts, players can claim a new in-game item, as long as their step count increased compared to the previous turn.

These items can be offensive, defensive, or have a boosting effect, with each items having their own success rate to keep the game fun and unpredictable.

During the first 20 minutes of each turn, players can decide to either use one of their items, attempt to protect themselves from other players' actions, or bribe another user to cancel their attack. Although these actions can change the course of the game, they are not guaranteed to succeed, as using an item or blocking attacks can fail.

Additionally, action will place the player in a cool down period that will last a certain amount of turns. During that period, players won't be able to perform another action, meaning they have to strategize to stay on top.

In addition to bribes, players can bets against one another, making Superwalk a fun way to get a few extra bucks while staying fit and having fun.

Game mechanics highlights

  • Step count: The steps data are recorded and reported automatically

  • Turns: Each turn lasts 1 hour, during which players can perform actions and pick items. The game operates in a turn-based manner and without any human intervention

  • Inventory & item airdrop: Players can pick a random item based on their last step count, provided their inventory is not full.

  • Actions: Players can perform actions such as using items, blocking, or bribing other players. Actions are subject to a cool down period and can only be performed within a specific time window.

  • Time constraints: All actions (getting a new item, bribing, using an object, blocking attacks) are subject to time constraints and can only be performed within a specific time window, the 20 first minutes of each turn.

  • Fitness monetization: Players have multiple opportunities to make their fitness activity an additional source of income, by scoring high, receiving bribes (a bribe is proportional to the step count of the briber, meaning the more that person walked, the more they will have to pay to not be attacked), or winning bets against other players.

How it's Made

This project is made of multiple parts :

  • A mobile app (Android-only), built with Expo and bootstrapped using Thirdweb templates ;
  • A custom smart contract for the game logic and an account factory contract, bootstrapped and managed via Thirdweb, implementing Pyth Network Entropy for RNG (random number generation)
  • A subgraph indexing the game contract event, built with Goldsky ;
  • A database with cron jobs and webhooks running, built with Supabase
  • An API built with Elysia

I was planning on using Thirdweb Engine but could not due to my laptop not having enough resources to run it locally (along with my API and mobile app environment)


Flow overview

The game continuously runs for 24 hours, divided into 60-minute turns, during which each player's step count is automatically reported every 10 minutes, with an automatic reset for every player everyday.

At the beginning of every turn, players can earn new in-game items, as long as their step count increased compared to the previous turn. These items can be offensive, defensive, or have a boosting effect, with each items having their own success rate to keep the game fun and unpredictable.

During the first 20 minutes of each turn, players can decide to either use of their items to change the course of the competition, or bribe another user to cancel their attack.

At the end of each turn, the score of each player is calculated by checking their current step count and applying any modifier applied to them during the turn (boosting items, attacks, if they cancelled an attack with a block...).

Game

  • users identify on the app then join the competition (if they didn't already) The game continuously runs for 24 hours, divided into 60-minute turns, during which each player's step count is automatically reported every 10 minutes, with an automatic reset for every player everyday.

At the beginning of every turn, players can earn new in-game items, as long as their step count increased compared to the previous turn. These items can be offensive, defensive, or have a boosting effect, with each items having their own success rate to keep the game fun and unpredictable.

During the first 20 minutes of each turn, players can decide to either use of their items to change the course of the competition, or bribe another user to cancel their attack.


Detailed implementation

Mobile app

The mobile app (Android only) was bootstrapped using Thirdweb Expo template. It uses xstate store and finite state machines for state management.

It was designed to be interoperable with HealthConnect (replacement of Google Fit API), but I had to switch to manually track steps with expo-sensor instead, as it is currently impossible to filter out manually added steps with HealthConnect](https://github.com/matinzd/react-native-health-connect/issues/51#issuecomment-2231091383).

Sadly this meant also dropping support for iOS, as the expo-sensor Pedometer implementation is completely different between iOS and Android, with Android support lacking the possibility to get step count between 2 dates. Currently, the steps are accounted for using a finite state machine that automatically records them in a databa

Due to these problems, I had to manually implement step tracking, but the source code still showcases a finite state machine for interacting with the HealthConnect SDK (granting permission, reading records etc.).

Authentication was built using Thirdweb Connect, with smart accounts as a priority. Designed for casual, non-crypto users first, Superwalk supports login with Google, email and phone number, but also offers connecting with Farcaster. Upon signing-in, behind the scenes, users are also authentified on the backend, using SIWE (sign-in with Ethereum) and custom API routes.

The interactions that interact with smart contracts (joining the competition, claiming an item, using an item, bribing another user...) are sponsored, another Thirdweb Connect feature.

All on-chain interactions were developed using the Thirdweb React Native SDK.

Smart contracts

2 smart contracts were deployed to Base Sepolia via the Thirdweb CLI :

  • the game
  • an account factory, (required to create a smart backend account)

The game smart contract implements all of the game logic. Some functions are available to everyone (joining the game for instance), but most are only allowed to specific wallets addresses meeting certain criteria :

  • being the owner of the contract: granting the GAME_MASTER role to a specific address
  • holding a specific role, like the GAME_MASTER role ; (possible by implementing AccessControl) : reporting step counts, scores, ending a turn to start a new one ;
  • being a registered player: claiming an item, performing a turn action (using an item, bribing another player, defending)

Additionally, the functions of the smart contract are gated with time control.

RNG

Being a game, Superwalk had to implement a reliable random number generator to guarantee a fair game. This was done using Pyth Network Entropy. Sadly, this meant not deploying the game contract to Metal L2 testnet and Celo Dango, as the required contracts are not available on those chains yet.

Entropy is used to :

  • randomly decide which item will be claimable by the user ;
  • decide if an in-game item will be successful or not (which implement weighted randomness)
  • decide if a blocking action will be successful or not ;

Events

Events are dispatched for most function :

  • GameItemCreated: Emitted when a new game item is created by the game master or contract owner
  • PlayerJoined: Emitted when a player joins the competition.
  • StepsCountReported: Emitted when a player's steps are reported.
  • IntentAction: Emitted when a player requests to perform an action (requires RNG)
  • BribeSent: Emitted when a bribe is sent from one player to another.
  • ItemUsed: Emitted when a player uses an item.
  • IntentPickItem: Emitted when a player requests to pick an item. (requires RNG)
  • ItemPicked: Emitted when a player successfully picks a random item.
  • ScoreUpdated: Emitted when a player's score is updated.
  • TurnEnded: Emitted when a turn ends.

Subgraph

The subgraph for the custom game contracted was created using Goldsky no-code deployment tool. It indexes all events defined above. The subgraph is used in various parts of the stack :

  1. in the app:
  • as an easy and fast way to check wheter or not the currently connected user joined the game
  • get the list of in-game items
  • get the leaderboard
  • get the steps history for a user

etc. ; and in the API to calculate the score of each player for a turn by doing the aggregating all actions that targeted a player

Database & CRON jobs

The database and cron jobs were created with Supabase. All tables have RLS enabled and users can't write to it. Only authenticated calls from the API can. The following data are stored :

  • Step counts
  • Actions
  • Game items

Steps are recorded every 10 minutes, with a hook verifying that the same player didn't already update their step count in the last 5 minutes.

Cron jobs were set to automate the following :

  • call the API every hour to report and calculate the scores as well as finishing the turn (reportScore, endTurn)
  • call the API multiple times every hour (at the 5,10,15,20,59th minutes) to report the last steps updates from the database to the smart contract, using the game master wallet (reportSteps)
  • call the API every day at midnight to reset all players step count

API

The API was bootstrapped using Elysia. It is the bridge between multiple parts of Superwalk :

  • it authenticates requests on the backend (SIWE)
  • it reports steps data to the database
  • it reports data (steps, scores) onchain using a trusted backend wallet (game master)

Overall, the goal was to create a player experience that would be as seamless as possible (non technical vocabulary, simple rules and flow) while keeping it open enough to find ways for the app to finance its own infrastructure.

Deployed contracts & subgraph

Base Sepolia

background image mobile

Join the mailing list

Get the latest news and updates