# Subsquid for ĞDev

**URL:** https://forum.duniter.org/t/subsquid-for-gdev/10684
**Category:** Indexers
**Tags:** subsquid
**Created:** [2 March 2023 13:10 UTC](https://forum.duniter.org/t/subsquid-for-gdev/10684 "2023-03-02T13:10:18Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [2 March 2023 13:10 UTC](https://forum.duniter.org/t/subsquid-for-gdev/10684/1 "2023-03-02T13:10:18Z")

</div>

Following this subject: [Subsquid (ancienne Hydra): indexer de blockchain substrate exposant des API GraphQL](https://forum.duniter.org/t/subsquid-ancienne-hydra-indexer-de-blockchain-substrate-exposant-des-api-graphql/9074)

I think that now subsquid project has evolved a lot and we might reconsider using it as a framework to develop an other indexer.

```bash
# install squid command line interface
pnpm i -g @subsquid/cli@latest
# check installed version
pnpm i -g @subsquid/cli@latest
# create new repo from template
sqd init duniter-gdev --template substrate

```

Then you can modify your template and follow documentation: [Simple Substrate indexer | Subsquid](https://docs.subsquid.io/quickstart/quickstart-substrate/)

I’ll publish a repo as soon as I get a minimal working example, but feel free to explore in parallel, we might discover complementary things.

We _NEED_ a complete indexer asap to be able to inspect the blockchain easily and build POCs. The `duniter-indexer` strategy is fine at long term, but not relevant for short term in my opinion.

* * *

[edit] at this point I am indexing locally gdev data from remote `gdev.p2p.legal`.  
In Altair extension ([https://altairgraphql.dev/](https://altairgraphql.dev/)), I can run this request by connecting to [http://localhost:8888/graphql](http://localhost:8888/graphql)

```auto
query MyQuery {
  metadata {
      specName
  }
}

```

which returns

```auto
{
  "data": {
    "metadata": [
      {
        "specName": "gdev"
      }
    ]
  }
}

```

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [10 March 2023 12:32 UTC](https://forum.duniter.org/t/subsquid-for-gdev/10684/2 "2023-03-10T12:32:58Z")

</div>

I made some progress on this subject, I am able to submit a request like:

```auto
{
  batch(
    limit: 10
    includeAllBlocks: false
    events: [{ name: "AuthorityMembers.MemberGoOnline" }]
  ) {
    header {
      height
    }
    events
  }
}

```

and get an answer :

```json
{
  "data": {
    "batch": [
      {
        "header": {
          "height": 7021
        },
        "events": [
          {
            "args": 2457,
            "callId": "0000007021-000001-72b7b",
            "extrinsicId": "0000007021-000001-72b7b",
            "id": "0000007021-000002-72b7b",
            "indexInBlock": 2,
            "name": "AuthorityMembers.MemberGoOnline",
            "phase": "ApplyExtrinsic",
            "pos": 4
          }
        ]
      },
      {
        "header": {
          "height": 38961
        },
        "events": [
          {
            "args": 7139,
            "callId": "0000038961-000001-99384",
            "extrinsicId": "0000038961-000001-99384",
            "id": "0000038961-000002-99384",
            "indexInBlock": 2,
            "name": "AuthorityMembers.MemberGoOnline",
            "phase": "ApplyExtrinsic",
            "pos": 4
          }
        ]
      },
      {
        "header": {
          "height": 290054
        },
        "events": [
          {
            "args": 7139,
            "callId": "0000290054-000001-723f3",
            "extrinsicId": "0000290054-000001-723f3",
            "id": "0000290054-000002-723f3",
            "indexInBlock": 2,
            "name": "AuthorityMembers.MemberGoOnline",
            "phase": "ApplyExtrinsic",
            "pos": 4
          }
        ]
      }
    ]
  }
}

```

It is still indexing locally. When I’m happy with the result, I will share how to do.  
The tricky part was the capital letter at the beginning of the event pallet which is not present on polkadotjsapp.

Right now, it’s still a simple docker compose running subsquid instance and connected to `gdev.p2p.legal` endpoint.

> **docker-compose.yml**
>
> ```auto
> services:
> db:
> image: postgres:15 # CockroachDB cluster might be a better fit for production deployment
> restart: always
> volumes:
> - /var/lib/postgresql/data
> environment:
> POSTGRES_USER: postgres
> POSTGRES_PASSWORD: postgres
> POSTGRES_DB: squid-archive
> 
> ingest:
> depends_on:
> - db
> restart: on-failure
> image: subsquid/substrate-ingest:firesquid
> command: [
> "-e", "wss://gdev.p2p.legal/ws",
> "-c", "5", # allow up to 20 pending requests for the above endpoint (default is 5)
> # "--start-block", "1000000", # uncomment to specify a non-zero start block
> "--out", "postgres://postgres:postgres@db:5432/squid-archive"
> ]
> 
> gateway:
> depends_on:
> - db
> image: subsquid/substrate-gateway:firesquid
> environment:
> RUST_LOG: "substrate_gateway=info,actix_server=info"
> command: [
> "--database-url", "postgres://postgres:postgres@db:5432/squid-archive",
> "--database-max-connections", "3", # max number of concurrent database connections
> # "--evm-support" # uncomment for chains with Frontier EVM pallet
> # (e.g. Moonbeam/Moonriver or Astar/Shiden)
> ]
> ports:
> - "8888:8000"
> 
> # Explorer service is optional.
> # It provides rich GraphQL API for querying archived data.
> # Many developers find it very useful for exploration and debugging.
> explorer:
> image: subsquid/substrate-explorer:firesquid
> environment:
> DB_TYPE: postgres # set to `cockroach` for Cockroach DB
> DB_HOST: db
> DB_PORT: "5432"
> DB_NAME: "squid-archive"
> DB_USER: "postgres"
> DB_PASS: "postgres"
> ports:
> - "4444:3000"
> 
> ```

I want to see how they suggest to implement custom indexing and how it compares to current duniter-indexer.

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [13 March 2023 16:16 UTC](https://forum.duniter.org/t/subsquid-for-gdev/10684/3 "2023-03-13T16:16:19Z")

</div>

I set up a public generic subsquid indexer for ĞDev which can be accessed here: [https://subsquid.gdev.coinduf.eu/](https://subsquid.gdev.coinduf.eu/)

You can know the latest indexed block with

```auto
{
  status {
    head
  }
}

```

which returns something like

```auto
{
  "data": {
    "status": {
      "head": 1276102
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [13 March 2023 16:25 UTC](https://forum.duniter.org/t/subsquid-for-gdev/10684/4 "2023-03-13T16:25:00Z")

</div>

In bonus, you also have the explorer at [https://explorer.subsquid.gdev.coinduf.eu/graphql](https://explorer.subsquid.gdev.coinduf.eu/graphql).  
It can for example get the events `Balances.Transfer` where the the amount is 314.

```auto
query MyQuery {
  events(limit: 3, where: {args_jsonContains: "{\"amount\":\"314\"}", name_eq: "Balances.Transfer"}) {
    name
    args
  }
}

```

```auto
{
  "data": {
    "events": [
      {
        "name": "Balances.Transfer",
        "args": {
          "to": "0xb2c04f16d0b7069bf237675bfbdf8a0eab4d6fa790f2a1d545ceb6c73428e6d5",
          "from": "0x0ed0734a282c8d3551694d74e12f6ec9a568770ad351a67303994908b638071b",
          "amount": "314"
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

### Author: ![cgeek](https://forum.duniter.org/user_avatar/forum.duniter.org/cgeek/32/279_2.png) [@cgeek](https://forum.duniter.org/u/cgeek)
#### Post date: [14 March 2023 18:19 UTC](https://forum.duniter.org/t/subsquid-for-gdev/10684/5 "2023-03-14T18:19:44Z")

</div>

> [@HugoTrentesaux](#):
>
> The `duniter-indexer` strategy is fine at long term, but not relevant for short term in my opinion.

Could you be more specific? I agree with the fact an indexer is quickly and absolutely necessary. But I don’t get why duniter-indexer could not feat this requirement.

---

<div class="post-metadata">

### Author: ![poka](https://forum.duniter.org/user_avatar/forum.duniter.org/poka/32/6827_2.png) [@poka](https://forum.duniter.org/u/poka)
#### Post date: [14 March 2023 18:28 UTC](https://forum.duniter.org/t/subsquid-for-gdev/10684/6 "2023-03-14T18:28:59Z")

</div>

Because compare to subsquid, an homemade indexer will not have all blockchain schema and exhaustive data available, we have to implement everything we want as we go along.

Subsquid comes with everything needed to analyze our blockchain out of the box.

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [14 March 2023 19:51 UTC](https://forum.duniter.org/t/subsquid-for-gdev/10684/7 "2023-03-14T19:51:23Z")

</div>

See also: [Why we need a full featured indexer?](https://forum.duniter.org/t/why-we-need-a-full-featured-indexer/10720) 😺

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [26 March 2023 15:35 UTC](https://forum.duniter.org/t/subsquid-for-gdev/10684/8 "2023-03-26T15:35:19Z")

</div>

An other thing which is very useful to help debug other users is the request:

```auto
{
  batch(
    limit: 10
    includeAllBlocks: false
    events: [{ name: "System.ExtrinsicFailed" }]
    fromBlock: 1430000
    toBlock: 1460000
  ) {
    header {
      height
      hash
    }    
  }
}

```

It allows to see the failed extrinsics in a given timeframe.

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [29 March 2023 11:02 UTC](https://forum.duniter.org/t/subsquid-for-gdev/10684/9 "2023-03-29T11:02:00Z")

</div>

> [@ĞDev indexer](https://forum.duniter.org/t/gdev-indexer/9481/45):
>
> @HugoTrentesaux ça te dit une d’organiser une petit atelier Subsquid en partage d’écran sur jitsi, qu’on regarde ça ensemble pour ceux que ça intéresse ?

Je n’ai pas grand chose à partager à ce sujet, j’ai mis tout ce que j’avais sur le sujet ci-dessus :

- docker-compose pour lancer subsquid (firesquid)
- endpoint graphql public pour le requêter
- exemples de requêtes quand je m’en sers

Par contre, je peux faire comme propose Pini

> [@ĞDev indexer](https://forum.duniter.org/t/gdev-indexer/9481/46):
>
> Un peu de vulgarisation sur ces indexeurs

Mais en ce moment je me sens un peu débordé, je vais essayer d’expliciter mes priorités du moment pour clarifier.
