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






Problem Statement
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 highlightsStep count: The steps data are recorded and reported automaticallyTurns: 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 interventionInventory & 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.
Solution
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 SupabaseAn API built with ElysiaI 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 overviewThe 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...).Gameusers 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 implementationMobile appThe 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 databaDue 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.).Authenticationwas 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 contracts2 smart contracts were deployed to Base Sepolia via the Thirdweb CLI :the gamean 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 addressholding a specific role, like the GAME_MASTER role ; (possible by implementingAccessControl) : 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.RNGBeing 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 ;EventsEvents are dispatched for most function :GameItemCreated: Emitted when a new game item is created by the game master or contract ownerPlayerJoined: 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.SubgraphThe 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 :in the app:as an easy and fast way to check wheter or not the currently connected user joined the gameget the list of in-game itemsget the leaderboardget the steps history for a useretc. ; and in the API to calculate the score of each player for a turn by doing the aggregating all actions that targeted a playerDatabase & CRON jobsThe 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 countsActionsGame itemsSteps 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 countAPIThe 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 databaseit 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 & subgraphBase SepoliaAccountFactorycontract deployed on Base SepoliaGame contractdeployed on Base SepoliaGame subgraph(Base Sepolia contract)
Hackathon
Superhack 2024
2024
Prizes
- 🏆
Use Blockscout Block Explorer!
Blockscout
- 🏆
Most Innovative use of Pyth pull oracle (Entropy)
Pyth
Contributors
- naomiHauret
40 contributions
- turbobot-temp
3 contributions