- Shows how to index the friend.tech trading activities on Coinbase’s L2 Base using Chainstack Subgraphs.
- Demonstrates how to capture key transaction data (e.g., trader, influencer, share price) from the protocol’s main contract and store it as queryable entities.
- Offers a practical example schema for analyzing fees, transaction details, and supply changes in a social DApp.
- Deploys on Chainstack for a robust and scalable subgraph solution powering analytics or trading automation.
Introduction
The decentralized social network friend.tech has gathered substantial attention within the Web3 space lately. It enables the trading of users’ tokenized stocks and is constructed on Coinbase’s L2 network Base. With a surge in queries concerning the accessibility of this application’s data, and considering the forthcoming release of the Base protocol in Chainstack Subgraphs hosting, we have prepared this tutorial. It aims to assist traders and analysts in launching their own subgraph, granting access to internal transactions, and if desired, facilitating the development of trading bots or financial analytics.Getting started
First, install the Graph CLI with either npm or yarn:ContractCreator: 0xdd9176ea3e7559d6b68b537ef555d3e89403f742 at txn [0xa7eba644182d78c4568364](https://basescan.org/tx/0xa7eba644182d78c4568364e00b0320a9fde9c1fe779cdbec6941fb7443d14c01)
:
Launching the subgraph
Let’s check what we have generated in thefriendtech-by-chainstack
directory. Specifically, we’re going to focus on the following files:
subgraph.yaml
schema.graphql
src/friendtech-shares-v-1.ts
subgraph.yaml
file, you can find the following code:
entities
that will be created in the database to store the smart contract events data and eventHandlers
that also can be used in the subgraph code and the paths to the other source code files.
If we open the file called schema.graphql
, we see the actual structure of the tables with data:
Trade
table is what we need. It contains the following entries:
trader
— the address of the tradersubject
— the address of the influencerisBuy
— the direction of saleshareAmount
— the number of shares in the tradeethAmount
— the price of the share in the dealsubjectEthAmount
— the fee that is received by the influencerprotocolEthAmount
field is the fee that is received by the protocolsupply
— the current total number of issued tokensblockNumber
,blockTimestamp
, andtransactionHash
are the block data that is not related to the protocol but useful for data analysis
src/friendtech-shares-v-1.ts
which contains the straightforward AssemblyScript code transferring the smart contract events data into the tables with the described structure.
handleTrade
function is what we are interested in. We see that each event emitting leads to the new entity created with the fields that exactly correspond to the table structure without any changes. But if you need any additional operations you can add them in the function.
Finally, to start using the subgraph, run the command:
