You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/pages/en/new-chain-integration.mdx
+1-30Lines changed: 1 addition & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,33 +76,4 @@ Graph Node should be syncing the deployed subgraph if there are no errors. Give
76
76
77
77
## Substreams-powered Subgraphs
78
78
79
-
For StreamingFast-led Firehose/Substreams integrations, basic support for foundational Substreams modules (e.g. decoded transactions, logs and smart-contract events) and Substreams-powered subgraph codegen tools are included (check out [Injective](https://substreams.streamingfast.io/documentation/intro-getting-started/intro-injective/injective-first-sps) for an example).
80
-
81
-
There are two options to consume Substreams data through a subgraph:
82
-
83
-
-**Using Substreams triggers:** Consume from any Substreams module by importing the Protobuf model through a subgraph handler and move all your logic into a subgraph. This method creates the subgraph entities directly in the subgraph.
84
-
-**Using EntityChanges:** By writing more of the logic into Substreams, you can consume the module's output directly into `graph-node`. In `graph-node`, you can use the Substreams data to create your subgraph entities.
85
-
86
-
It is really a matter of where you put your logic, in the subgraph or the Substreams. Keep in mind that having more of your logic in Substreams benefits from a parallelized model, whereas triggers will be linearly consumed in `graph-node`. Consider the following example implementing a subgraph handler:
let transactions =assembly.eth.transaction.v1.Transactions.decode(bytes.buffer).trasanctions// 1.
91
-
if (transactions.length==0) {
92
-
log.info('No transactions found', [])
93
-
return
94
-
}
95
-
96
-
for (let i =0; i<transactions.length; i++) {
97
-
// 2.
98
-
let transaction =transactions[i]
99
-
100
-
let entity =newTransaction(transaction.hash) // 3.
101
-
entity.from=transaction.from
102
-
entity.to=transaction.to
103
-
entity.save()
104
-
}
105
-
}
106
-
```
107
-
108
-
The `handleTransactions` function is a subgraph handler that receives the raw Substreams bytes as parameter and decodes them into a `Transactions` object. Then, for every transaction, a new subgraph entity is created. For more information about Substreams triggers, visit the [StreamingFast documentation](https://substreams.streamingfast.io/documentation/consume/subgraph/triggers) or check out community modules at [substreams.dev](https://substreams.dev/).
79
+
For StreamingFast-led Firehose/Substreams integrations, basic support for foundational Substreams modules (e.g. decoded transactions, logs and smart-contract events) and Substreams codegen tools are included. These tools enable the ability to enable [Substreams-powered subgraphs](./sps/sps-intro). Follow the [How-To Guide](https://substreams.streamingfast.io/documentation/how-to-guides/intro-your-first-application) and run `substreams codegen subgraph` to experience the codegen tools for yourself.
title: Introduction to Substreams-powered Subgraphs
3
3
---
4
4
5
-
By leveraging a Substreams package (`.yaml`) as a data source, your subgraph gains access to pre-extracted, indexed blockchain data, enabling more efficient and scalable data handling, especially when dealing with large or complex blockchain networks.
5
+
By using a Substreams package (`.spkg`) as a data source, your subgraph gains access to a stream of pre-indexed blockchain data. This enables more efficient and scalable data handling, especially with large or complex blockchain networks.
6
6
7
-
This technology opens up more efficient and versatile indexing for diverse blockchain environments. For more information on how to build a Substreams-powered subgraph, [click here](./triggers.mdx). You can also visit the following links for How-To Guides on using code-generation tooling to scaffold your first end to end project quickly:
7
+
There are two methods of enabling this technology:
Using Substreams [triggers](./triggers): Consume from any Substreams module by importing the Protobuf model through a subgraph handler and move all your logic into a subgraph. This method creates the subgraph entities directly in the subgraph.
10
+
11
+
Using [Entity Changes](https://substreams.streamingfast.io/documentation/consume/subgraph/graph-out): By writing more of the logic into Substreams, you can consume the module's output directly into graph-node. In graph-node, you can use the Substreams data to create your subgraph entities.
12
12
13
-
**Public Substreams packages**
13
+
It is really a matter of where you put your logic, in the subgraph or the Substreams. Keep in mind that having more of your logic in Substreams benefits from a parallelized model, whereas triggers will be linearly consumed in graph-node.
14
14
15
-
A Substreams package is a precompiled binary file that defines the specific data you want to extract from the blockchain—similar to the `mapping.ts` file in traditional subgraphs.
16
15
17
-
Visit [substreams.dev](https://substreams.dev/) to explore a growing collection of ready-to-use Substreams packages across various blockchain networks that can be easily integrated into your subgraph. If you can’t find a suitable Substreams package and want to build your own, click [here](https://thegraph.com/docs/en/substreams/) for detailed instructions on creating a custom package tailored to your needs.
16
+
Visit the following links for How-To Guides on using code-generation tooling to build your first end-to-end project quickly:
title: Tutorial: Set Up a Substreams-Powered Subgraph on Solana
3
3
---
4
4
5
-
Here you’ll walk through a Solana based example for setting up your Substreams-powered subgraph project. If you haven’t already, first check out the [Getting Started Guide](https://github.com/streamingfast/substreams/blob/enol/how-to-guides/docs/new/how-to-guides/intro-how-to-guides.md) for more information on how to initialize your project.
5
+
## Prerequisites
6
6
7
-
Consider the following example of a Substreams manifest (`substreams.yaml`), a configuration file similar to the `subgraph.yaml`, using the SPL token program Id:
7
+
Before starting, make sure to:
8
8
9
-
```graphql
9
+
- Complete the [Getting Started Guide](https://github.com/streamingfast/substreams-starter) to set up your development environment using a Dev Container.
10
+
- Be familiar with The Graph and basic blockchain concepts such as transactions and Protobufs.
11
+
12
+
## Step 1: Initialize Your Project
13
+
14
+
1. Open your Dev Container and run the following command to initialize your project:
15
+
16
+
```bash
17
+
substreams init
18
+
```
19
+
20
+
2. Select the "minimal" project option.
21
+
3. Replace the contents of the generated `substreams.yaml` file with the following configuration, which filters transactions for the Orca account on the SPL token program ID:
moduleName: map_spl_transfers# Module defined in the substreams.yaml
50
68
file: ./my-project-sol-v0.1.0.spkg
51
69
mapping:
52
70
apiVersion: 0.0.7
@@ -55,53 +73,68 @@ dataSources:
55
73
handler: handleTriggers
56
74
```
57
75
58
-
Once your manifests are created, define in the `schema.graphql` the data fields you’d like saved in your subgraph entities:
76
+
## Step 3: Define Entities in `schema.graphql`
77
+
78
+
Define the fields you want to save in your subgraph entities by updating the `schema.graphql` file. Here is an example:
59
79
60
80
```graphql
61
81
type MyTransfer @entity {
62
-
id: ID!
63
-
amount: String!
64
-
source: String!
65
-
designation: String!
66
-
signers: [String!]!
82
+
id: ID!
83
+
amount: String!
84
+
source: String!
85
+
designation: String!
86
+
signers: [String!]!
67
87
}
68
88
```
69
89
70
-
The Protobuf object is generated in AssemblyScript by running `npm run protogen` after running `substreams codegen subgraph` in the devcontainer, so you can import it in the subgraph code. Then transform your decoded Substreams data within the `src/mappings.ts` file, just like in a standard subgraph:
90
+
This schema defines a `MyTransfer` entity with fields such as `id`, `amount`, `source`, `designation`, and `signers`.
71
91
72
-
```tsx
73
-
import { Protobuf } from 'as-proto/assembly'
74
-
import { Events as protoEvents } from './pb/sf/solana/spl/token/v1/Events'
75
-
import { MyTransfer } from '../generated/schema'
92
+
## Step 4: Generate Protobuf Files
76
93
77
-
export function handleTriggers(bytes: Uint8Array): void {
To generate Protobuf objects in AssemblyScript, run the following command:
95
+
96
+
```bash
97
+
npm run protogen
98
+
```
99
+
100
+
This command converts the Protobuf definitions into AssemblyScript, allowing you to use them in the subgraph's handler.
101
+
102
+
## Step 5: Handle Substreams Data in `mappings.ts`
79
103
80
-
for (let i = 0; i < input.data.length; i++) {
81
-
const event = input.data[i]
104
+
With the Protobuf objects generated, you can now handle the decoded Substreams data in your `mappings.ts` file found in the `./src` directory. The example below demonstrates how to extract to subgraph entities the non-derived transfers associated to the Orca account id:
82
105
106
+
```bash
107
+
import { Protobuf } from "as-proto/assembly";
108
+
import { Events as protoEvents } from "./pb/sf/solana/spl/token/v1/Events";
109
+
import { MyTransfer } from "../generated/schema";
110
+
111
+
export function handleTriggers(bytes: Uint8Array): void {
1. The bytes containing Substreams data are decoded into the generated `Transactions` object, this object is used like any other AssemblyScript object
104
-
2. Looping over the transactions
105
-
3. Create a new subgraph entity for every transaction
138
+
You’ve successfully set up a trigger-based Substreams-powered subgraph for a Solana SPL token. You can now further customize your schema, mappings, and modules to suit your specific use case.
106
139
107
-
> Note: It's beneficial to have more of your logic in Substreams, as it allows for a parallelized model, whereas triggers are linearly consumed in `graph-node`.
140
+
For more advanced customization and optimizations, check out the official [Substreams documentation](https://substreams.streamingfast.io/tutorials/solana).
Custom triggers allow you to send data directly into your subgraph mappings file and entities (similar to tables and fields), enabling full use of the GraphQL layer. By importing the Protobuf definitions emitted by your Substreams module, you can receive and process this data within your subgraph’s handler, ensuring efficient and streamlined data management within the subgraph framework.
6
+
7
+
> Note: If you haven’t already, visit one of the How-To Guides found [here](./sps-intro) to scaffold your first project in the Development Container.
8
+
9
+
The following example demonstrates how to implement a `handleTransactions` function in a subgraph handler. This function receives raw Substreams bytes as a parameter and decodes them into a `Transactions` object. For each transaction, a new subgraph entity is created.
let transactions =assembly.eth.transaction.v1.Transactions.decode(bytes.buffer).trasanctions// 1.
14
+
if (transactions.length==0) {
15
+
log.info('No transactions found', [])
16
+
return
17
+
}
18
+
19
+
for (let i =0; i<transactions.length; i++) {
20
+
// 2.
21
+
let transaction =transactions[i]
22
+
23
+
let entity =newTransaction(transaction.hash) // 3.
24
+
entity.from=transaction.from
25
+
entity.to=transaction.to
26
+
entity.save()
27
+
}
28
+
}
29
+
```
6
30
7
-
Substreams triggers allow you to integrate Substreams data directly into your subgraph. By importing the [Protobuf definitions](https://substreams.streamingfast.io/documentation/develop/creating-protobuf-schemas#protobuf-overview) emitted by your Substreams module, you can receive and process this data in your subgraph's handler. This enables efficient and streamlined data handling within the subgraph framework.
31
+
Here's what you’re seeing in the `mappings.ts` file:
8
32
9
-
> Note: If you haven’t already, visit one of the How-To Guides found [here](./sps_intro) to scaffold your first project in the devcontainer.
33
+
1. The bytes containing Substreams data are decoded into the generated `Transactions` object, this object is used like any other AssemblyScript object
34
+
2. Looping over the transactions
35
+
3. Create a new subgraph entity for every transaction
10
36
11
-
To go through a coded example of a triggerbased Subgraph, [click here](./triggers_example).
37
+
To go through a detailed example of a trigger-based subgraph, [click here](./triggers-example).
Copy file name to clipboardExpand all lines: website/pages/en/substreams.mdx
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ title: Substreams
6
6
7
7
Substreams is a powerful blockchain indexing technology designed to enhance performance and scalability within The Graph Network. It offers the following features:
8
8
9
-
-**Accelerated Indexing**: Substreams reduces subgraph indexing time thanks to a parallelized engine, enabling faster data retrieval and processing.
9
+
-**Accelerated Indexing**: Substreams reduce subgraph indexing time thanks to a parallelized engine, enabling faster data retrieval and processing.
10
10
-**Multi-Chain Support**: Substreams expand indexing capabilities beyond EVM-based chains, supporting ecosystems like Solana, Injective, Starknet, and Vara.
@@ -46,3 +46,7 @@ To learn about the latest version of Substreams CLI, which enables developers to
46
46
### Expand Your Knowledge
47
47
48
48
- Take a look at the [Ethereum Explorer Tutorial](https://substreams.streamingfast.io/tutorials/evm) to learn about the basic transformations you can create with Substreams.
49
+
50
+
### Substreams Registry
51
+
52
+
A Substreams package is a precompiled binary file that defines the specific data you want to extract from the blockchain, similar to the `mapping.ts` file in traditional subgraphs. Visit [substreams.dev](https://substreams.dev/) to explore a growing collection of ready-to-use Substreams packages across various blockchain networks.
0 commit comments