This document explains how game developers can use the API to send confirmed game events.
Developers need to implement an indexer (in this example, Apibara) that tracks events in the game and sends corresponding requests to the API.
To authenticate API requests, a secret is required, which is unique for each game. You can obtain it by contacting us.
Developers must provide a predefined list of possible actions that will be tracked and sent to the API. These actions must represent events that have already occurred, such as:
"Zombie killed""Iron Mined""Match Won"
Only actions from the provided list will be accepted by the system.
The API accepts POST requests to the following URL:
POST $API_URL/api/v2/action-dispatcher/dispatch/public
{
"actions": ["Zombie killed", "Iron Mined"],
"playerAddress": "0x123456789abcdef"
}{
"secret": "GAME_UNIQUE_SECRET",
"Content-Type": "application/json"
}Success: { "status": "success" }
Error: Returns 400
Example of request code is in utils/push-actions.ts
Below is an example of an Apibara indexer that tracks events and sends them to the API.
Example indexer listens to two types of events:
- START_GAME: Triggers when a game starts.
- ADVENTURER_UPGRADED: Triggers when an adventurer is upgraded.
filter: {
events: [
{
address: config.gameAddress,
keys: [START_GAME],
},
{
address: config.gameAddress,
keys: [ADVENTURER_UPGRADED],
},
],
},Each event is processed, and the corresponding action is pushed to the API.
START_GAMEmaps to the action"Game started".ADVENTURER_UPGRADEDmaps to the action"Adventurer upgraded".
block.events.map((event) => {
switch (event.keys[0]) {
case START_GAME: {
const { value } = parseStartGame(event.data, 0);
const owner = numberToHex(BigInt(value.adventurerState.owner));
payloads.push({ actions: ["Game started"], address: owner });
break;
}
case ADVENTURER_UPGRADED: {
const { value } = parseAdventurerUpgraded(event.data, 0);
const owner = numberToHex(
BigInt(value.adventurerStateWithBag.adventurerState.owner ?? 0)
);
payloads.push({ actions: ["Adventurer upgraded"], address: owner });
break;
}
}
});The collected actions are sent to the API using pushActions.
try {
const promises = payloads.map((payload) => pushActions(payload));
await Promise.all(promises);
} catch (error) {
logger.error("Failed to push actions", error);
}Example of indexing code coult be found at indexers/adventurers.indexrer.ts