重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
npx skills add https://github.com/dojoengine/book --skill dojo-indexer设置并使用 Torii(Dojo 索引器),以实现对世界状态的高效查询和实时订阅。
管理 Torii 索引器:
启动 Torii:
torii --world <WORLD_ADDRESS>
这将使用默认设置启动 Torii:
http://localhost:8080/graphqlhttp://localhost:8080启用控制器索引(推荐):
torii --world <WORLD_ADDRESS> --indexing.controllers
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
torii --world <WORLD_ADDRESS> --db-dir ./torii-db --indexing.controllers
Torii 是 Dojo 索引器,它:
为何使用 Torii:
Torii 在 http://localhost:8080/graphql 提供 GraphQL 端点。
在浏览器中使用 GraphiQL IDE 来探索模式和测试查询。
Torii 生成两种类型的查询:
通用查询:
entities - 访问所有实体(支持过滤)models - 检索模型定义transactions - 查询已索引的交易模型特定查询:
{modelName}Models - 每个模型的自定义查询positionModels、movesModels获取模型的所有实体:
query {
movesModels {
edges {
node {
player
remaining
last_direction
}
}
}
}
获取模型元数据:
query {
models {
edges {
node {
id
name
classHash
contractAddress
}
}
totalCount
}
}
基于游标的分页:
query {
entities(first: 10) {
edges {
cursor
node {
id
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
获取下一页:
query {
entities(first: 10, after: "cursor_value") {
edges {
cursor
node { id }
}
}
}
偏移量/限制分页:
query {
entities(offset: 20, limit: 10) {
edges {
node { id }
}
totalCount
}
}
通过 WebSocket 订阅世界状态变化。
subscription {
entityUpdated(id: "0x54f58...") {
id
updatedAt
models {
__typename
... on Position {
vec {
x
y
}
}
... on Moves {
remaining
}
}
}
}
监控所有世界事件:
subscription {
eventEmitted {
id
keys
data
transactionHash
}
}
监听新模型注册:
subscription {
modelRegistered {
id
name
namespace
}
}
Torii 将数据存储在 SQLite 中,可用于复杂查询。
连接到数据库:
sqlite3 torii.db
查询示例:
-- Count entities
SELECT COUNT(*) FROM entities;
-- Custom aggregations
SELECT AVG(value) FROM model_data WHERE model_name = 'Health';
import { createClient } from '@dojoengine/torii-client';
const client = await createClient({
rpcUrl: "http://localhost:5050",
toriiUrl: "http://localhost:8080",
worldAddress: WORLD_ADDRESS,
});
// Query entities
const positions = await client.getEntities({
model: "Position",
limit: 10
});
// Subscribe to updates
await client.onEntityUpdated(
[{ model: "Position", keys: [playerId] }],
(entity) => console.log("Position updated:", entity)
);
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
const client = new ApolloClient({
uri: 'http://localhost:8080/graphql',
cache: new InMemoryCache(),
});
const { data } = await client.query({
query: gql`
query GetMoves {
movesModels {
edges {
node {
player
remaining
}
}
}
}
`
});
| 选项 | 描述 | 默认值 |
|---|---|---|
--world | 世界合约地址 | 可选(自 Torii 1.6.0 起) |
--rpc | RPC 端点 URL | http://localhost:5050 |
--db-dir | 数据库目录 | 内存 |
--config | TOML 配置文件路径 | 无 |
--http.cors_origins | CORS 来源 | * |
Slot 提供托管的 Torii 实例。Slot 需要一个 TOML 配置文件。
# torii.toml
world_address = "<WORLD_ADDRESS>"
rpc = "<RPC_URL>"
[indexing]
controllers = true
有关所有 TOML 选项(索引、轮询、命名空间等),请参阅 Torii 配置指南。
slot auth login
slot deployments create <PROJECT_NAME> torii --config torii.toml --version <DOJO_VERSION>
# 流式传输日志
slot deployments logs <PROJECT_NAME> torii -f
# 删除并重新创建(安全 — 所有数据都在链上)
slot deployments delete <PROJECT_NAME> torii
终端 1:启动 Katana
katana --dev --dev.no-fee
终端 2:部署世界
sozo build && sozo migrate
终端 3:启动 Torii
torii --world <WORLD_ADDRESS> --http.cors_origins "*"
entities 查询设置 Torii 后:
dojo-client 技能)每周安装次数
59
代码仓库
GitHub 星标数
53
首次出现
2026年1月30日
安全审计
安装于
opencode56
codex55
kimi-cli54
gemini-cli54
cursor54
github-copilot53
Set up and use Torii, the Dojo indexer, for efficient querying and real-time subscriptions to your world state.
Manages Torii indexer:
Start Torii:
torii --world <WORLD_ADDRESS>
This starts Torii with default settings:
http://localhost:8080/graphqlhttp://localhost:8080With Controller indexing (recommended):
torii --world <WORLD_ADDRESS> --indexing.controllers
Production configuration:
torii --world <WORLD_ADDRESS> --db-dir ./torii-db --indexing.controllers
Torii is the Dojo indexer that:
Why use Torii:
Torii provides GraphQL endpoint at http://localhost:8080/graphql
Use the GraphiQL IDE in your browser to explore the schema and test queries.
Torii generates two types of queries:
Generic Queries:
entities - Access all entities with filteringmodels - Retrieve model definitionstransactions - Query indexed transactionsModel-Specific Queries:
{modelName}Models - Custom queries for each modelpositionModels, movesModelsGet all entities of a model:
query {
movesModels {
edges {
node {
player
remaining
last_direction
}
}
}
}
Get model metadata:
query {
models {
edges {
node {
id
name
classHash
contractAddress
}
}
totalCount
}
}
Cursor-based pagination:
query {
entities(first: 10) {
edges {
cursor
node {
id
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
Get next page:
query {
entities(first: 10, after: "cursor_value") {
edges {
cursor
node { id }
}
}
}
Offset/limit pagination:
query {
entities(offset: 20, limit: 10) {
edges {
node { id }
}
totalCount
}
}
Subscribe to world state changes via WebSocket.
subscription {
entityUpdated(id: "0x54f58...") {
id
updatedAt
models {
__typename
... on Position {
vec {
x
y
}
}
... on Moves {
remaining
}
}
}
}
Monitor all world events:
subscription {
eventEmitted {
id
keys
data
transactionHash
}
}
Listen for new model registrations:
subscription {
modelRegistered {
id
name
namespace
}
}
Torii stores data in SQLite, accessible for complex queries.
Connect to database:
sqlite3 torii.db
Example queries:
-- Count entities
SELECT COUNT(*) FROM entities;
-- Custom aggregations
SELECT AVG(value) FROM model_data WHERE model_name = 'Health';
import { createClient } from '@dojoengine/torii-client';
const client = await createClient({
rpcUrl: "http://localhost:5050",
toriiUrl: "http://localhost:8080",
worldAddress: WORLD_ADDRESS,
});
// Query entities
const positions = await client.getEntities({
model: "Position",
limit: 10
});
// Subscribe to updates
await client.onEntityUpdated(
[{ model: "Position", keys: [playerId] }],
(entity) => console.log("Position updated:", entity)
);
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
const client = new ApolloClient({
uri: 'http://localhost:8080/graphql',
cache: new InMemoryCache(),
});
const { data } = await client.query({
query: gql`
query GetMoves {
movesModels {
edges {
node {
player
remaining
}
}
}
}
`
});
| Option | Description | Default |
|---|---|---|
--world | World contract address | Optional (since Torii 1.6.0) |
--rpc | RPC endpoint URL | http://localhost:5050 |
--db-dir | Database directory | In-memory |
--config | Path to TOML configuration file | None |
--http.cors_origins |
Slot provides hosted Torii instances. Slot requires a TOML configuration file.
# torii.toml
world_address = "<WORLD_ADDRESS>"
rpc = "<RPC_URL>"
[indexing]
controllers = true
See the Torii configuration guide for all TOML options (indexing, polling, namespaces, etc.).
slot auth login
slot deployments create <PROJECT_NAME> torii --config torii.toml --version <DOJO_VERSION>
# Stream logs
slot deployments logs <PROJECT_NAME> torii -f
# Delete and recreate (safe — all data is on-chain)
slot deployments delete <PROJECT_NAME> torii
Terminal 1: Start Katana
katana --dev --dev.no-fee
Terminal 2: Deploy world
sozo build && sozo migrate
Terminal 3: Start Torii
torii --world <WORLD_ADDRESS> --http.cors_origins "*"
entitiesAfter Torii setup:
dojo-client skill)Weekly Installs
59
Repository
GitHub Stars
53
First Seen
Jan 30, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode56
codex55
kimi-cli54
gemini-cli54
cursor54
github-copilot53
Azure 升级评估与自动化工具 - 轻松迁移 Functions 计划、托管层级和 SKU
127,000 周安装
Wiki 架构师:AI 代码库文档生成工具,自动创建结构化维基和入门指南
69 周安装
YAML配置验证器 - DevOps自动化工具,支持CI/CD与容器化最佳实践
71 周安装
Prompt Generator - AI提示词生成器 | GitHub星标1.2K | 支持Claude/Codex/Cursor等开发工具
68 周安装
商业方案撰写专家 | AI驱动的专业咨询提案写作工具与框架指南
45 周安装
营销数据分析专家:SOSTAC控制、归因建模、A/B测试与ROI分析
68 周安装
React性能优化指南:Next.js应用消除瀑布流与包体积优化
69 周安装
| CORS origins |
* |