The Graph

Intro

The Graphopen in new window is a protocol for building decentralized applications (dApps) quickly on Ethereum and IPFS using GraphQL.

Graph Node is an open source Rust implementation that event sources the Ethereum blockchain to deterministically update a data store that can be queried via the GraphQL endpoint.

For detailed instructions and more context, check out the Getting Started Guide.

Since Unique Network provides the Ethereum API to work with networks, this approach can also be used.

Launch a local graph-node

To start, please clone the https://github.com/graphprotocol/graph-nodeopen in new window repository using Git.

git clone https://github.com/graphprotocol/graph-node.git

cd graph-node/docker

Then, open the Dockerfile and modify the following variable:

environment.ethereum: 'mainnet:https://rpc-opal.unique.network'

When the new variable is saved, please start the container by this command:

docker compose up

Generate subgraph locally using the ABI file

Let's install the Graph CLI. To do this, please run the command below.

npm install -g @graphprotocol/graph-cli
yarn global add @graphprotocol/graph-cli

After this, run this command to initialize the Graph, and also specify the smart contract address and the ABI file (for more details, please check the Graph docsopen in new window).

graph init --from-contract contractAddress --abi ./abi.json <prefix/graphName> 

After executing this command, the subgraph is generated using the specified contract and the ABI file. Here is the exampleopen in new window.

Now, we need to open the subgraph.yaml file and set the following: dataSources.source.startBlock. This is the start block for smart contract scanning.

When it is done, please execute these commands to deploy your subgraph to the local graph-node.

npm run create-local
npm run deploy-local 
yarn run create-local
yarn run deploy-local 

Examples

Here are the examples how the main items look:

Smart contract address - 0xED83A4E878E496ec1C84BdBbbC50c6657181F906

The ABI file - ./abi.json

Subgraph for indexing all blocks data - https://thegraph.com/hosted-service/subgraph/kybernetwork/ethereum-blocksopen in new window