Sample Mobius DApp Store application implemented using Ruby and the Mobius DApp Store Ruby SDK.
- Run:
bundle
mobius-cli create dev-wallet
mv dev-wallet.html public/
-
Start the server with
rails s
-
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
rails s
-
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.
The client side code is similarly very simple. It started as a fork of https://github.com/nebez/floppybird/ and is located in public/flappy_bird.
To add MOBI payment support we made the following changes
- We added a div
#credits_balance
on line 41 to show info such as the player's current MOBI balance.
-
The code expects the
token
value used to identify this user to be passed in via the URLtoken
parameter and we save it in a new variableg_token
on line 69 -
In the
$(document).ready
callback function on line 87 we get the player's balance from the server by calling the/balance
endpoint and pass in theg_token
value to identify the current player. The#credits_balance
div is updated with the value on response. -
On line 141 we create a new
startGame
function that delays starting a new game until payment is successful. On successful payment it callsstartGameReal
the originalstartGame
function.
In the startGame
function on line 148 we updated the #credits_balance
div to say "Paying........."
On line 150 the pay
server call is made passing g_token
to identify the player. If payment is successful the game is started by calling startGameReal
on line 154.
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.
Everyone interacting in the Mobius::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.