# Substreams-Powered Subgraphs

{% hint style="danger" %}
&#x20;An internet connection is required for generating Rust bindings.
{% endhint %}

1. Direct Download

```sh
LINK=$(curl -s https://api.github.com/repos/bufbuild/buf/releases/latest | \
awk "/download.url.*buf-Linux-$(uname -m)\"/ {print \$2}" | sed 's/"//g')

echo Downloading $LINK

curl -L $LINK -o /usr/bin/buf
```

2. Using npm

```sh
npm install @bufbuild/buf
```

#### Rust

A complete Rust environment is necessary for developing Substreams modules.

```sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

source $HOME/.cargo/env
```

### Create Substreams-Powered Subgraphs

There are two methods of creating Substreams-Powered Subgraphs:

1. **Using Substreams** [**triggers**](https://thegraph.com/docs/en/sps/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.
2. **Using** [**Entity Changes⁠**](https://docs.substreams.dev/how-to-guides/sinks/subgraph/graph-out): By writing more of the logic into Substreams, you can consume the module’s output directly into Subgraph. In Subgraph you can use the Substreams data to create your Subgraph entities.

You can choose where to place your logic, either in the Subgraph or Substreams. However, consider what aligns with your data needs, as Substreams has a parallelized model, and triggers are consumed linearly.

### Deploy Substreams-Powered Subgraphs

{% hint style="danger" %}
Before deploying a substream-powered subgraph, ensure substream are enabled for the blockchain network in Graph Node.
{% endhint %}

1. Add Rust Target

```sh
rustup target add wasm32-unknown-unknown
```

2. Generate Protobuf Types

```sh
substreams protogen
```

This command generates types in /src/pb.

3. Build Substreams

```sh
substreams build
```

This command creates a Substream package (`.spkg`), which can be used as a data source for a subgraph to access pre-indexed blockchain data streams.

4. Generate Subgraph Project

```sh
substreams codegen subgraph
```

5. Navigate to the Subgraph Directory

Edit the following files as needed:

* mappings.ts
* schema.graphql
* subgraph.yaml

6. Install Dependencies

```sh
npm install
```

7. Generate AssemblyScript & Protobuf Bindings

```sh
npm run generate
```

8. Build Subgraph

```sh
npm run build
```

The final step is to deploy the subgraph using the deployment command. See [Manage Subgraph](/services/dedicated-indexing/graph-nodes/subgraph-manual/manage-subgraph.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.traceye.io/services/dedicated-indexing/graph-nodes/subgraph-manual/substreams-powered-subgraphs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
