Mobius Floppy Bird DApp
Sample Mobius DApp Store application implemented using Ruby and the Mobius DApp Store Ruby SDK.
bundle mobius-cli create dev-wallet mv dev-wallet.html public/
Start the server with
Open http://localhost:3000/dev-wallet.html and copy the Application Private Key.
Open config/secrets.yml and paste the secret key in the shared/app/secret_key value.
shared: app: secret_key: PASTE_SECRET_KEY_HERE jwt_secret: 431714aa54beec753975eaffba3db12d43d4ee52cafeb3ddcdbea05903e3a3ee78ff1f49d56b23df16597bc15f6d6099aef2f668aa38f957ffc960a5445aa8fb
- Stop the server (Ctrl + C)
Start the server with
Click Open under Normal Account.
Play Floppy Bird! Note when you click to start playing there is a pause of a couple seconds because it is in real-time making a blockchain payment! In a real app you would withdraw a larger number of MOBI at once to have some locally on deposit for the user to charge against.
The server side code is very simple and is copied from the Mobius DApp Store Ruby SDK.
There are two parts to the server code:
Authentication - located in app/controllers/auth_controller.rb
Payment - located in app/controllers/app_controller.rb
Both are documented in the Mobius DApp Store Ruby SDK.
To add MOBI payment support we made the following changes
- We added a div
#credits_balanceon line 41 to show info such as the player's current MOBI balance.
The code expects the
tokenvalue used to identify this user to be passed in via the URL
tokenparameter and we save it in a new variable
g_tokenon line 69
$(document).readycallback function on line 87 we get the player's balance from the server by calling the
/balanceendpoint and pass in the
g_tokenvalue to identify the current player. The
#credits_balancediv is updated with the value on response.
On line 141 we create a new
startGamefunction that delays starting a new game until payment is successful. On successful payment it calls
startGame function on line 148 we updated the
#credits_balance div to say "Paying........."
Bug reports and pull requests are welcome on GitHub at https://github.com/mobius-network/mobius-client-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Mobius::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.