Monad pfp
Monad
@monad-xyz
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 🧵
179 replies
542 recasts
1532 reactions

Monad pfp
Monad
@monad-xyz
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 https://blog.monad.xyz/blog/build-2048
18 replies
62 recasts
253 reactions

Monad pfp
Monad
@monad-xyz
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: https://github.com/monad-developers/2048-contracts
1 reply
3 recasts
38 reactions

Monad pfp
Monad
@monad-xyz
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:
1 reply
2 recasts
33 reactions

Monad pfp
Monad
@monad-xyz
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 reply
2 recasts
24 reactions

Monad pfp
Monad
@monad-xyz
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 reply
1 recast
18 reactions

Monad pfp
Monad
@monad-xyz
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 reply
2 recasts
18 reactions

Monad pfp
Monad
@monad-xyz
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 reply
2 recasts
18 reactions

Monad pfp
Monad
@monad-xyz
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 reply
1 recast
17 reactions

Monad pfp
Monad
@monad-xyz
Full blog post here: https://blog.monad.xyz/blog/build-2048
2 replies
2 recasts
20 reactions

tokenfox pfp
tokenfox
@tokenfox.eth
very cool!
0 reply
0 recast
0 reaction