# Create the Game Handling
Make sure you have all you need before proceeding:
- Have Go installed.
- The checkers blockchain codebase with
MsgCreateGame
created by Starport. You can get there by following the previous steps checking out the relevant version (opens new window).
You added the message to create a game along with its serialization and dedicated gRPC function with the help of Starport in the previous section.
Now all that remains is to add code that:
- Creates a brand new game.
- Saves it in storage.
- Returns the ID of the new game.
Starport isolated this concern into a separate file, x/checkers/keeper/msg_server_create_game.go
, for you to edit:
All the message processing code were created for you and all you are left to do is code the meat of the action. Opting for Starport is a wise decision as you can see.
Given that you have already done a lot of preparatory work: what does it involve to code the action? With what do you replace // TODO: Handling the message
?
First,
rules
represent the ready-made file with the imported rules of the game:
Get the new game's ID:
Using the
Keeper.GetNextGame
(opens new window) function created by thestarport scaffold single nextGame...
command.Create the object to be stored:
Notice the use of:
- The
rules.New()
(opens new window) command, which is part of the Checkers rules file you imported earlier. - The string content of the
msg *types.MsgCreateGame
namely.Creator
,.Red
, and.Black
.
- The
Confirm that the values in it are correct by checking the validity of the players' addresses:
The
.Creator
,.Red
, and.Black
need to be checked because they were copied as strings. The check on.Creator
is redundant here because at this stage the message's signatures have been verified and in particular the creator is the signer.Save the
StoredGame
object:Using the
Keeper.SetStoredGame
(opens new window) function created by thestarport scaffold map storedGame...
commandPrepare the ground for the next game with:
Using the
Keeper.SetNextGame
(opens new window) function created by Starport.Return the newly created ID for reference:
# Next up
You will modify this handling in the next sections:
- To add new fields to the stored information.
- To add an event.
- To consume some gas.
- To facilitate the eventual deadline enforcement.
- To add money handling including foreign tokens.
Now that a game is created, it is time to play it. That is the subject of the next section.