Graph开发和部署学习教程 (一)

以开发一个friend.tech项目的子图为例子展示 subgraph 的开发和部署过程。

去中心化社交网络 friend.tech 建立在 Coinbase 的 L2 网络基础上,实现社交影响力的货币化;本节以开发一个 friend.tech 项目的子图为例子展示 subgraph 的开发和部署过程。

friend.tech智能合约
本节的关注点在graph的开发,了解 friend.tech 的项目的详细分析看这里。

合约信息内有合约代码:

在这里插入图片描述
https://basescan.org/address/0xCF205808Ed36593aa40a44F10c7f7C2F67d4A4d4#code

friend.tech 项目的智能合约相对简单,主要有两个重要的函数 buyShares 和 sellShares; 用户的交易行为触发了 Trade 事件, Trade 事件函数的签名记录了交易相关的信息, 即需要索引的数据。

安装依赖:

yarn global add @graphprotocol/graph-cli
yarn global add @graphprotocol/graph-ts

在这里插入图片描述

✔ Protocol · ethereum                                                                                                                                    
✔ Product for which to initialize · subgraph-studio                                                                                                      
✔ Subgraph slug · FriendtechGraph                                                                                                                        
✔ Directory to create the subgraph in · FriendtechGraph
✔ Ethereum network · base
✔ Contract address · 0xCF205808Ed36593aa40a44F10c7f7C2F67d4A4d4
✔ Fetching ABI from Etherscan
✖ Failed to fetch Start Block: Failed to fetch contract creation transaction 
✔ Do you want to retry? (Y/n) · false
✔ Start Block · 2430439
✔ Contract Name · FriendtechSharesV1
✔ Index contract events as entities (Y/n) · true
  Generate subgraph
  Write subgraph to directory
✔ Create subgraph scaffold
✔ Initialize networks config
✔ Initialize subgraph repository
✔ Install dependencies with yarn
✔ Generate ABI and schema types with yarn codegen
Add another contract? (y/n): 
Subgraph FriendtechGraph created in FriendtechGraph

第7步如果因为网络原因不能获取合约ABI文件,也可以使用本地文件。

猜你喜欢

转载自blog.csdn.net/Tesla_Zhou/article/details/135196059