# Shredstream gRPC

### Benefits

If you're a trader or need to receive transaction data earlier than your competitors, simple subscription to [Yellowstone gRPC endpoint](https://docs.rpcfast.com/rpc-fast-api/yellowstone-grpc) to retrieve transactions data in real time might not be sufficient for you – Solana RPC node still needs to insert shreds, process and validate them, before sending them via Yellowstone gRPC subscription. To overcome this behavior, you can subscribe directly to shredstream using the gRPC interface.

RPC Fast infra receives shreds from Jito and other partner providers to boost the performance.

> **Shredstream gRPC** endpoint is offered within the **Aperture plan** (SaaS) and a [dedicated node](https://rpcfast.com/dedicated-solana-nodes) offering at no add-on cost.

Using direct gRPC subscription to the shredstream endpoint, you will

* receive transactions **\~50-100ms earlier** on average, compared to Yellowstone gRPC;
* receive **even more** transactions, including failed and votes;
* **avoid** time-consuming replay of transactions by RPC node.

{% hint style="info" %}
Check out Geyser vs Shredstream benchmark on our [Github](https://github.com/dysnix/solana-test/tree/main/geyser-vs-shredstream).
{% endhint %}

### What's inside a Solana shred?

Shred is an essential component of Solana architecture. A shred is a fragment of a Solana block. Instead of transmitting entire blocks, Solana breaks them down into smaller pieces called *shreds*, which are easier to send and recover over the network.

Each shred contains unordered transactions data, slot number, it's index inside the slot.

{% hint style="success" %}
When using Shredstream gRPC, shreds are already reconstructed to **Solana entries**, which contain already ordered and serialized transactions.
{% endhint %}

For more info about the format of Solana entry, please refer to [Solana documentation](https://docs.rs/solana-entry/latest/solana_entry/entry/struct.Entry.html).

### How to create a direct subscription to Jito Shredstream?

1. If you already have a Solana dedicated node, you can use following endpoint for gRPC subscription: `sol-shredstream-CUSTOMER.rpcfast.net:443`
2. To decode gRPC stream, you need protobuf files. You can get them here: <https://github.com/jito-labs/mev-protos>
3. Install [grpcurl](https://github.com/fullstorydev/grpcurl) software onto your machine.
4. Launch grpcurl command from the directory where protobuf files has been downloaded:\\

   ```bash
   grpcurl \
     -proto shredstream.proto \
     -H 'x-token: YOUR_AUTH_TOKEN' \
     sol-shredstream-CUSTOMER.rpcfast.net:443 \
     shredstream.ShredstreamProxy/SubscribeEntries
   ```
5. You will start to receive **encoded** Solana entries.

### How to decode Solana shreds into human-readable format?

1. Clone the repository <https://github.com/dysnix/solana-test>
2. Run the following command inside repository to download code example

   ```bash
   git submodule init && git submodule update --recursive --remote --force
   ```
3. Navigate to `jito-shredstream-proxy/examples` directory.
4. [Install Rust language](https://rustup.rs/) tools onto your machine.
5. Set environment variables

   ```bash
   export SHREDSTREAM_GRPC_URL=https://sol-shredstream-CUSTOMER.rpcfast.net
   export SHREDSTREAM_AUTH_TOKEN=YOUR-AUTH-TOKEN
   ```
6. Launch code example

   ```bash
   cargo run --example deshred
   ```
7. You will receive decoded transactions for each slot.
8. If you want to integrate this to your application code or workflow, please use `deshred.rs` as an example.
