website logo
Join the CommunityContact Us
Navigate through spaces
Main
⌘K
Palm Network Developer Portal
The Palm Network
Submit an Article
Network Details
Validators
Get Started
Get PALM Tokens
Gas Fees
Connect to Palm network
Run a Transaction Node
How To Tutorials
MetaMask Wallet Setup
Deploy NFT Contracts
Verifying NFT Contracts
Mint NFTs with Hardhat
Bridge
Use the Bridge
Integrate With the Bridge
Bridge Component Addresses
Deprecated
Use Supported Tools
Block Explorer
Moralis
The Graph
Covalent API
Docs powered by archbee 
28min

The Graph

Overview

DApps such as NFT markets constantly need to retrieve on-chain data pertaining to token transfers or asset minting. One way to obtain that information is to pull it directly from the blockchain. This is often a complicated process which requires building an ad-hoc server instance. Instead, you can use a dedicated protocol like The Graph, which focuses on smart contract data indexing and storage.



1. How does The Graph work?

The Graph is a decentralized protocol for querying blockchains like the Palm network. It enables developers to build custom APIs called Subgraphs.

What are Subgraphs?

Subgraphs listen to specific smart contract events and act as data stores so that the information can easily be retrieved by a DApp. Since Subgraphs are built around developers’ specific data requirements (e.g. IEP-721 subgraph schema ) they only need to be called once, unlike general-purpose APIs which sometimes require hundreds of calls to gather relevant information.

Learn more about The Graph network and Protocol



2. Querying the Palm network’s Subgraphs

The Graph provides a GraphQL API. If you are familiar with GraphQL, you should be comfortable querying The Graph. Make sure to learn the specifics of The Graph’s API.

Beginner GraphQL Resources

  • GraphQL
  • How to GraphQL Tutorials

Resources to Experiment with Subgraphs and GraphQL

(optional)

  • A training toolkit to deploy a contract and immediately mint NFTs on the Palm Network
  • GraphiQL tests queries against deployed Subgraphs and the NFTs you’ve minted


3. Available Subgraphs on the Palm network

The Palm network provides a Graph node and a number of deployed Subgraphs tailored for NFT contexts. Developers can access those Subgraphs through RESTful or WebSocket APIs calls:

Name & repo

Use

Mainnet Endpoint/GraphiQL

Testnet Endpoint/GraphiQL

wighawag/eip721-subgraph

Querying ERC-721 tokens

https://graph.palm.io/subgraphs/name/wighawag/eip721-subgraph

https://graph.palm-uat.xyz/subgraphs/name/wighawag/eip721-subgraph

amxx/eip1155-subgraph

Querying ERC-1155 tokens

https://graph.palm.io/subgraphs/name/amxx/eip1155-subgraph

https://graph.palm-uat.xyz/subgraphs/name/amxx/eip1155-subgraph

sushi/exchange-palm

Querying the Palm Sushi exchange

https://graph.palm.io/subgraphs/name/sushi/exchange-palm



nftx-project/nftx-v2-subgraph

Querying the https://nftx.io/ contracts deployed to Palm

https://graph.palm.io/subgraphs/name/nftx-project/nftx-v2-palm



ethereum-blocks

Querying Palm mainnet’s blocks

https://graph.palm.io/subgraphs/name/blocklytics/palm-mainnet-blocks





4. Using the Graph from a DApp

A variety of tools are available to consume Subgraphs from applications based on:

  • React
  • Vue
  • iOS
  • Android
  • React Native

You can use a fully-featured package such as Apollo or a leaner implementation like GraphQL-Request.





💡 Learn More

  • Learn more about querying The Graph from a DApp


Sample code for a React DApp

Index.tsx
App.tsx
|



5. Build a New Subgraph

Creating a subgraph allows to determine the data that the graph will index from the blockchain. It will then decide how this data will be stored.

To do that:

  1. Deploy smart contracts that will be indexed (and their addresses)
  2. Create subgraph.yaml
    • Subgraph's manifest i.e. a config file, holds information about the smart contracts indexed by a Subgraph
  3. Create schema.graphql
    • GraphQL schema defines a Subgraph’s structure
      • 💡 Learn More
  4. Create an AssemblyScript mapping
    • TypeScript code used to translate contracts’ event data into specific objects in the schema
    • The Graph offers a code generator for that
      • 💡 Learn More
  5. To get an idea of the usual structure of a subgraph repository you can use graphprotocol’s example subgraph for a start.
  6. Learn More on NFT-specific repositories dedicated to:


Example Files

There is no particular order to follow when modifying the files required to create a Subgraph.

Once done editing the 3 files below to define your subgraph, you can then optionally test your mapping in a sandbox environment and start the process of adding your subgraph to the Palm network.



Manifest/config File
|


License[1]



Designed Around EIP-721 Compliant Contracts

Schema.graphql
|


License[1:1]



Mappings File

JS
|


License[1:2]



6. How to add your own subgraph to the Palm network

  1. Deploy your smart contracts & obtain their addresses for the subgraph manifest
  2. Create a config file for Palm testnet & mainnet with required info network: palm-mainnet or palm-testnet
  3. Ask the Palm Network team to set up & deploy the subgraph by filling out the subgraph registration form
  4. Grant access to the Palm network team to the relevant subgraph code repository
  5. The palm network team will review the subgraph & deploy it into testnet environments
  6. You will be then able to validate that the test subgraph is working correctly
  7. The Palm network team will deploy the subgraph to mainnet environments
  8. You will now validate that the subgraph on Palm mainnet is working correctly
  9. The Palm network team will document your subgraph’s endpoint on the docs.palm.io page


Copyright (C) <2019-2020> Ronan Sandford - GNU - https://github.com/wighawag/eip721-subgraph ↩︎ ↩︎ ↩



👉 Mint NFTs Tutorial

🔥 Example Queries



Updated 01 Dec 2022
Did this page help you?
Yes
No
UP NEXT
Mint NFTs Tutorial
Docs powered by archbee 
TABLE OF CONTENTS
Overview
1. How does The Graph work?
What are Subgraphs?
2. Querying the Palm network’s Subgraphs
Beginner GraphQL Resources
Resources to Experiment with Subgraphs and GraphQL
3. Available Subgraphs on the Palm network
4. Using the Graph from a DApp
💡 Learn More
Sample code for a React DApp
5. Build a New Subgraph
Example Files
Designed Around EIP-721 Compliant Contracts
Mappings File
6. How to add your own subgraph to the Palm network
👉 Mint NFTs Tutorial
🔥 Example Queries