安装yarn,node环境
设置yarn仓库
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
设置node仓库
curl --silent --location https://rpm.nodesource.com/setup_16.x | sudo bash -
开始安装
sudo yum install yarn
安装成功
yarn --version
配置国内镜像
yarn config set registry https://registry.npm.taobao.org
安装graph-cli
Install with yarn:
yarn global add @graphprotocol/graph-cli
Install with npm:
npm install -g @graphprotocol/graph-cli
访问thegraph服务,进入graph studio,创建subgraph,生成SUBGRAPH_SLUG
初始化subgraph
graph init --studio <SUBGRAPH_SLUG>
修改配置,完成编码
进行auth认证
graph auth --studio <DEPLOY KEY>
发布subgraph
graph deploy --studio <SUBGRAPH_SLUG>
官方quick start
This guide uses Truffle and Ganache for local development. It covers the following steps:
1. Set up Ganache CLI
2. Start a local Graph Node
3. Initialize a new subgraph
4. Deploy an example smart contract to Ganache
5. Deploy the subgraph to the local Graph Node
6. Use the subgraph in a dApp built with React
根据上述步骤进行实操
我们以接入ethereum为测试目标,第一步忽略
Graph Node依赖postgres 、ipfs服务,我们以docker部署为例
运行postgres 镜像
docker run --name=postgres -p 15432:5432 -e POSTGRES_PASSWORD=postgres -e TZ=PRC -d postgres
运行ipfs镜像
docker run -d --name ipfs \
-v /home/work/app/ipfs-node/staging:/export \
-v /home/work/app/ipfs-node/data:/data/ipfs \
-p 5001:5001 \
ipfs/go-ipfs:latest
docker run -it -d --name graph-node-ropsten \
-p 8000:8000 -p 8001:8001 -p 8020:8020 -p 8030:8030 \
-e GRAPH_ALLOW_NON_DETERMINISTIC_FULLTEXT_SEARCH="true" \
-e postgres_host=172.18.0.1 \
-e postgres_port=5432 \
-e postgres_user=postgres \
-e postgres_pass=postgres \
-e postgres_db=graph-node-ropsten \
-e ipfs=172.18.0.1:5001 \
graphprotocol/graph-node:latest
创建一个新的subgraph
我们拉取uniswap-v2的subgraph代码,来进行实验
https://github.com/Uniswap/uniswap-v2-subgraph
修改subgraph.yml配置文件
主要修改address地址
忽略
发布subgraph到我们的自建节点
安装代码依赖
$ yarn && yarn codegen
创建本地graph
$ yarn create-local
发布到本地节点
$ yarn deploy-local
使用graphql进行查询