# Read from the Subgraph

## Read Only: The subgraph

Most of the data from the blockchain, and additional higher level fields are readable from the [subgraph](https://thegraph.com/) ([quick video](https://www.youtube.com/watch?v=l2rzT_Dp4T0)).

Kovan: <https://thegraph.com/explorer/subgraph/charged-particles/kovan-universe?query=Protons%20NFTs>

&#x20;We recommend digging into the **Schema** yourselves to figure out what is available to query.

![](/files/-MW7ESsPZVc5TUxAmJxz)

Please also pay attention to some example queries we provide on the top left

![](/files/-MW7IYjISqAa5aZQxeU-)

{% hint style="info" %}
Almost all the information available from the contracts is available somewhere on the subgraph, besides the **current accrued interest** (ie: *how much my DAI at 12% APY in my ProtonNFT made me*) which is currently available only by [contract querying](https://docs.charged.fi/charged-particles-protocol/smart-contracts-documentation/interfaces/charged-particles-interface)`currentParticleCharge(address,uint256,string,address)(uint256)`
{% endhint %}

### Sample Interaction using Node.js

The sample is in Typescript using `ts-node` but you can use CommonJs require as well.

```yaml
npm install -D ts-node graphql-request graphql
```

`graphql-request` is the most minimal and simplest to use GraphQL client. It's perfect for small scripts or simple apps. But **it doesn't allow you to listen for changes** for this, please use something like [apollo-client](https://www.npmjs.com/package/apollo-client).

You might also need a `tsconfig.json` at the root of your project with&#x20;

```typescript
{ "compilerOptions": { "moduleResolution": "node" } }
```

until <https://github.com/prisma-labs/graphql-request/issues/214> is resolved.

{% code title="getFirst20Protons.ts" %}

```typescript
import { request, gql } from 'graphql-request';

const query = gql`
{
   universes {
     protonToken {
       tokens(first:20) {
         name,
         tokenId,
         id
         creator,
         owner,
         salePrice,
         lastSalePrice,
       }
     }
   }
 }`
 
 const doGraphRequest = (endpoint, query, variables={}) => new Promise((resolve, reject) => {
  request(endpoint, query, variables)
    .then((data) => resolve(data))
    .catch(err => reject(err));
});

async function run() {
  const endpoint = 'https://api.thegraph.com/subgraphs/name/charged-particles/kovan-universe';
  const res: any = await doGraphRequest(endpoint, query);
  const { protonToken } = res.universes[0];
  console.log(protonToken);
}

run();
```

{% endcode %}

```typescript
# Run it
./node_modules/.bin/ts-node getFirst20Protons.ts

/* Outputs:


{
  tokens: [
    {
      creator: '0xb14d1a16f30db670097da86d4008640c6ccc2b76',
      id: '0xd4f7389297d9cea850777ea6ccbd7db5817a12b2-1',
      lastSalePrice: null,
      name: 'ETH on Mars',
      owner: '0xb14d1a16f30db670097da86d4008640c6ccc2b76',
      salePrice: '69000000000000000000',
      tokenId: '1'
    },
    {
      creator: '0x11113c2fba9ae08d7d16c817f03de51f29117db2',
      id: '0xd4f7389297d9cea850777ea6ccbd7db5817a12b2-10',
      lastSalePrice: null,
      name: 'ha',
      owner: '0x11113c2fba9ae08d7d16c817f03de51f29117db2',
      salePrice: '0',
      tokenId: '10'
    },
    ...
*/
```

{% hint style="info" %}
If you want access to [**VSCode debugger**](/charged-particles-protocol/developing-on-the-protocol/quickstart/vscode-node.js-typescript-debugging.md#debugging-ts-node) and be able to set breakpoints check Debugging so you can use `debugger;` statement.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.charged.fi/charged-particles-protocol/developing-on-the-protocol/quickstart/read-from-the-subgraph.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
