RPC (Remote Procedure Calls)
Both Cardinal queries and transactions are submitted to Nakama via RPCs. The Nakama client libraries provide a simple interface for making RPC calls. You can consult the official documentation (Unity example) for a guide on how to do this on your game engine/programming language of choice.Cardinal Query via Nakama RPC
All Cardinal queries are automatically registered as a Nakama RPC endpoint with the same format as the REST API endpoint:query/game/<query_name>
The
query_name
is based on the name you passed in when registering the query on Cardinal’s main.go file. For example, if you registered a query with the name player-info
, the RPC endpoint will be query/game/player-info
.Example
In this example, let’s first register a query on Cardinal with the nameplayer-info
.
/cardinal/main.go
Unity/C# Example
Cardinal Transaction via Nakama RPC
Before you can submit a transaction to Cardinal, you need to complete 2 key steps:- Create and authenticate a Nakama account
- Create a Persona to attach to the Nakama account.
Authenticating with Nakama
Nakama provides multiple authentication methods that you can easily setup with a few lines of code, such as email/password, device ID, Facebook, Google, etc. You can consult the official documentation (Unity example) for a guide on how to do this.Creating a Persona
Once your client is authenticated using a Nakama account, you can claim a persona and attach it to the account. This is done by calling thenakama/claim-persona
RPC endpoint.
The nakama/claim-persona
RPC endpoint takes in a JSON payload with a single parameter personaTag
that corresponds to the persona tag you want to claim.
Example
Unity/C# Example
Submitting a Transaction
Now that you have authenticated with Nakama and have a persona attached to your account, you can submit a transaction to Cardinal. You don’t have to worry about signing the transaction, as Nakama will handle this for you. You just need to provide the message payload and Nakama will take care of the rest. All Cardinal transactions/messages are automatically registered as a Nakama RPC endpoint with the same format as the REST API endpoint:tx/game/<msg_name>
The
msg_name
is based on the name you passed in when constructing the messaging using NewMessageType
in Cardinal. For example, if you registered a message with the name attack
, the RPC endpoint will be tx/game/attack
.Example
In this example, let’s first define a message on Cardinal with the nameattack
.
/cardinal/msg/attack.go
Unity/C# Example
Viewing Receipts and Events
Game clients can view events emitted in systems as well as the results of iterating over messages by listening for notifications from Nakama.Example
The code to receive notifications will be different depending on the game engine/client you are using. Learn more about how to receive notifications for your game client at Nakama docs. Here are structs that can be used to deserialize notification information. Note, the Receipt.Result field is an arbitrary object that will depend on the exact messages you’ve defined in your game.Unity/C# Example
Unity/C# Example