在https://thegraph.com上 创建Subgraphs项目
安装 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
网友评论