---
description: >-
  Subscribe requests for monitoring transactions across Multiple Accounts using
  Solana gRPC
---

# Subscribing to all transactions of multiple addresses

A subscribe request defines the type of updates you want using filters. Filters allow you to set specific conditions—like monitoring a particular wallet, account, or transaction type—ensuring that you only receive updates relevant to your needs. We can subscribe to transactions using the <mark style="color:yellow;">transactions filter.</mark>

{% tabs %}
{% tab title="TypeScript" %}
```typescript
import Client, {
  CommitmentLevel,
  SubscribeRequestAccountsDataSlice,
  SubscribeRequestFilterAccounts,
  SubscribeRequestFilterBlocks,
  SubscribeRequestFilterBlocksMeta,
  SubscribeRequestFilterEntry,
  SubscribeRequestFilterSlots,
  SubscribeRequestFilterTransactions,
} from "@triton-one/yellowstone-grpc";
import { SubscribeRequestPing } from "@triton-one/yellowstone-grpc/dist/grpc/geyser";
import bs58 from "bs58";

// Interface for the subscription request structure
interface SubscribeRequest {
  accounts: { [key: string]: SubscribeRequestFilterAccounts };
  slots: { [key: string]: SubscribeRequestFilterSlots };
  transactions: { [key: string]: SubscribeRequestFilterTransactions };
  transactionsStatus: { [key: string]: SubscribeRequestFilterTransactions };
  blocks: { [key: string]: SubscribeRequestFilterBlocks };
  blocksMeta: { [key: string]: SubscribeRequestFilterBlocksMeta };
  entry: { [key: string]: SubscribeRequestFilterEntry };
  commitment?: CommitmentLevel;
  accountsDataSlice: SubscribeRequestAccountsDataSlice[];
  ping?: SubscribeRequestPing;
}

const ADDRESSES_TO_MONITOR = ["HgQy5bqJd3GcjqakukhfMpqAfP62nTxGiqAqh4QtTuHF","8pQYy5peKKqKk34BvJBuuBAfakukTLsmT2MVSzijUgt1"];

/**
 * Subscribes to the gRPC stream and handles incoming data.
 *
 * @param client - Yellowstone gRPC client
 * @param args - The Subscription request which specifies what data to stream
 */
async function handleStream(client: Client, args: SubscribeRequest) {
  const stream = await client.subscribe();

  // Promise that resolves when the stream ends or errors out
  const streamClosed = new Promise<void>((resolve, reject) => {
    stream.on("error", (error) => {
      console.error("Stream error:", error);
      reject(error);
      stream.end();
    });

    stream.on("end", resolve);
    stream.on("close", resolve);
  });

  // Handle incoming transaction data
  stream.on("data", (data) => {
    if (data?.transaction) {
      console.log("Received Transaction:");
      console.log(bs58.encode(data?.transaction?.transaction?.signature));
      console.log("\n");
      console.log(data?.transaction);
    }
  });

  // Send the subscription request
  await new Promise<void>((resolve, reject) => {
    stream.write(args, (err: any) => {
      err ? reject(err) : resolve();
    });
  }).catch((err) => {
    console.error("Failed to send subscription request:", err);
    throw err;
  });

  // Wait for the stream to close
  await streamClosed;
}

/**
 * Entry point to start the subscription stream.
 *
 */
async function subscribeCommand(client: Client, args: SubscribeRequest) {
  while (true) {
    try {
      await handleStream(client, args);
    } catch (error) {
      console.error("Stream error, retrying in 1 second...", error);
      await new Promise((resolve) => setTimeout(resolve, 1000));
    }
  }
}

// Instantiate Yellowstone gRPC client with env credentials
const client = new Client(
  "YOUR-GRPC-ENDPOINT", //Your Region specific gRPC URL
  "YOUR-ACCESS-TOKEN", // your Access Token
  undefined,
);

/**
 * Subscribe Request: The `transactions` field filters transaction streams to only include those
 * that involve the addresses in `accountInclude`.
 */
const req: SubscribeRequest = {
  accounts: {},
  slots: {},
  transactions: {
    pumpFun: {
      vote: false,
      failed: false,
      signature: undefined,
      accountInclude: ADDRESSES_TO_MONITOR, //list of wallets to be monitored
      accountExclude: [],
      accountRequired: [],
    },
  },
  transactionsStatus: {},
  blocks: {},
  blocksMeta: {},
  entry: {},
  accountsDataSlice: [],
  ping: undefined,
  commitment: CommitmentLevel.CONFIRMED,
};

// Start the subscription
subscribeCommand(client, req);

```


{% endtab %}
{% endtabs %}

The `accountInclude` field is an <mark style="color:yellow;">array</mark> and can take <mark style="color:yellow;">multiple wallet addresses</mark>, and will subscribe to all transactions from them.

{% hint style="success" %}
You can copy and paste this code on Replit to see it action, or simply remix [<mark style="color:yellow;">this code</mark>](https://replit.com/@shyft-to/streaming-transactions-for-multiple-address?v=1) on Replit.
{% endhint %}
