Quests Integration Guide
1 - Fill out Quest metadata form
In order for us to set up a Quest for a game within the Treasure Platform, the following details will need to be collected (see here for a Google Sheets template to provide quests in bulk).
- Quest Name
- Name of the associated game
- Quest Description: A non-technical definition of what a player needs to do to achieve this quest (73 character limit is preferred).
- Start and End Dates: Provide a UTC date + timestamp (e.g.,
2024-06-07T16:00:00Z
). - CTA Link: The URL that the player will need to navigate to to work on said quest
- Badge (optional): to accompany this specific quest. See the Badge Design Guide for more details.
- Quest Mechanics : To help us normalize rewards please provide approximate scores in the following categories:
- Friction Score: On a scale of 1-10 with 10 being most friction, how much friction does a player need to go through in order to complete this quest?
- Difficulty Score: On a scale of 1-10 with 10 being most difficult, how much skill does a player need to complete this quest?
- Time Required: On average, how much time (in hrs) will a player need to commit to complete this quest?
- Quest Event Schema: Tell us the schema for your event payload. See Step (2).
- Quest Denominator (integer): This is the
denominator
field described in the technical criteria step. - Quest Numerator (query): Tell us the SQL query to use to compute the
numerator
for this quest. The quest is complete whennumerator >= denominator
. See the “Create a Quest query” for details on the syntax (Treasure team can assist you with formulating this query if needed).
2 - Prepare your payload
The required fields are
cartridge_tag
name
time_server
(a string representation of an integer)smart_account
(oruser_id
)id
(for the event)properties
(a JSON object containing game-specific event data)
Recommended and optional fields are indicated in the schema below.
The other fields you add within properties
can be JSON scalar, array, or object types.
Your Event Payload schema should have the following format.
A TypeScript version of your schema.
Examples payloads
3 - Push game events to Treasure
From your backend, push your event payloads to our infra. You can choose from the following methods: Kafka, HTTP POST, or AWS SNS.
There is no need for you to set up your own Kafka cluster with this approach. Just send messages to a dedicated Redpanda Kafka topic that Treasure manages for you.
-
Receive Kafka client credentials (username, password, bootstrap URL) from Treasure.
-
Send your JSON payloads using a Kafka producer client. Kafka client libraries are available in a number of languages. The following example is in TypeScript (assumes you have already installed
kafkajs@2.2.4
):
4 - Create a Quest query
Aside from the usual Quest metadata (name, description, optional image, start/end dates), you’ll need to tell us
- What
cartridge_tag
+name
to filter for. - The value for the quest’s
denominator
. - How to count/sum/aggregate the quest’s
numerator
from the set of filtered events.
A quest is complete when numerator >= denominator
. You can express the numerator computation as an aggregate query over the DB.
We currently support PostgreSQL syntax. The following special variables will be subbed into your SQL query:
{{START_DATE_MILLIS}}
(the start date of the quest in UNIX milliseconds){{END_DATE_MILLIS}}
(the end date of the quest in UNIX milliseconds){{START_DATE_SECONDS}}
(the start date of the quest in UNIX seconds){{END_DATE_SECONDS}}
(the end date of the quest in UNIX seconds){{USER_ADDRESS}}
(the player’s wallet address)
Appendix
Quest query examples
We provide a few simple example queries here.
Combining on-chain + off-chain quest criteria
Using Goldsky’s Mirror pipelines, Darkmatter is able to ingest on-chain events and transactions, allow us to make queries that combine web3 and web2 data.
If you’d like us to ingest your on-chain data to use for Quests, here are the steps.
Provide event signature
Give Treasure the event signature that you want us to index. Example: Stamp(uint256 indexed stampId, address indexed caller, uint256 nonce)
If your event is defined in a widely adopted standard (like ERC20, ERC721, etc), then please tell us which
chain
and contract_address
to listen for as well.
Table setup
Treasure will set up a table containing those events. In our example, that table would be contract_events.stamp
. Note that event_params
JSONB captures the event parameters for an emitted event Stamp(13, 0xabcde123456789012345678901234567890abcde, 69)
.
Construct SQL query
Construct a SQL query to compute the numerator
for you quest. Example for a quest whose goal is to “win at least 1 match and produce an on-chain Stamp
with nonce 69 or 420”: