Help & Support

The Graph

The Graph is a decentralized protocol that enables efficient indexing and querying of blockchain data via GraphQL APIs. Lens Testnet is currently supported in The Graph Studio with the network tag: lens-testnet. This guide provides a walkthrough for developing and deploying a subgraph for a demo contract on the Lens Testnet.

1

Create a New Subgraph in Subgraph Studio.

Navigate to Subgraph Studio and connect your crypto wallet which will manage and deploy subgraph instance.

This will generate a Subgraph Slug, which will be used in subsequent steps.

2

Initialize Subgraph Indexing

Open your terminal and navigate to your desired directory.

Install The Graph CLI with your package manager of choice if not already installed:

npm install -g @graphprotocol/graph-cli@latest

Initialize the subgraph using the Graph CLI:

graph init --studio <SUBGRAPH_SLUG>

Replace the <SUBGRAPH_SLUG> with the slug obtained from Subgraph Studio.

Follow the prompts to configure your subgraph:

  • ethereum as the protocol

  • lens-testnet as the network

  • Contract address(es) to index

  • Contract ABI path, start block, and name (if not automatically fetched from block explorer)

  • It is recommended to select 'Index contract events as entities' as 'true', which will simplify the process of creating entity mappings

3

Update Subgraph Configuration

After initializing the subgraph, files will be generated that define the mapping from contract events to GraphQL entities, which can be customized based on your needs:

  • The schema (schema.graphql) contains generated entities which will be exposed from the GraphQL endpoint.

  • The subgraph manifest (subgraph.yaml) contains configuration for the data source(s) that will be indexed by the subgraph.

  • Mapping files are generated in the src directory, which define how schema entities are created, updated, or deleted as contract events are indexed.

See The Graph Development docs for more information on features and customization for these files.

4

Deploy the Subgraph

Follow the steps on the Subgraph Studio dashboard to authenticate and deploy the subgraph:

graph auth --studio <INSERT_DEPLOY_KEY>graph codegen && graph buildgraph deploy <INSERT_SUBGRAPH_SLUG>

5

Querying the Subgraph

Once deployed, navigate to Subgraph Studio to find the deployed GraphQL endpoint and test queries against the indexed data.

Use GraphQL queries to fetch indexed events and entity data from the contract within your integrating application. See The Graph Querying Docs for more information on available GraphQL APIs.