We offer a controller template github.com/moneypot/controller-template as a starting point for building your own game on top of the @moneypot/hub server library.
The template implements useful boilerplate code but also an example coinflip game that you can use as a reference for your own graphql plugins and database modifications.
git clone https://github.com/moneypot/controller-template # Rename the folder to your project name mv controller-template my-game cd my-game npm install
For the rest of this document, whenever you see my-game
, replace it with your project name.
Ensure postgres is installed and running locally.
Create a new database for our game server.
On Linux or macOS, you can just run this from the terminal:
createdb my_game
Create an app_postgraphile
postgres user with a secure password (username is important here):
CREATE ROLE app_postgraphile LOGIN PASSWORD '<todo: secure password>'; -- Or you can update the password if it already exists ALTER ROLE app_postgraphile PASSWORD '<todo: secure password>';
app_postgraphile
should not be a superuser. This is the postgres user that our GraphQL executor will use to run queries, so we want it to obey RLS authorization.Ensure there's also a user with superuser access to the database (username not important):
CREATE ROLE my_superuser WITH LOGIN SUPERUSER PASSWORD '<todo: secure password>';
Rename file .env.example
to .env
and update it.
DATABASE_URL=postgresql://app_postgraphile:xxx@localhost:5432/my_game SUPERUSER_DATABASE_URL=postgresql://my_superuser:xxx@localhost:5432/my_game
Run the server which will create the database schema and begin serving requests:
npm run dev # Listening on port 4000
You'll notice that the .sql files in the automigrations
folder were executed and the sample app.coinflip_bet
table was created.
Visit http://localhost:4000/graphql to view and play with the GraphQL API
Visit http://localhost:4000/dashboard to view the admin dashboard
To get an api key, run the sql insert into hub.api_key default values returning key
.
You need to tell your hub server about every Moneypot casino it should integrate with.
For development purposes, we operate moneypot.dev as a public Moneypot casino.
Register at moneypot.dev.
Create a new controller at moneypot.dev/me/controllers.
Create a new API key for that controller and note the API key.
Go to your hub server's admin dashboard: http://localhost:4000/dashboard.
Click "Add casino" and fill in:
moneypot.dev
https://moneypot.dev
(This is the origin of the casino URL that will <iframe>
our experience frontend)https://api.moneypot.dev
<paste this from Step #3>
If your hub server successfully authenticates with the casino server, the casino should now show up in your casino list.
In your hub dashboard, go to the casino's "Bankrolls" tab and add a bankroll for the test HOUSE
currency so that our server can begin accepting user bets. )
You could do it manually with:
insert into hub.bankroll (casino_id, currency_key, amount) values ('<casino_id>', 'HOUSE', 1000000);
TODO: Document that we need to fund our controller on the casino website before users can withdraw. And we should be able to manage the controller balance from the dashboard.
Now when you start your hub server, it will begin polling for user transfers from each casino. When users deposit currency into our experience, the controller will receive a hub.deposit
and update the hub.balance
table.
Now that you have a basic controller server running, notice that it comes with a demo app.coinflip_bet
table migration along with a plugin that implements a makeCoinflipBet
graphql mutation.
Here are some places you can go from here:
Start reading the hub manual to learn more about how the underlying @moneypot/hub server works and how to extend it.
Add a migration like 003-my-bet-table.sql
where you add your own betting system along with your own src/plugins/my-bet-plugin.ts
where you implement a graphql mutation.
Add a migration to drop the coinflip table: 003-drop-coinflip.sql
:
DROP TABLE app.coinflip_bet CASCADE;