Snack Game Build Better on Stellar: Smart Contract Challenge



This content originally appeared on DEV Community and was authored by Dhokai Raj B

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

What I Built

SnackGame

Demo

Image description

My Code

Journey

Additional Prize Categories: Glorious Game and/or Super Sustainable
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

2. Update a Player’s Score

soroban contract invoke --id CBGPKZU7CNVUITUZO5SJXMBIMVHZPU2PIOJAM7MBWBPEITKUY2YLEJRB --source alice --network testnet -- update_player --player_id 1 --new_score 150

3. Get Player by ID

soroban contract invoke --id CBGPKZU7CNVUITUZO5SJXMBIMVHZPU2PIOJAM7MBWBPEITKUY2YLEJRB --source alice --network testnet -- get_player_by_id --player_id 1

4. Get All Players

soroban contract invoke --id CBGPKZU7CNVUITUZO5SJXMBIMVHZPU2PIOJAM7MBWBPEITKUY2YLEJRB --source alice --network testnet -- get_all_players

5. Delete a Player by ID

soroban contract invoke --id CBGPKZU7CNVUITUZO5SJXMBIMVHZPU2PIOJAM7MBWBPEITKUY2YLEJRB --source alice --network testnet -- delete_player --player_id 1

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.

@chintanonweb


This content originally appeared on DEV Community and was authored by Dhokai Raj B