Developer Hub
Relation ProtocolRelation ONE APIRelation Graph API
English
English
  • Overview
  • QUICK START
    • Deploy a Semantic SBT contract leveraging Relation Protocol
    • Deploying query services using Graph Indexer
  • KEY CONCEPTS
    • RDF
    • Semantic SBTs
    • Social Graph
  • Architecture
  • Schema Standard
    • Overview
    • How schemas limit smart contracts
    • Store schema
    • List of schemas
  • Contract Open Standard
    • Overview
    • Identity
      • Name Service
    • Relationship
      • Follow
      • Dao
    • Publication
      • Content
      • Privacy Content
  • Open Standard API
    • Introduction
    • EIP-6239
    • Business Interface
      • Identity
      • Relationship
      • Publication
  • Graph Indexer
    • Definition and usage
    • Listen to events
    • To parse RDF data
    • To build a social graph
  • Integrations
    • Quick start
    • Construct a social graph with Relation Protocol
    • List of resources
    • NameService contract guide
    • Follow contract guide
    • Dao contract guide
    • Content contract guide
    • PrivacyContent contract guide
  • Relation Name Service
    • Name Service Api
  • Use Case
  • APPENDIX
    • Deploy a contract using Hardhat
    • SemanticSBT Deployment tool
Powered by GitBook
On this page
  • Use The Graph index
  • Use The ethers.js
  1. Graph Indexer

Listen to events

Last updated 1 year ago

The events defined in the Relation Protocol are completely inherited from , we need to listen to all events that comply with the EIP6239 specifications:

/**
 * @title Semantic Soulbound Token
 * Note: the EIP-165 identifier for this interface is 0xfbafb698
 */
interface ISemanticSBT {
    /**
     * @dev This emits when minting a Semantic Soulbound Token.
     * @param tokenId The identifier for the Semantic Soulbound Token.
     * @param rdfStatements The RDF statements for the Semantic Soulbound Token. An RDF statement is the statement made by an RDF triple.
     */
    event CreateRDF (
        uint256 indexed tokenId,
        string rdfStatements
    );
    /**
     * @dev This emits when updating the RDF data of Semantic Soulbound Token. RDF data is a collection of RDF statements that are used to represent information about resources.
     * @param tokenId The identifier for the Semantic Soulbound Token.
     * @param rdfStatements The RDF statements for the semantic soulbound token. An RDF statement is the statement made by an RDF triple.
     */
    event UpdateRDF (
        uint256 indexed tokenId,
        string rdfStatements
    );
    /**
     * @dev This emits when burning or revoking Semantic Soulbound Token.
     * @param tokenId The identifier for the Semantic Soulbound Token.
     * @param rdfStatements The RDF statements for the Semantic Soulbound Token. An RDF statement is the statement made by an RDF triple.
     */
    event RemoveRDF (
        uint256 indexed tokenId,
        string rdfStatements
    );
    /**
     * @dev Returns the RDF statements of the Semantic Soulbound Token. An RDF statement is the statement made by an RDF triple.
     * @param tokenId The identifier for the Semantic Soulbound Token.
     */
    function rdfOf(uint256 tokenId) external view returns (string memory);
}
  • CreateRDF: Triggered when a SBT containing RDF semantics is created.

  • UpdateRDF: Triggered when a SBT containing RDF semantics is updated.

  • RemoveRDF: Triggered when a SBT containing RDF semantics is removed.

By listening to these events on the blockchain, you will receive RDF data containing semantics (code 7-1), which contains user behavior data.

code 7-1
:Soul_0x0109c8ee3151bde7b6b5d9f37e9d2c4bc16930fe p:following :Soul_0x6247123ec0fe0d25feb811e3c4d4a760c1f2e63e .

Use The Graph index

Below is the behavioral data from the Polygon network through our listening. The address is:

  • Query via the playground provided by The Graph:

  • Query via the GraphQL API provided by The Graph:

eg. To query the latest two token records:

curl --location --request POST 'https://api.thegraph.com/subgraphs/name/relationlabs/semantic-sbt' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"{\n  turtles(first: 2) {\n    id\n    owner\n    tokenId\n    turtle\n  }\n}"}'

The result

{"data":{"turtles":[{"id":"33456276423","owner":"0x16ff7821a8d293cd2ea07b650fc69ea9206d0615","tokenId":"1","turtle":":Activity1 p:name \"Activity_2049_1\" . :Activity1 p:level 1 . "},{"id":"33456276425","owner":"0x16ff7821a8d293cd2ea07b650fc69ea9206d0615","tokenId":"2","turtle":":Activity2 p:name \"Activity_2049_2\" . :Activity2 p:level 2 . "}]}}

Use The ethers.js

For example:

const ethers = require('ethers')
const rpc = 'https://polygon-mumbai.blockpi.network/v1/rpc/public'
let abi = ['event CreateRDF(uint256 indexed tokenId, string rdfStatements)']
const provider = new ethers.JsonRpcProvider(rpc)
const iface = new ethers.Interface(abi)
const filter = {}

// listen
provider.on(filter, (e) => {
  try {
    let event = iface.parseLog(e)
    console.log(event)
    // parse ...
  } catch (error) {}
})

With , we can index users' behavioral data on the blockchain easily. You can refer to .

is a JavaScript library for interacting with the Ethereum Blockchain and its ecosystem.

EIP6239
The Graph
The Graph documentation
https://thegraph.com/hosted-service/subgraph/relationlabs/semantic-sbt
ethers.js
Figure 7-2 Query via the playground