Custom Graphs

This guide will introduce the concept of Custom Graphs and how to create and manage them.


This guide provides an introduction to the concept of Custom Graphs. More information will be provided in due course.

As outlined in the Graph concept page, there are two classes of Graph instances:

  • The Global Graph: This is the default, familiar graph, encompassing all connections to date.

  • Custom Graphs: These are app-specific graphs, accessible openly or governed by Graph Rules.

Create a Custom Graph

To create a Graph, you need to:

  1. Create a Graph Metadata object

  2. Upload the Graph Metadata object onto a public URI.

  3. Deploy the Lens Graph smart contract.

See the Lens Metadata Standards guide for more information on creating and hosting Metadata objects.

1

Create Graph Metadata

Use the @lens-protocol/metadata package to construct a valid GraphMetadata object:

Example
import { graph } from "@lens-protocol/metadata";
const metadata = graph({  name: "XYZ",  title: "Not Just Another Graph… or is it?",  description: "My custom graph description",});

2

Upload Graph Metadata

Then, upload the Graph Metadata object to a public URI.

import { uploadJson } from "./my-upload-lib";
const metadataURI = await uploadJson(metadata); // e.g., lens://4f91ca…

3

Deploy Graph Contract

You can use the createGraph mutation to deploy the Lens Graph smart contract.

You MUST be authenticated as Builder to make this request.

mutation {  createGraph(    request: {      metadataUri: "lens://4f91cab87ab5e4f5066f878b72…"
      # optional list of admins      # admins: [EvmAddress!]
      # other fields such as graph rules configuration      # will be documented in due course    }  ) {    ... on CreateGraphResponse {      hash    }
    ... on SelfFundedTransactionRequest {      ...SelfFundedTransactionRequest    }
    ... on TransactionWillFail {      reason    }  }}

Finally, handle the result as explained in the Transaction Lifecycle guide.

Fetch a Graph

Use the graph query to fetch a single Graph by address or by transaction hash.

query {  graph(    request: {      graph: "0xdeadbeef…"
      # OR
      # txHash: TxHash!    }  ) {    address    metadata {      name      title      description    }
    # other fields such as graph rules    # will be documented in due course  }}