An example Starknet subgraph for testing Starknet Graph setup
This simple subgraph that tracks the number of inbound and outbound transfers of the Ether token on starknet-mainnet.
Note
It's important to note that Starknet was initially launched without events, which means the oldest blocks contain no events at all. Since we're tracking ETH Transfer events here, it would be helpful to know that the first ever ETH Transfer event on mainnet was emitted in this transaction on block 2823. The subgraph would have no data if the Firehose stack hasn't synced past this block yet.
This project requires Node.js to be installed.
You must also have a working Firehose Starknet stack with a properly configured graph-node connected to it:
- You can get the whole stack (including Firehose and
graph-node) up and running with a single command by following the quickstart guide. - Alternatively, you can set up a Firehose stack following the official docs, and configure a
graph-nodeinstance to connect to it as a Firehose provider.
Note
If you follow option 2 and you're using the official graph-node distribution (instead of the fork available in starknet-graph), make sure you're using version 0.33.0 or later, as earlier versions do not have Starknet support built in.
Note that the Starknet support in graph-node is still a work-in-progress. Improvements on features and performance are constantly being added. Make sure to upgrade your graph-node instances as newer versions become available.
Clone and change directory into the repository, then install dependencies:
yarn installThen generate code based on ABI and subgraph definition:
yarn codegenBuild the subgraph:
yarn buildNow you're ready to deploy the subgraph! Make sure your graph-node exposes a JSON-RPC endpoint at localhost:8020, and an IPFS node is available at localhost:5001, then run this command to create the subgraph:
yarn create-localand this command to deploy the subgraph:
yarn deploy-localNote
If your graph-node and IPFS endpoints are not available on the expected localhost ports, you'll need to run this command directly for subgraph creation:
yarn graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 starknet/exampleand this command for deployment:
yarn graph create --node http://localhost:8020/ starknet/examplewhere http://localhost:8020/ and http://localhost:5001 are replaced by the actual URL.
As noted above, the subgraph will only have data if it's synced past block 2823. Once that happens, you can make subgraph queries like so (assuming that the graph-node query endpoint is available at localhost:8000):
curl http://localhost:8000/subgraphs/name/starknet/example \
-d '{
"query": "{outboundTransfers(first:3,orderBy:count,orderDirection:desc){id count}}"
}'The query above checks the top 3 accounts that made the most outbound ETH transfers. An example response looks like this:
{
"data": {
"outboundTransfers": [
{
"id": "0x0000000000000000000000000000000000000000000000000000000000000000",
"count": "9118"
},
{
"id": "0x07c57808b9cea7130c44aab2f8ca6147b04408943b48c6d8c3c83eb8cfdd8c0b",
"count": "2694"
},
{
"id": "0x06cc9b6f10480352867a271cbf80a701b95bd5b580052af44171ac1fff3e428b",
"count": "398"
}
]
}
}Note
The subgraph used to generate this example response was not synchronized.