官方文档: https://thegraph.com/docs/zh/quick-start/
简介
The Graph 可以干什么,记录区块链上数据,以前都要有个后端服务和数据库,维护和开发成本大,使用The Graph,方便快捷节省成本
部署
核心: the graph node,将合约的事件索引,存入数据库
自己部署 TheGraphNode rust 实现 ,依赖IPFS,postgrest, geth 归档节点
火币部署文档
使用
合约部署
以一个ERC20代币的合约为例:
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MockToken is ERC20 {
string internal NAME = "Mock Token";
string internal SYMBOL = "MT";
uint256 internal constant TOTAL_SUPPLY = 1e28;
uint8 public decimal;
constructor(uint8 _decimal) public ERC20(NAME, S