ziegfried / peepeth-subgraph

Subgraph for Peepeth, the blockchain-powered social network

Home Page:https://thegraph.com/explorer/subgraph/ziegfried/peepeth

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Peepeth Subgraph

This subgraph sources events from Peepeth, the the blockchain-powered social network.

Example query

{
  # 5 lastest peeps
  peeps(first: 5, orderBy: number, orderDirection: desc) {
    number
    content
    timestamp
    # Get some account info from the author of the peep
    account {
      name
      realName
    }
    # Get message this peep is sharing
    share {
      content
      account {
        name
        realName
      }
    }
  }
  # Get total number of accounts and peeps on Peepeth
  peepeth(id: "global") {
    numberOfPeeps
    numberOfAccounts
  }
}

Demo App

Check out the demo app, which uses the subgraph to show some Peepeth accounts, their followers and peeps.

See it live here: https://peepeth-subgraph.sigi.dev/

Find the sources and some more info in the /demo-app folder

How Peepeth works

For a high-level overview see https://peepeth.com/how.

Basically peepeth uses a stateless smart contract where (arguments to) method calls point to JSON blobs on IPFS. The transaction is submitted and signed by the user.

  Ethereum Tx                      IPFS File
+---------------------+          +----------------------------+
| createAccount(      |          |{                           |
|   name: "Hugo",     |          |  "realName": "Hugo Foobar",|
|   ipfsHash: "Qm..." +--------->+  "location": "Somewhere",  |
| )                   |          |  ...                       |
+---------------------+          |}                           |
                                 +----------------------------+

Most actions can be performed this way, see ABI for details. Some actions do not have corresponding JSON data in IPFS (follow/unfollow for example).

Batched actions

To reduce cost, Peepeth allows the user to batch a number of actions and submit them at once. In this case the ethereum function call points to a JSON blob in IPFS that contains a list of actions (which can in turn point to JSON blobs in IPFS).

   Ethereum Tx             IPFS File 1
+-------------------+    +--------------------------------+       IPFS File 2
|saveBatch(         |    |{                               |     +---------------------------+
|  ipfsHash: "Qm..X"+--->+  "batchSaveJSON": [            |     |{                          |
|)                  |    |    { "follow": { "followee": "0|     |  "type": "peep",          |
+-------------------+    |    { "peep": { "ipfs": "Qm...J"+---->+  "content": "hello world",|
                         |  ]                             |     |  ...                      |
                         |}                               |     |}                          |
                         +--------------------------------+     +---------------------------+

Signed actions

See

Basically allows users to perform actions for free. User sign action(s) and a central service submits signed batches for all users to the blockchain.

Similar to regular batch, signed actions are stored in JSON documents on IPFS, pointing to other IPFS hashes. The user creates a signature of the IPFS hash of the actual action document using ethereum-style elliptic curve cryptography (eth_sign).

Subgraph Schema

Account

An account is a peepeth user, bound to an ethereum wallet

Field Argument Type Description
id ID!

The account ID is the ethereum wallet address of the user

number Int!

Accounts are numbered in the order they were created

name String!

The username

ipfsHash String!

IPFS of the account info

info String

Tagline of the user

website String

The users website

location String

Geographical location of the user (not in a particular format)

realName String

The users real name

avatarUrl String

User avatar image

backgroundUrl String

User background image

messageToWorld String

Shout it out there

followers [Follower!]!

List of followers of this user, for example

followers {
  account {
    name
  }
}
following [Follower!]!

List of peepeth this account is following, for example


following {
  followee {
    name
  }
}

peeps [Peep!]!

List of peeps by this account

createdInBlock Int!

Number of the ethereum block this account was created in

createdInTx Bytes!

Hash of the ethereum transation this account was created in

createdTimestamp Int!

Timestamp of the transaction this account was created in

updatedInBlock Int

Number of the ethereum block this account was last updated in

updatedInTx Bytes

Hash of the ethereum transaction this account was last updated in

updatedTimestamp Int

Timestamp of the transaction this account was last updated in

Follower

A follower connects two accounts in a directed fashion. It persists the information of an account following an followee-account.

Field Argument Type Description
id ID!

A combination of the two account IDs

followee Account!

The account being followed

account Account!

The account that is following

timestamp Int!

Timestamp when the follow action occurred

createdInBlock Int!

Number of the ethereum block this follow action ocurred

createdInTx Bytes!

Hash of the ethereum transaction this follow action ocurred

createdTimestamp Int!

Timestamp of the transaction this follow action ocurred

Peep

A post made on the Peepeth social network

Field Argument Type Description
id ID!

The Peep ID is the IPFS hash from where the data was retrieved

number Int!

Peeps are numbered in the order they are processed

type PeepType!

Type of the peep, allows to distinguish between regular peeps, peeps that share another peep, and replies to other peeps

content String!

The content (message) of the peep

pic String

A picture associated to the peep

account Account

The author of the peep

timestamp Int!

Timestamp when the peep was created

share Peep

The peep shared by this peep. This is null in case this is not of type=SHARE

replyTo Peep

The peep which this peep is the reply to. Thi is null in case this is not of type=REPLY

replies [Peep!]!

List of all reply-peeps to this peep

createdInBlock Int!

Number of the ethereum block this peep was created in

createdInTx Bytes!

Hash of the ethereum transation this peep was created in

createdTimestamp Int!

Timestamp of the transaction this peep was created in

Peepeth

Global stats about Peepeth, use Peepeth(id: "global")

Field Argument Type Description
id ID!

There is only one entry with id: "global"

numberOfAccounts Int!

Total number of Peepeth accounts

numberOfPeeps Int!

Total number of peeps

numberOfPeepsNotFound Int!

Number of peeps where the data in IPFS could not be located

Enums

PeepType

Type of a peep to distinguish replies, shared peeps and regular peeps

Value Description
PEEP

A regular peep

SHARE

A peep sharing another peep

REPLY

A peep as a reply to another peep

Known issues

  • Not not all peeps, accounts, followers are recorded correctly by the subgraph in cases when IPFS reads time out: graph-node issue
  • Signatures from signed actions are currently not verified, since there is no easy way to perform this in assembly script: graph-ts issue
  • changeName actions are currently ignored due to some transactions in mainnet causing the subgraph to crash: graph-node issue

About

Subgraph for Peepeth, the blockchain-powered social network

https://thegraph.com/explorer/subgraph/ziegfried/peepeth

License:MIT License


Languages

Language:TypeScript 97.4%Language:HTML 2.6%