Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .gitbook/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,26 @@
"jp/developers-native/query-chain/wasmx",
"jp/developers-native/query-chain/token-factory"
]
}
},
{
"group": "Indexerのクエリ",
"pages": [
"jp/developers-native/query-indexer/index",
"jp/developers-native/query-indexer/account",
"jp/developers-native/query-indexer/auction",
"jp/developers-native/query-indexer/derivatives",
"jp/developers-native/query-indexer/explorer",
"jp/developers-native/query-indexer/insurance-funds",
"jp/developers-native/query-indexer/markets",
"jp/developers-native/query-indexer/leaderboard",
"jp/developers-native/query-indexer/mito",
"jp/developers-native/query-indexer/oracle",
"jp/developers-native/query-indexer/portfolio",
"jp/developers-native/query-indexer/spot",
"jp/developers-native/query-indexer/transaction"
]
},
"jp/developers-native/query-ethereum"
]
},
{
Expand Down
114 changes: 114 additions & 0 deletions .gitbook/jp/developers-native/query-ethereum.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
title: GraphQLエンドポイントのクエリ
updatedAt: "2025-12-23"
---

このガイドでは、`@injectivelabs/utils`の`HttpClient`を使用してGraphQLエンドポイントをクエリする方法について説明します。

## セットアップ

```ts
import { HttpClient } from '@injectivelabs/utils'

const client = new HttpClient('YOUR_GRAPHQL_ENDPOINT')
```

## 認証

GraphQLエンドポイントが認証を必要とする場合は、ヘッダーを設定します:

```ts
client.setConfig({
headers: {
authorization: 'Bearer YOUR_API_KEY'
}
})
```

## クエリの実行

GraphQLクエリは、`query`と必要に応じて`variables`を含むJSON文字列として構成します:

```ts
const query = JSON.stringify({
query: `
query GetData($id: ID!) {
entity(id: $id) {
id
name
value
}
}
`,
variables: {
id: '123'
}
})

const response = await client.post<string, { data: { data: YourResponseType } }>('', query)

console.log(response.data.data)
```

## 完全な例

```ts
import { HttpClient } from '@injectivelabs/utils'

interface Token {
id: string
symbol: string
name: string
}

interface TokensResponse {
tokens: Token[]
}

const client = new HttpClient('YOUR_GRAPHQL_ENDPOINT')

// Set auth headers if required
client.setConfig({
headers: {
authorization: 'Bearer YOUR_API_KEY'
}
})

const query = JSON.stringify({
query: `
query GetTokens($first: Int!) {
tokens(first: $first, orderBy: symbol) {
id
symbol
name
}
}
`,
variables: {
first: 10
}
})

const response = await client.post<string, { data: { data: TokensResponse } }>('', query)

console.log(response.data.data.tokens)
```

## エラーハンドリング

GraphQLのレスポンスはステータスコード200でもエラーを含む場合があります。常にエラーをチェックしてください:

```ts
interface GraphQLResponse<T> {
data?: T
errors?: Array<{ message: string }>
}

const response = await client.post<string, { data: GraphQLResponse<YourResponseType> }>('', query)

if (response.data.errors && response.data.errors.length > 0) {
throw new Error(response.data.errors[0].message)
}

const data = response.data.data
```
166 changes: 166 additions & 0 deletions .gitbook/jp/developers-native/query-indexer/account.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
title: Account
updatedAt: "2025-12-23"
---

subaccount関連のデータをindexerでクエリするためのコードスニペット例。

## gRPCを使用する

### ユーザーのportfolioの詳細を取得する

利用可能残高、未実現損益(unrealized PnL)、portfolioの価値などが含まれます。注: **非推奨** → 代わりに [Portfolio](../query-indexer/portfolio/#using-grpc) を使用してください。

```ts
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts/client/indexer";

const endpoints = getNetworkEndpoints(Network.Testnet);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);

const injectiveAddress = "inj...";

const portfolio = await indexerGrpcAccountApi.fetchPortfolio(injectiveAddress);

console.log(portfolio);
```

### epochごとのユーザーのtrading rewardsを取得する

```ts
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts/client/indexer";

const endpoints = getNetworkEndpoints(Network.Testnet);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);

const injectiveAddress = "inj...";
const epoch = -1; // current epoch

const tradingRewards = await indexerGrpcAccountApi.fetchRewards({
address: injectiveAddress,
epoch,
});

console.log(tradingRewards);
```

### injective addressに関連付けられたsubaccountsを取得する

```ts
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts/client/indexer";

const endpoints = getNetworkEndpoints(Network.Testnet);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);

const injectiveAddress = "inj...";

const subaccountsList = await indexerGrpcAccountApi.fetchSubaccountsList(
injectiveAddress
);

console.log(subaccountsList);
```

### 特定のdenomに対するsubaccountの残高を取得する

```ts
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts/client/indexer";

const endpoints = getNetworkEndpoints(Network.Testnet);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);

const subaccountId = "0x...";
const denom = "inj";

const subaccountBalance = await indexerGrpcAccountApi.fetchSubaccountBalance(
subaccountId,
denom
);

console.log(subaccountBalance);
```

### subaccountの残高一覧を取得する

```ts
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts/client/indexer";

const endpoints = getNetworkEndpoints(Network.Testnet);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);

const subaccountId = "0x...";

const subaccountBalanceList =
await indexerGrpcAccountApi.fetchSubaccountBalancesList(subaccountId);

console.log(subaccountBalanceList);
```

### subaccountの履歴を取得する

```ts
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
import { PaginationOption } from '@injectivelabs/sdk-ts/types'
import { IndexerGrpcAccountApi } from '@injectivelabs/sdk-ts/client/indexer'

const endpoints = getNetworkEndpoints(Network.Testnet)
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer)

const subaccountId = '0x...'
const denom = 'inj'
const pagination = {...} as PaginationOption

const subaccountHistory = await indexerGrpcAccountApi.fetchSubaccountHistory({
subaccountId,
denom,
pagination /* optional param */
})

console.log(subaccountHistory)
```

### subaccountのordersの概要を取得する

```ts
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts/client/indexer";

const endpoints = getNetworkEndpoints(Network.Testnet);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);

const subaccountId = "0x...";
const marketId = "0x";
const orderDirection = "buy";

const orderSummary = await indexerGrpcAccountApi.fetchSubaccountOrderSummary({
subaccountId,
marketId,
orderDirection,
});

console.log(orderSummary);
```

### spotまたは(および)derivatives ordersの状態を取得する

```ts
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
import { IndexerGrpcAccountApi } from "@injectivelabs/sdk-ts/client/indexer";

const endpoints = getNetworkEndpoints(Network.Testnet);
const indexerGrpcAccountApi = new IndexerGrpcAccountApi(endpoints.indexer);

const spotOrderHashes = ["0x..."];
const derivativeOrderHashes = ["0x..."];

const orderStates = await indexerGrpcAccountApi.fetchOrderStates({
spotOrderHashes,
derivativeOrderHashes,
});

console.log(orderStates);
```
38 changes: 38 additions & 0 deletions .gitbook/jp/developers-native/query-indexer/auction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Auction
updatedAt: "2025-12-23"
---

auctionモジュール関連のデータをindexerでクエリするためのコードスニペット例。

## gRPCを使用する

### ラウンドに基づいてauctionを取得する

```ts
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
import { IndexerGrpcAuctionApi } from "@injectivelabs/sdk-ts/client/indexer";

const endpoints = getNetworkEndpoints(Network.Testnet);
const indexerGrpcAuctionApi = new IndexerGrpcAuctionApi(endpoints.indexer);

const round = 1;

const auction = await indexerGrpcAuctionApi.fetchAuction(round);

console.log(auction);
```

### auctionsを取得する

```ts
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
import { IndexerGrpcAuctionApi } from "@injectivelabs/sdk-ts/client/indexer";

const endpoints = getNetworkEndpoints(Network.Testnet);
const indexerGrpcAuctionApi = new IndexerGrpcAuctionApi(endpoints.indexer);

const auction = await indexerGrpcAuctionApi.fetchAuctions();

console.log(auction);
```
Loading