> ## Documentation Index
> Fetch the complete documentation index at: https://www.helius.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# So streamen Sie Solana Pump AMM-Daten

> Erfahren Sie, wie Sie Live-Solana Pump AMM-Daten mit LaserStream WebSocket streamen. Protokollbasiertes Monitoring verfügbar in allen Plänen mit automatischer Wiederverbindung.

## Verwendung von LaserStream WebSocket

<p>
  [LaserStream WebSocket](/docs/de/rpc/websocket) bietet eine einfache WebSocket-Integration und ist in allen Helius-Plänen verfügbar, was es zu einer praktischen Wahl für Entwickler macht. Dieses Beispiel verwendet Solanas `logsSubscribe`-Methode, sodass Sie nur Protokollnachrichten erhalten.
</p>

<Tip>
  LaserStream WebSocket ist bis zu 200 ms schneller als die standardmäßige Agave RPC-basierte WebSocket-Implementierung.
</Tip>

### So funktioniert es

Verbinden Sie sich mit dem [LaserStream WebSocket-Endpunkt](https://www.helius.dev/docs/api-reference/endpoints), abonnieren Sie Protokolle, die das [Pump AMM-Programm](https://orbmarkets.io/address/pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA/history) erwähnen, und verarbeiten Sie die ankommenden Protokolldaten.

Das untenstehende Beispiel enthält eine automatische Wiederverbindungslogik mit exponentiellen Rücksetzzeiten.

## Anforderungen

<Card>
  <ul>
    <li><strong>Node.js ≥ 18</strong> (getestet mit v20)</li>
    <li><strong>TypeScript ≥ 5</strong>, wenn Sie die <code>.ts</code>-Beispiele mit <code>ts‑node</code> ausführen möchten</li>
    <li>Jeder <strong>Helius-Plan</strong> – funktioniert mit allen Planstufen</li>
    <li>Eine <strong>Umgebungsvariable</strong> namens <code>HELIUS\_API\_KEY</code>, die Ihren API-Schlüssel speichert</li>
  </ul>

  <Tip>
    Installieren Sie Abhängigkeiten global: <code>npm i -g typescript ts‑node</code>
  </Tip>
</Card>

## Implementierung

<Steps>
  <Step title="Abhängigkeiten installieren">
    ```bash theme={"system"}
    npm install ws
    ```
  </Step>

  <Step title="Erstellen des WebSocket-Clients">
    Erstellen Sie eine Datei namens `standard-ws-pump.ts` mit folgendem Code:

    ```ts theme={"system"}
    // standard-ws-pump.ts
    import WebSocket from 'ws';

    // Configuration
    const MAX_RETRIES = 5;
    const INITIAL_RETRY_DELAY = 1000; // 1 second
    let retryCount = 0;
    let retryTimeout: NodeJS.Timeout | null = null;
    let subscriptionId: number | null = null;

    // Create a WebSocket connection
    let ws: WebSocket;

    function connect() {
      ws = new WebSocket(`wss://mainnet.helius-rpc.com/?api-key=${process.env.HELIUS_API_KEY}`);

      // Function to send a request to the WebSocket server
      function sendRequest(ws: WebSocket): void {
        const request = {
          "jsonrpc": "2.0",
          "id": 1,
          "method": "logsSubscribe",
          "params": [
            {
              "mentions": ["pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA"]
            }
          ]
        };
        console.log('Sending subscription request:', JSON.stringify(request, null, 2));
        ws.send(JSON.stringify(request));
      }

      // Function to send a ping to the WebSocket server
      function startPing(ws: WebSocket): void {
        setInterval(() => {
          if (ws.readyState === WebSocket.OPEN) {
            ws.ping();
            console.log('Ping sent');
          }
        }, 30000); // Ping every 30 seconds
      }

      // Define WebSocket event handlers
      ws.on('open', function open() {
        console.log('WebSocket is open');
        retryCount = 0; // Reset retry count on successful connection
        sendRequest(ws); // Send a request once the WebSocket is open
        startPing(ws); // Start sending pings
      });

      ws.on('message', function incoming(data: WebSocket.Data) {
        const messageStr = data.toString('utf8');
        try {
          const messageObj = JSON.parse(messageStr);

          // Handle subscription confirmation
          if (messageObj.result && typeof messageObj.result === 'number') {
            subscriptionId = messageObj.result;
            console.log('Successfully subscribed with ID:', subscriptionId);
            return;
          }

          // Handle actual log data
          if (messageObj.params && messageObj.params.result) {
            const logData = messageObj.params.result;
            console.log('Received log data:', JSON.stringify(logData, null, 2));
            
            // Extract the transaction signature if available
            if (logData.signature) {
              console.log('Transaction signature:', logData.signature);
              // You can call getTransaction with this signature to get the full transaction details
            }
          } else {
            console.log('Received message:', JSON.stringify(messageObj, null, 2));
          }
        } catch (e) {
          console.error('Failed to parse JSON:', e);
        }
      });

      ws.on('error', function error(err: Error) {
        console.error('WebSocket error:', err);
      });

      ws.on('close', function close() {
        console.log('WebSocket is closed');
        if (subscriptionId) {
          console.log('Last subscription ID was:', subscriptionId);
        }
        reconnect();
      });
    }

    function reconnect() {
      if (retryCount >= MAX_RETRIES) {
        console.error('Max retry attempts reached. Please check your connection and try again.');
        return;
      }

      const delay = INITIAL_RETRY_DELAY * Math.pow(2, retryCount);
      console.log(`Attempting to reconnect in ${delay/1000} seconds... (Attempt ${retryCount + 1}/${MAX_RETRIES})`);

      retryTimeout = setTimeout(() => {
        retryCount++;
        connect();
      }, delay);
    }

    // Start the initial connection
    connect();

    // Cleanup function
    process.on('SIGINT', () => {
      if (retryTimeout) {
        clearTimeout(retryTimeout);
      }
      if (ws) {
        ws.close();
      }
      process.exit();
    });
    ```
  </Step>

  <Step title="Umgebungsvariablen setzen">
    Fügen Sie Ihren Helius-API-Schlüssel als Umgebungsvariable hinzu:

    ```bash theme={"system"}
    export HELIUS_API_KEY=your-helius-api-key
    ```

    Ersetzen Sie `your-helius-api-key` durch Ihren aktuellen Helius-API-Schlüssel aus dem Dashboard.

    Wenn Sie keinen API-Schlüssel haben, [melden Sie sich an](https://dashboard.helius.dev/signup) oder lassen Sie Ihren Agenten einen programmatisch mit [dem Helius CLI](/docs/de/agents/cli) erstellen.
  </Step>

  <Step title="Anwendung ausführen">
    Führen Sie das Skript aus, um mit dem Streaming von Pump AMM-Daten zu beginnen:

    ```bash theme={"system"}
    npx ts-node standard-ws-pump.ts
    ```

    Sie erhalten Protokollnachrichten, die das Pump AMM-Programm erwähnen. Um die vollständige Transaktion abzurufen, rufen Sie [`getTransaction`](/docs/de/api-reference/rpc/http/gettransaction) mit der Signatur aus dem Protokolleintrag auf.
  </Step>
</Steps>

## Hauptvorteile

* **Universeller Zugang** - Verfügbar in allen Helius-Plänen, einschließlich kostenloser Stufe
* **Leichtgewichtig** - Minimaler Datentransfer, da nur Protokolle gestreamt werden, nicht vollständige Transaktionen
* **Einfach zu implementieren** - Verwendet das standardmäßige Solana RPC-WebSocket-Protokoll
* **Niedrige Einstiegsschwelle** - Perfekt für Prototyping und initiales Monitoring

## Abrufen vollständiger Transaktionsdetails

Da der Standard-WebSocket nur Protokollnachrichten bereitstellt, benötigen Sie einen zusätzlichen Schritt, um vollständige Transaktionsdaten zu erhalten:

```ts theme={"system"}
// Example of how to fetch a full transaction from a log entry
async function fetchFullTransaction(signature: string) {
  const response = await fetch(`https://mainnet.helius-rpc.com/?api-key=${process.env.HELIUS_API_KEY}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      jsonrpc: '2.0',
      id: 'my-id',
      method: 'getTransaction',
      params: [
        signature,
        {
          encoding: 'jsonParsed',
          maxSupportedTransactionVersion: 1
        }
      ]
    })
  });
  
  const data = await response.json();
  return data.result;
}
```

## Häufige Probleme und Lösungen

<AccordionGroup>
  <Accordion title="401 Nicht autorisiert">
    Überprüfen Sie, ob Ihr HELIUS\_API\_KEY korrekt ist.
  </Accordion>

  <Accordion title="Keine Protokolle empfangen">
    Stellen Sie sicher, dass die Pump AMM-Programm-Adresse korrekt ist und auf dem Programm Aktivität vorhanden ist.
  </Accordion>

  <Accordion title="Verbindung wird unterbrochen">
    Implementieren Sie eine robustere Wiederverbindungslogik oder überprüfen Sie die Netzwerkstabilität.
  </Accordion>
</AccordionGroup>
