Coder Social home page Coder Social logo

marketplace-subgraph's Introduction

NFT Marketplace Indexer

Overview

I’m using TheGraph project as indexer for the Marketplace, and more specifically I’ve created a subgraph for my Marketplace.

The subgraph analyzes the smart contract and extract all events with their parameters. For this to happen, the contract must be deployed to pubic testnet and verified via Etherscan.

The subgraph is responsible for reading blocks, handling all emitted events and storing them. This data can be accessed later with GraphQL queries, as we are reading from database.

The events and their data are represented as entities and there is custom logic in the events handlers - we can define what to happen with this data before it is saved. One example is that I’ve created additional property to the List event entity, isActive, which represents is the current listing is active. On Buy or Cancel event, this property is set to false.

Here in the subgraph is important to keep all events historically and not delete them. The consumers of the subgraph can filter by isActive property to get only active listings, for example.

Creation of the subgraph

Requirements

  • Graph CLI: npm install -g @graphprotocol/graph-cli

Following official TheGraph documentation is pretty straightforward: Quick Start for subgraph init Creating a subgraph

Main points are:

  • Initializing the subgraph - One should provide several options, such as desired network, contract address, constract ABI, start block, etc.
  • Writing the subgraph logic - After the initializing step from exisiting contract, the subgraph provides basic handlers for all events. One can write custom logic here.
  • Deploying the subgraph to Subgraph Studio:
graph codegen
graph build

graph auth --studio <DEPLOY_KEY>
graph deploy --studio <SUBGRAPH_SLUG>
  • Publishing the subgraph from Subgraph Studio to become publicly available - you need some GRT tokens for this operation.

Working with the subgraph

Subgraph Studio provides query URLs, used to communicate with the subgraph externally.

My subgraph is published and can be used with the development query URL: https://api.studio.thegraph.com/query/48381/nftmarketplace/version/latest

marketplace-subgraph's People

Stargazers

Iliyan Iliev avatar

Watchers

Vladimir Trifonov avatar Iliyan Iliev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.