> For the complete documentation index, see [llms.txt](https://blocknote-js.gitbook.io/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blocknote-js.gitbook.io/doc/blocknote/data-streaming/read-a-stream.md).

# Read a stream

To read a stream on-chain, use its  `payload_transaction_id`  &#x20;

```javascript
let content;

(async() => {

    const options = { 
        onGetHistoricalData: (previous_data) => { content = previous_data; },                      
        onData: (data) => { content += data; },  
        onFinish: (result) => { console.log(result); }        
        onError: (error) => { console.log(error); }
    }
    const reader = new StreamnoteReader(
        "G3RINZEJDP2UCPKHEFRL5DRPIYC45PSOYYTDON3JA6NRPEJKFBJA", 
        options
    );    
    
    console.log(await reader.getPayload());
       
    if(await reader.isOver()){    
        console.log("The stream is over");
    }
    
    reader.start(); 
});


```

## Constructor&#x20;

<table><thead><tr><th width="242">Name</th><th width="430">Description</th><th>Type</th></tr></thead><tbody><tr><td>payload_transaction_id</td><td>The <code>payload_transaction_id</code> of the stream to read</td><td>string</td></tr><tr><td>options</td><td>See the options table below</td><td>object</td></tr></tbody></table>

#### Options

<table><thead><tr><th width="168">Name</th><th width="467">Description</th><th width="114">Type</th></tr></thead><tbody><tr><td>password</td><td>The password to decrypt the stream if required.</td><td>string</td></tr><tr><td>aes_key</td><td>The AES key to decrypt the stream if required.</td><td>string</td></tr><tr><td><p>GetHistoricalData</p><p>⇒ (historical_data)</p></td><td>A callback that provides all the data sent since the start of the stream.</td><td>function</td></tr><tr><td><p>onData</p><p>⇒ (data)</p></td><td>The callback that retrieves new incoming data as it arrives.</td><td>function</td></tr><tr><td><p>onFinish</p><p>⇒ ()</p></td><td>The callback triggered when the stream ends.</td><td>function</td></tr></tbody></table>

***

## Methods

{% hint style="info" %}
**Note:** `getPayload()` and `isOver()` can be used without passing any options to the `StreamnoteReader` constructor. Even if the stream is encrypted (with a password or an AES key), no decryption information is needed to check whether the stream has finished or to retrieve its payload.
{% endhint %}

### <mark style="color:$primary;">start</mark>

Start reading the stream.\
Incoming data will start being delivered through the `onData(data)` callback.

#### Return

`null`<br>

***

### <mark style="color:$primary;">getPayload</mark>

#### Return

A promise that contains the stream's payload.&#x20;

***

### <mark style="color:$primary;">getHistoricalData</mark>

#### Return

A promise that contains all the data sent since the start of the stream.

***

### <mark style="color:$primary;">isOver</mark>

#### Return

A promise that resolves to a boolean indicating whether the stream has ended.
