You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Dojo SDK offers a powerful and intuitive way to interact with your onchain state. It provides a seamless experience for fetching and subscribing to data, supporting both simple and complex queries.
3
+
The Dojo SDK provides a powerful, intuitive interface for interacting with onchain state. It streamlines data fetching and subscriptions, supporting both simple and complex queries.
4
+
5
+
## Table of Contents
6
+
7
+
-[Installation](#installation)
8
+
-[Usage](#usage)
9
+
-[Initializing the SDK](#initializing-the-sdk)
10
+
-[Understanding Queries](#understanding-queries)
11
+
-[Querying Entities](#querying-entities)
12
+
-[Subscribing to Entity Changes](#subscribing-to-entity-changes)
13
+
-[Sending Signed Messages](#sending-signed-messages)
@@ -63,7 +82,7 @@ To take advantage of this type safety (You will need [dojo](https://github.com/d
63
82
64
83
This approach ensures that your code remains in sync with your Dojo world definition, catching potential issues early in the development process.
65
84
66
-
## Usage
85
+
## Initializing the SDK
67
86
68
87
```typescript
69
88
import { init, SchemaType } from "@dojoengine/sdk";
@@ -113,7 +132,7 @@ const db = await init<MockSchemaType>(
113
132
// Voila! Now you have a typed interface
114
133
```
115
134
116
-
## Query Explanation
135
+
## Understanding Queries
117
136
118
137
The SDK utilizes two primary types of queries to interact with the Dojo Engine:
119
138
@@ -125,22 +144,54 @@ Both query types enable filtering based on `entityIds` and specific model proper
125
144
- **`SubscriptionQueryType`**:
126
145
- Supports only the `$is` operator for exact matches.
127
146
- **`QueryType`**:
128
-
- Supports a variety of operators including `$eq`, `$neq`, `$gt`, `$gte`, `$lt`, and `$lte`for more advanced filtering.
129
147
130
-
## Examples
148
+
- Supports a variety of operators for more advanced filtering:
149
+
150
+
| Operator | Description |
151
+
| -------- | ------------------------ |
152
+
|`$eq`| Equal to |
153
+
|`$neq`| Not equal to |
154
+
|`$gt`| Greater than |
155
+
|`$gte`| Greater than or equal to |
156
+
|`$lt`| Less than |
157
+
|`$lte`| Less than or equal to |
158
+
159
+
- You combine queries with 'AND' with 'OR' from deep queries. See [Advanced Usage](#advanced-usage).
131
160
132
-
### Subscribing to Entity Updates
161
+
## Querying Entities
133
162
134
-
This example demonstrates how to subscribe to entity updates in the `world` namespace, specifically for the `item` model. It filters for items where the type is "sword" and the durability is 5. This subscription will trigger the callback functionwhenever an item matching these criteria is updated, created, or deleted.
163
+
This example fetches `player` entities from the `world` namespace where `id` is "1" and `name` is "Alice", demonstrating multiple conditions in a query.
164
+
165
+
Note: `$eq` is for exact matching. Other operators (`$gt`, `$lt`, etc.) are available for complex queries.
This example subscribes to `item` model updates in the `world` namespace, filtering for swords with durability 5. The callback triggers on matching item changes.
console.error("Error setting up entity sync:", response.error);
286
+
} else if (response.data && response.data[0].entityId !== "0x0") {
287
+
// You just need to do this!
288
+
state.setEntities(response.data);
289
+
}
290
+
}
291
+
);
292
+
```
293
+
294
+
## Optimistic Client Rendering
295
+
296
+
<!-- TODO -->
173
297
174
-
This example demonstrates fetching entities from the `world` namespace, specifically the `player` model. It retrieves players where the `id` equals "1" and the `name` equals "Alice". This showcases how to use multiple conditions in a query to precisely filter entities.
298
+
# Advanced Usage
175
299
176
-
Note: The `$eq` operator is used for exact matching. Other operators like `$gt` (greater than), `$lt` (less than), etc., are available for more complex queries.
300
+
Create complex 'AND' with 'OR' statements to narrow in on what you want to fetch.
0 commit comments