Git Product home page Git Product logo

erc1155-subgraph's Introduction

Generic ERC1155 Substream Powered Subgraph

A simple subgraph for tracking a single ERC1155 smart contract.

Link to see what this is like live: Here

Quickstart

Make sure you have the latest versions of the following installed:

1. Update the ADDRESS and START_BLOCK variables in src/lib.rs

pub const ADDRESS: &str = "0x73DA73EF3a6982109c4d5BDb0dB9dd3E3783f313";
const START_BLOCK: u64 = 12129118;

2. Update the initialBlock params for all modules within substreams.yaml

  - name: map_transfers
    kind: map
    initialBlock: 12129118
    inputs:
      - source: sf.ethereum.type.v2.Block
    output:
      type: proto:schema.Transfers

3. Compile the Project with cargo build --release --target wasm32-unknown-unknown

We now need to recompile our WASM binary with the new changes we made to the rust files.

4. Pack the spkg with substreams pack -o substream.spkg

We need to bundle the protobuf definitions and the WASM binary into a single file. This is what we will deploy the subgraph.

5. Deploy the subgraph with graph deploy <YOUR_ENDPOINT>

This endpoint will change if you are deploying to the hosted service or decentralized network. But replace this with the command that is appropriate for your setup.

6. Enjoy your data!

Schema

type Collection @entity {
  id: ID! #address of the contract
  tokens: [Token!]! @derivedFrom(field: "collection") #tokens that belong to the contractA
}

enum TransferType {
  SINGLE,
  BATCH
}

type Transfer @entity {
  id: ID! # {tx-hash}-{log-index}
  from: Account! #account that sent the transfer
  to: Account! #account that received the transfer
  operator: Account! #account that sent the transfer (msg.sender)
  tokenIds: [Token!]! #token ids that were transferred
  transferType: TransferType! #single or batch transfer
}

type ApprovalForAll @entity {
  id: ID! #tx hash of the approval
  owner: Account!
  operator: Account!
  approved: Boolean!
}

type Token @entity {
  id: ID! #token id
  collection: Collection! #contract that the token belongs to
  owner: Account! #account that owns the token
  transfers: [Transfer!]! @derivedFrom(field: "tokenIds") #transfers that the token has been involved in
  uri: String #uri of the token
}

type Account @entity {
  id: ID! #Address of the account
  tokens: [Token!]! @derivedFrom(field: "owner") #tokens that the account owns
}

erc1155-subgraph's People

Contributors

mercuricchloride avatar

Watchers

 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.