Snake Game Build Better on Stellar: Smart Contract Challenge

rajdhokai

Dhokai Raj B

Posted on August 18, 2024

Snake Game Build Better on Stellar: Smart Contract Challenge

This is a submission for the Build Better on Stellar: Smart Contract Challenge : Build a dApp

What I Built

I created a classic Snake game using React and integrated it with a Stellar smart contract to store player game details. The contract handles essential operations such as adding new players, retrieving player information, updating scores, and even deleting players. This integration with Stellar allows the game to securely and transparently manage player data, including scores and public keys, all on the blockchain.

Demo

https://stellar-snake-game.vercel.app/

Image description

Image description

My Code

https://github.com/rajdhokai/stellar-snake-game

Journey

The idea behind this project was to blend the nostalgic fun of the Snake game with the modern capabilities of blockchain technology. I wanted to create something that not only provided entertainment but also showcased the potential of decentralized systems for managing game data.

The design of the smart contract was centered around creating a secure and efficient way to handle player information. I focused on making the contract versatile, allowing for easy addition of new players, updating of scores, and retrieval of all players. The contract also includes functionality for deleting players, ensuring that the game’s data remains clean and manageable.

Throughout the development process, I learned a lot about the Stellar ecosystem, especially the intricacies of smart contract development with Soroban. It was exciting to see how blockchain technology could be applied to a simple game, providing transparency and security in a fun and engaging way.

I'm particularly proud of how seamlessly the smart contract integrates with the game, providing real-time updates and secure storage of player data. Next, I hope to explore more complex gaming mechanics and further leverage Stellar's capabilities to create even more immersive blockchain-based games.

Additional Prize Categories: Glorious Game and/or Super Sustainable
Given the fun and interactive nature of the Snake game, coupled with the innovative use of blockchain technology, I would like this submission to be considered for the Glorious Game prize category. The combination of a classic game with the power of Stellar's smart contracts creates a unique and engaging experience that stands out in the gaming space.

Here's how you can invoke the methods of the Stellar smart contract for the snake game using the soroban contract invoke command. Replace <DEPLOYED_CONTRACT_ADDRESS> with your actual deployed contract address.

1. Create a Player

soroban contract invoke --id CBGPKZU7CNVUITUZO5SJXMBIMVHZPU2PIOJAM7MBWBPEITKUY2YLEJRB --source alice --network testnet -- add_player --name "Alice" --public_key "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF" --score 100
Enter fullscreen mode Exit fullscreen mode

2. Update a Player's Score

soroban contract invoke --id CBGPKZU7CNVUITUZO5SJXMBIMVHZPU2PIOJAM7MBWBPEITKUY2YLEJRB --source alice --network testnet -- update_player --player_id 1 --new_score 150
Enter fullscreen mode Exit fullscreen mode

3. Get Player by ID

soroban contract invoke --id CBGPKZU7CNVUITUZO5SJXMBIMVHZPU2PIOJAM7MBWBPEITKUY2YLEJRB --source alice --network testnet -- get_player_by_id --player_id 1
Enter fullscreen mode Exit fullscreen mode

4. Get All Players

soroban contract invoke --id CBGPKZU7CNVUITUZO5SJXMBIMVHZPU2PIOJAM7MBWBPEITKUY2YLEJRB --source alice --network testnet -- get_all_players
Enter fullscreen mode Exit fullscreen mode

5. Delete a Player by ID

soroban contract invoke --id CBGPKZU7CNVUITUZO5SJXMBIMVHZPU2PIOJAM7MBWBPEITKUY2YLEJRB --source alice --network testnet -- delete_player --player_id 1
Enter fullscreen mode Exit fullscreen mode

Notes:

  • Replace "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF" with a valid public key for your player.
  • The --id flag represents the ID of the player when updating, retrieving, or deleting specific player data.
  • The commands assume that the name, public_key, and score parameters are required to create a new player. Adjust accordingly if your contract implementation differs.

Team:

@chintanonweb

💖 💪 🙅 🚩
rajdhokai
Dhokai Raj B

Posted on August 18, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related