@openzeppelin/subgraphs 简单使用

在https://thegraph.com上 创建Subgraphs项目

https://thegraph.com/studio/

安装 graph 命令行工具

npm install -g @graphprotocol/graph-cli
# 安装成功后
$ graph --version
0.30.4

开始本地创建项目

mkdir openzeppelin_subgraphs_demo && cd openzeppelin_subgraphs_demo
npm init -y

npm intall @openzeppelin/subgraphs

mkdir configs && cd configs
touch sample.json

sample.json 内容如下


{
    "output": "generated/sample.",
    "chain": "rinkeby",
    "datasources": [
        { "address": "your_contract_address", "startBlock": 10336543, "module": ["erc20"] }
    ]
}

编译 sample.json

npx graph-compiler \
  --config configs/sample.json \
  --include node_modules/@openzeppelin/subgraphs/src/datasources \
  --export-schema \
  --export-subgraph

编译代码和部署

subgraphs_project_name=
subgraphs_deploy_key=
# 认证部署密钥
graph auth --studio ${subgraphs_deploy_key}
# 生成代码并编译
graph codegen generated/sample.subgraph.yaml 
graph build generated/sample.subgraph.yaml
# 部署项目
graph deploy --studio ${subgraphs_project_name} generated/sample.subgraph.yaml

实际项目测试

https://api.studio.thegraph.com/query/29672/hhq/v0.0.4/graphql?query=query+MyQuery+%7B%0A++erc20Balances+%7B%0A++++account+%7B%0A++++++ERC20balances+%7B%0A++++++++value%0A++++++++id%0A++++++%7D%0A++++%7D%0A++%7D%0A%7D

你可能感兴趣的:(@openzeppelin/subgraphs 简单使用)