Stream data on-chain

Basic usage

import  {Streamnote} from  "blocknote"

const options = {            
    title:    "", 
    mime:     "text/plain"
    getPayloadTransactionId: (payload_transaction_id) => {        
        // Return the payload_transaction_id.
        // It is required for those who want to read to the stream.
        console.log("stream id: "+payload_transaction_id);
    },     
    onFinish: (result) => { console.log("finish", result); }
}
const sender_mnemonic    = "gorilla shiver hood theory letter absorb arctic ...";
const stream             = new Streamnote(sender_mnemonic, options); 

stream.send("some data to stream, can be utf8, arrayBuffer or uint8array"); 
stream.send("send some more data");
stream.send("and a bit more");

stream.stop(); // Ends the stream.

Constructor

Name
Description
Type

sender_mnemonic

The sender's mnemonic

string

options

See the options table below

object

Options

Name
Description
Type
Default

title

The stream's title

string

Untitled

mime

The stream's mime type

string

plain/text

compression

  • The compression algorithm's name: brotli, gzip, lz4, lz-string, pako, snappy

  • "none" won't compress the data.

string

none

aes_key

An AES key to encrypt the stream. Do not set an AES key if you are already encrypting with a password.

string

password

A password to encrypt the stream. (The strength of the password is not verified) Do not set a password if you are already encrypting with an AES key.

string

encrypt_title

Encrypt the title. This option will be ignored if aes_key or password is not set.

boolean

true

getPayloadTransactionId ⇒ (payload_transaction_id)

Callback returning the payload_transaction_id of the current stream, required by StreamnoteReader to listen to this stream.

function

onFinish

⇒ (result)

Callback executes once stream ends, returning a result object that contains the payload and the details of the stream.

function

onError

⇒ (error)

Triggered if an error occurs while sending the batch of transactions. Note that Blocknote will always retry to send a transaction when failed, so they are not throwable errors. It is more like a log of failing transaction.

function


Methods

send

Parameters

Name
Description
Type

raw_content

The content to stream

string, Uint8Array, Buffer

Return

null


stop

Stop accepting new incoming data but sends the remaining content. Marks the stream as concluded. Ensure not to omit it, or the StreamnoteReader will continually await new incoming data.

Return

null

Last updated