Read from the Subgraph
Read most data from the blockchain, as well as some additional higher-level fields without querying contracts themselves

Read Only: The subgraph

Most of the data from the blockchain, and additional higher level fields are readable from the subgraph (quick video).
We recommend digging into the Schema yourselves to figure out what is available to query.
Please also pay attention to some example queries we provide on the top left
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 queryingcurrentParticleCharge(address,uint256,string,address)(uint256)

Sample Interaction using Node.js

The sample is in Typescript using ts-node but you can use CommonJs require as well.
1
npm install -D ts-node graphql-request graphql
Copied!
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.
You might also need a tsconfig.json at the root of your project with
1
{ "compilerOptions": { "moduleResolution": "node" } }
Copied!
getFirst20Protons.ts
1
import { request, gql } from 'graphql-request';
2
3
const query = gql`
4
{
5
universes {
6
protonToken {
7
tokens(first:20) {
8
name,
9
tokenId,
10
id
11
creator,
12
owner,
13
salePrice,
14
lastSalePrice,
15
}
16
}
17
}
18
}`
19
20
const doGraphRequest = (endpoint, query, variables={}) => new Promise((resolve, reject) => {
21
request(endpoint, query, variables)
22
.then((data) => resolve(data))
23
.catch(err => reject(err));
24
});
25
26
async function run() {
27
const endpoint = 'https://api.thegraph.com/subgraphs/name/charged-particles/kovan-universe';
28
const res: any = await doGraphRequest(endpoint, query);
29
const { protonToken } = res.universes[0];
30
console.log(protonToken);
31
}
32
33
run();
Copied!
1
# Run it
2
./node_modules/.bin/ts-node getFirst20Protons.ts
3
4
/* Outputs:
5
6
7
{
8
tokens: [
9
{
10
creator: '0xb14d1a16f30db670097da86d4008640c6ccc2b76',
11
id: '0xd4f7389297d9cea850777ea6ccbd7db5817a12b2-1',
12
lastSalePrice: null,
13
name: 'ETH on Mars',
14
owner: '0xb14d1a16f30db670097da86d4008640c6ccc2b76',
15
salePrice: '69000000000000000000',
16
tokenId: '1'
17
},
18
{
19
creator: '0x11113c2fba9ae08d7d16c817f03de51f29117db2',
20
id: '0xd4f7389297d9cea850777ea6ccbd7db5817a12b2-10',
21
lastSalePrice: null,
22
name: 'ha',
23
owner: '0x11113c2fba9ae08d7d16c817f03de51f29117db2',
24
salePrice: '0',
25
tokenId: '10'
26
},
27
...
28
*/
Copied!
If you want access to VSCode debugger and be able to set breakpoints check Debugging so you can use debugger; statement.
Last modified 2mo ago