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.
The Graph is a decentralized protocol for querying blockchains like the Palm network. It enables developers to build custom APIs called 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.
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
Querying ERC-721 tokens
Querying ERC-1155 tokens
Querying the Palm Sushi exchange
Querying the https://nftx.io/ contracts deployed to Palm
Querying Palm mainnet’s blocks
A variety of tools are available to consume Subgraphs from applications based on:
- React Native
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:
- Deploy smart contracts that will be indexed (and their addresses)
- Create subgraph.yaml
- Subgraph's manifest i.e. a config file, holds information about the smart contracts indexed by a Subgraph
- Create schema.graphql
- Create an AssemblyScript mapping
- To get an idea of the usual structure of a subgraph repository you can use graphprotocol’s example subgraph for a start.
- Learn More on NFT-specific repositories dedicated to:
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.
- Deploy your smart contracts & obtain their addresses for the subgraph manifest
- Create a config file for Palm testnet & mainnet with required info network: palm-mainnet or palm-testnet
- Ask the Palm Network team to set up & deploy the subgraph by filling out the subgraph registration form
- Grant access to the Palm network team to the relevant subgraph code repository
- The palm network team will review the subgraph & deploy it into testnet environments
- You will be then able to validate that the test subgraph is working correctly
- The Palm network team will deploy the subgraph to mainnet environments
- You will now validate that the subgraph on Palm mainnet is working correctly
- The Palm network team will document your subgraph’s endpoint on the docs.palm.io page