DEV Community

Cover image for Pay Picker: Fun way to decide who's paying | #BuildBetterOnStellar
Hasto
Hasto

Posted on

Pay Picker: Fun way to decide who's paying | #BuildBetterOnStellar

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

What I Built

Pay Picker reimagines the way friends decide who picks up the tab. Instead of the usual awkwardness or rote solutions, it transforms the process into a game.

Picture this: a virtual egg hunt unfolds on your phone, each tap brimming with anticipation.

As you and your friends take turns uncovering these digital surprises, one thing becomes clear – only one egg holds the key to paying the bill.

Pay Picker leverages the power of Soroban events to deliver a smooth and interactive gaming experience on Stellar.

This technology also makes Pay Picker incredibly scalable. Whether you're playing with a dozen friends or thousands of other players, Soroban events help ensure the game runs smoothly.

Demo

My Code

You can find the source code and documentation for this project at:

  1. Pay Picker flutter mobile app repository

GitHub logo hasToDev / pay_picker

Pay Picker Flutter App

Flutter Dart


Pay Picker

Smart contract-based mobile app built with Flutter and Soroban

About Pay Picker

Pay Picker is the dApp that makes splitting dinner bills with friends effortless.

Pay Picker combines Rust-based smart contracts built with Soroban on Stellar blockchain, and a mobile app to access the smart contracts functionality built with one of the most popular cross-platform frameworks, Flutter.

Get Started

This article is specifically about the Flutter mobile app for Pay Picker.

Discussion for Pay Picker smart contract is in the Pay Picker Soroban repository,

Pay Picker mobile app in this repository was developed using Flutter version 3.22.3 and Dart version 3.4.4

Environment Variable Setup

This app will require the necessary environment variables to run properly.

You can find environment variables example in the env directory.

The following is an example of an environment variable value:

{
  "sorobanRpcURL": "https://soroban-testnet.stellar.org:443"
  "stellarNetworkPassphrases": "Test SDF Network ; September 2015",
  "payPickerContractAddress": "<SOROBAN PAY
  1. Pay Picker soroban smart-contract repository

GitHub logo hasToDev / pay_picker_soroban

Pay Picker Soroban Smart-Contract

Stellar Rust


Pay Picker

Smart contract-based mobile app built with Flutter and Soroban

About Pay Picker

Pay Picker is the dApp that makes splitting dinner bills with friends effortless.

Pay Picker combines Rust-based smart contracts built with Soroban on Stellar blockchain, and a mobile app to access the smart contracts functionality built with one of the most popular cross-platform frameworks, Flutter.

Get Started

This article is specifically about the Soroban smart contract for Pay Picker.

Discussion for Pay Picker mobile app is in the Pay Picker repository,

Pay Picker smart contract in this repository was developed using Rust version 1.80.0 and Stellar CLI 21.3.0

Install Rust and Soroban CLI

The first step you have to do is install Rust. You can follow the steps to install Rust in the following article:

Next we install…

Journey

dApp Inspiration

We've all been there – that slightly awkward moment at the end of a fun outing when it's time to settle the bill. Sure, you could flip a coin, play a quick round of "credit card roulette" or maybe rely on a random phone app. But what if there was a more fun, engaging, and even rewarding way to decide who picks up the tab?

With the existence of Stellar and Soroban, we can now play an on-chain games where the stakes are real. Well, as real as paying for your delicious meal. Not only does the winner automatically transfer the funds to the merchant, but the entire experience becomes a fun extension of your hangout.

Beyond settling the bill, think of it as a game you can enjoy anytime with friends. Imagine unlocking badges based on your luck – think win ratios and epic winning streaks.

And hey, if you're feeling unlucky, why not call on a friend with a history of good fortune? Maybe they can play a round on your behalf and save you from footing the bill!

Smart Contract Design

In order to make a smooth gameplay experience, I have to discover the limitations of what Soroban can and can't do.

What I discover:

  1. We can read from the same Key storage simultaneously, no matter how many people read it.
  2. We can't write to the same Key storage at the same time, if 5 people write simultaneously, only 1 will succeed.

What is the problem:

  1. When creating a new game, new game data is saved to the contract's temporary storage.
  2. The contract will need to know every time a player joins or exits a particular game.
  3. If players write directly to the same key storage simultaneously, it will cause a bad experience, they will have to keep repeating the process until it's successful.
  4. If the amount of players is small, maybe they will only have to try several times. But imagine if the player is much bigger, how long they will need to keep pressing that button until they are successful ??

What is the solution for that: Soroban Event

With Soroban Event, the player will only need to write to their own storage key, then the contract will publish an event that announces to everyone "Hey, I just joined this game!".

Then the mobile app or any Pay Picker-related service will listen to this event, and process it.

This way, the game can be very scalable, handling as many players as it can in one single game!

What's Behind the Egg

The Egg basically is a random number generated by the smart contract.

When starting a new game, Pay Picker smart contract randomly generates a list of numbers, based on how many players that join the game, then randomly pick a secret "lucky number".

This "lucky number" is safely stored in the temporary storage. The only thing that Stellar Network can know is that this contract publishes an event that contains random numbers, that's it.

That random number then appears as a list of eggs that can be chosen by the player.

Random Brute Force Guessing

Yeah, you can try that and fail.

The contract will only return status in the form of u32 number.

Any useful information about any game on this contract only exists in its event and only successful invocation will publish it.

What's Next

  1. Pay Picker and Luck Leaderboard, will contain stats for each type of game, player will be ranked based on their performance, and win/lose ratio.
  2. Badges or NFT, players with a certain "luck level" will unlock this and they can brag it to the community.
  3. Tournaments, every person can compete and try to win some Badges, NFT, Prizes, or maybe acknowledgment from the Stellar team.
  4. Web App & Pass-Keys, since the app is built with Flutter, it will be relatively easier to create a web app version of it. Pass-Keys implementation will make things more interesting.

Additional Prize Categories: Glorious Game and/or Super Sustainable

Top comments (0)