Monad avatar
Your onchain game doesn’t need to be slow We built Monad2048 - a fully onchain version of 2048 - to show how to build fast and button-mashable gameplay while keeping all game logic on chain If you're building responsive, high-throughput dapps, this thread is your blueprint 🧵
Cast image embed
100
378
1.1K
Monad avatar
Monad2048 runs entirely onchain: every move is a transaction and is validated by a smart contract. No servers involved. Play the game at 2048.monad.xyz and read about the build process at
Monad 2048
2048.monad.xyz
Monad 2048
2048: A Guide to Building High Performance Games on Monad
blog.monad.xyz
2048: A Guide to Building High Performance Games on Monad
6
28
122
Monad avatar
We aimed to prevent cheating while keeping moves instant. A deterministic seed generates new tiles, discouraging cheating without slowing gameplay. Here’s how we designed it. Contracts:
GitHub - monad-developers/2048-contracts: Smart contracts that let you play a game of 2048 entirely onchain on Monad testnet.
github.com
GitHub - monad-developers/2048-contracts: Smart contracts that let you play a game of 2048 entirely onchain on Monad testnet.
1
4
35
The Monad2048 contract stores the 4x4 board in one uint256. Each tile’s value is encoded in 8 bits. This function reads a tile’s value:
Cast image embed
1.5Kviews
Monad avatar
Gameplay works in two steps: 1. startGame: Submit four initial boards to begin, and a seed. 2. play: Submit a move and the resultant board. The seed is used in a deterministic formula to determine where new tiles spawn upon new moves.
1
3
20
Monad avatar
The frontend uses Privy for creating player wallets, which avoids repeated popup confirmation for each move. We update the interface instantly after a move, sending transactions in the background. If a transaction fails, we revert to the last valid board.
1
1
20
Monad avatar
For rapid transactions, we manage nonce locally and avoid unnecessary RPC calls (e.g. in simulations). Transactions are signed with viem but sent directly to the RPC. This prevents large delays between client and chain state. To skip simulations safely, test client transaction inputs beforehand.
1
2
17
Monad avatar
Errors are handled by resetting to the last valid board and showing a notification. We store failed boards and pick the lowest-scoring one to resume. We allow to player to re-sync their board and resume their game by fetching the latest board from the smart contract.
1
3
16
Monad avatar
The key takeaway is to explore how you can eliminate latency in your code, wherever possible. Use techniques like optimistic UI updates, re-syncing with chain state, etc. Monad Testnet blocks are as fast as the blink of an eye; strive to make your app updates at least as fast.
1
3
18
Monad avatar
Full blog post here:
2048: A Guide to Building High Performance Games on Monad
blog.monad.xyz
2048: A Guide to Building High Performance Games on Monad
2
3
19