Replies: 5 comments 2 replies
-
提交 PR 时要注意: |
Beta Was this translation helpful? Give feedback.
-
Tips: |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
网络有问题可以参考这个,smartcontractkit/full-blockchain-solidity-course-js#2247 (comment) |
Beta Was this translation helpful? Give feedback.
-
graph deploy --studio nftmarketsepolia Error: Failed to upload file to IPFS: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
虽然这次的 task 很多,而且有一定难度,但是最后几个 task,特别是 task 7, 8, 9,可以说是给大家送福利来的,希望大家优先去做,千万不要放过了!
准备工作:
在做 task 9 之前,请大家先准备好一个钱包账户,一个电子邮件信箱(用来接收验证码),一个已经部署好的合约(需要合约地址)。
第一步:创建 graph 账户

进入下面的网页:
https://thegraph.com/studio/ ,点击 “Connect Wallet” (连接钱包)
连接钱包之后,需要签名

签名之后,需要填写电子邮件地址,如何点击“Send verification code” (发送验证码)

去电子邮件信息,找到验证码,并填入,然后点击“Verify” (验证)

第二步:创建在线 Subgraph

点击网页右边的“Create a Subgraph” (创建一个 Subgraph)
输入 Subgraph 的名字,然后点击 “Create Subgraph” (创建 Subgraph)

生成之后,你会发现 “Save” (保存)按钮是灰的,必须在 “Subgraph Description” (Subgraph 描述)部分填写内容, “Save” (保存)按钮才会被 enable。

点击 "Save" 保存了 Subgraph 之后,就可以根据右边的 commands 在自己电脑上创建 Subgraph 了。

第三步:创建本地 Subgraph

首先是安装 graph,虽然网页上有 npm 和 yarn 2 个命令,但我建议用 npm 命令去安装(我本人在用 yarn 安装的时候,遇到一点问题,npm 则 OK)。
然后 init 本地的 Subgraph:

当问到 Protocol 的时候,选择 ethereum:

Subgraph slug,则填入上一步的 Subgraph slug:


Directory to create the subgraph in,则填入你希望生成的本地目录的文件夹名:

选择网络时,用上下箭头选中已部署合约的网络:

Contract address,则填入已部署的合约地址:

由于网络的问题,在 Fetching Start Block 和 Fetching Contract Name 的时候,可能经常会报错,但是不要紧,每次直接按回车,让他 retry 就好了:

拿到 Start Block 和 Contract Name 之后,Index contract events as entities 不用改,直接回车就可以,之后等待一段时间,会问 Add another contract?,点击 “n”,Subgraph 就创建完成了。

第四步:Deploy Subgraph

本地生成的 Subgraph 文件夹,里面最主要的是三个文件:src/ 里面的 .ts 文件,schema.graphql 文件和 subgraph.yaml 文件,有兴趣的可以打开看一下:
Authenticate within the CLI:

Build Subgraph:

Deploy Subgraph:

在 Deploy 的时候,会问版本号,填你想用的版本号就可以:

第五步:Play around

Deploy 成功之后,刷新页面,会发现在线的 Subgraph 页面有一些变化:
这时点击 Logs,会发现多了很多东西:

点击 Playground,通过修改左边的代码,然后点击中间的按钮,右边就会显示出我们想要知道的信息:

还在等待什么,快点截图并提交 PR 吧~
Beta Was this translation helpful? Give feedback.
All reactions