Creating Subgraphs on Linea: A Comprehensive Guide
Because the web continues to evolve, the decentralized internet, generally known as web3, is gaining traction. Nonetheless, accessing and studying blockchain knowledge stays a problem. Based on Linea, The Graph addresses this situation by offering a decentralized protocol for indexing and querying blockchain knowledge.
Understanding The Graph
The Graph is an indexing protocol designed to make blockchain knowledge simply accessible by means of open APIs generally known as subgraphs. This protocol leverages the participation of assorted community contributors who earn GRT, The Graph’s native utility token, for his or her efforts in organizing knowledge effectively.
Key individuals in The Graph community embrace:
- Subgraph Builders: Create and publish subgraphs which might be accessible to everybody.
- Indexers: Function nodes to index subgraphs and serve knowledge to customers.
- Curators: Establish and curate invaluable subgraphs for Indexers.
- Delegators: Safe the community by delegating GRT to Indexers.
The decentralized nature of The Graph ensures open entry to knowledge, fostering innovation and collaboration inside the web3 ecosystem.
Constructing a Subgraph on Linea
Linea’s ecosystem makes use of The Graph to entry blockchain knowledge, enhancing transparency and lowering censorship dangers. Here’s a step-by-step information to constructing a subgraph on Linea:
Step 0: Create a New Subgraph
Start by visiting Subgraph Studio and connecting your pockets. As soon as related, choose “create a subgraph,” select Linea because the community, and click on proceed.
Step 1: Set up the Graph CLI
Set up the Graph CLI on your native machine utilizing both npm or yarn:
$ npm set up -g @graphprotocol/graph-cli
$ yarn world add @graphprotocol/graph-cli
Step 2: Initialize Your Subgraph
Initialize your subgraph from an current contract:
graph init --studio <SUBGRAPH_SLUG>
Present the required data comparable to protocol (choose Ethereum), subgraph slug, native listing, community (Linea or Linea Sepolia), contract deal with, ABI, begin block, contract identify, and whether or not to index contract occasions as entities.
Step 3: Write Your Subgraph
Modify the scaffold subgraph by working with three most important recordsdata:
- Manifest (subgraph.yaml): Defines the info sources your subgraph will index.
- Schema (schema.graphql): Defines the info to retrieve from the subgraph.
- AssemblyScript Mappings (mapping.ts): Interprets knowledge out of your knowledge sources to the entities outlined within the schema.
For detailed directions, confer with The Graph’s documentation.
Step 4: Deploy to Subgraph Studio
Generate AssemblyScript varieties and compile your subgraph:
$ graph codegen
$ graph construct
Authenticate and deploy your subgraph to a Graph Node:
$ graph auth --studio <DEPLOY_KEY>
$ graph deploy --studio <SUBGRAPH_SLUG>
Present a model label, ideally utilizing semver.
Step 5: Check Your Subgraph
Check your subgraph by making pattern queries within the playground part and checking the logs for any errors. Use the GraphiQL Playground to question your subgraph’s well being if wanted.
Step 6: Publish to The Graph’s Decentralized Community
After deploying and testing your subgraph, publish it to the decentralized community through Subgraph Studio. It is strongly recommended to publish subgraphs to Arbitrum One for decrease fuel prices. Curate your subgraph utilizing GRT to make sure it’s listed and out there for querying promptly.
Step 7: Question Your Subgraph
Question your subgraph by sending GraphQL queries to your subgraph’s Question URL. For extra data on querying knowledge, confer with The Graph’s querying documentation.
Picture supply: Shutterstock
. . .
Tags