103.0.0 • Published 26 days ago

@streamr/sdk v103.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
26 days ago

latest npm package version GitHub stars Discord Chat

The Streamr SDK allows you to interact with the Streamr Network from JavaScript-based environments, such as browsers and Node.js. This library contains convenience functions for creating and managing streams on the Streamr Network.

Checkout our documentation for the full usage instructions.

Quickstart

The SDK is available on NPM and can be installed simply by:

npm install @streamr/sdk

If using TypeScript you can import the library with:

import { StreamrClient } from '@streamr/sdk'

If using Node.js you can import the library with:

const { StreamrClient } = require('@streamr/sdk')

Environments and frameworks

The Streamr SDK is built for the browser and Node.js environments.

Node.js

  • Node.js 20, NPM 10 and later versions are recommended.

Browser (Website/WebApps)

  • For usage in the browser include the latest build, e.g. by including a <script> tag pointing at a CDN:
  • <script src="https://unpkg.com/@streamr/sdk@latest/streamr-sdk.web.min.js"></script>
  • To use within React, please see streamr-client-react

Browser extension

  • Due to the stricter security rules inside browser extensions you must use the web build version of the Streamr SDK.

Usage

Full API reference

For a full API reference visit https://docs.streamr.network/usage/sdk/api/.

Identity

In Streamr, cryptographic keys establish identity. Various types of key pairs and algorithms are supported, for example Ethereum private keys. Read more about Identity. Providing a key is not required if you are subscribing to public streams on the Network.

const streamr = new StreamrClient({
    auth: {
        privateKey: 'ethereum-private-key'
    }
})

Authenticating with an Ethereum private key contained in an Ethereum (web3) provider (e.g. MetaMask):

const streamr = new StreamrClient({
    auth: {
        ethereum: window.ethereum,
    }
})

You can also create an anonymous client instance that can interact with public streams:

const streamr = new StreamrClient()

Creating a stream

// Requires POL tokens (Polygon blockchain gas token)
const stream = await streamr.createStream({
    id: '/foo/bar'
})

console.log(stream.id) // e.g. `0x12345.../foo/bar`

Subscribing

const streamId = 'streams.dimo.eth/firehose/weather'

streamr.subscribe(streamId, (message) => {
    // handle for individual messages
})

Publishing

Publishing messages requires your Ethereum account to have permission to publish. See the stream permission docs for more information.

// Requires POL tokens (Polygon blockchain gas token)
const stream = await streamr.createStream({
    id: '/foo/bar'
})

await stream.publish({ timestamp: Date.now() })

Requesting historical messages

By default subscribe will not request historical messages.

You can fetch historical messages with the resend method:

streamr.resend(streamId, { last: 10 }, (msgs) => {
  console.log("messages": msgs);
});

This Readme only scratches the surface of what's possible - be sure to checkout our documentation for the full usage instructions.

102.1.1

2 months ago

103.0.0-rc.20

1 month ago

103.0.0-rc.17

2 months ago

103.0.0-rc.18

2 months ago

103.0.0-rc.15

2 months ago

103.0.0-rc.16

2 months ago

103.0.0-rc.13

2 months ago

103.0.0-rc.14

2 months ago

103.0.0-rc.11

2 months ago

103.0.0-rc.12

2 months ago

103.0.0-rc.19

1 month ago

103.0.0

26 days ago

103.0.0-rc.1

3 months ago

103.0.0-rc.3

3 months ago

103.0.0-rc.2

3 months ago

103.0.0-rc.5

3 months ago

103.0.0-rc.9

2 months ago

103.0.0-rc.8

3 months ago

103.0.0-rc.0

4 months ago

102.2.0-rc.1

4 months ago

102.2.0-rc.2

4 months ago

102.2.0-rc.3

4 months ago

102.2.0-rc.0

4 months ago

102.1.0

5 months ago

102.0.0

5 months ago

102.0.0-beta.2

6 months ago

102.0.0-beta.3

5 months ago

102.0.0-beta.1

6 months ago

102.0.0-beta.0

9 months ago

101.1.2

10 months ago

101.1.1

10 months ago

101.0.0-beta.0

1 year ago

101.1.0

11 months ago

101.0.1

12 months ago

101.0.0-beta.1

1 year ago

101.0.0

12 months ago

101.0.0-beta.2

1 year ago

101.0.0-beta.3

1 year ago

101.0.0-beta.4

1 year ago

101.1.1-beta.0

11 months ago

101.1.1-beta.1

10 months ago

101.0.2-beta.0

11 months ago

100.2.5-beta.0

1 year ago

100.2.5-beta.1

1 year ago

100.2.4

1 year ago

100.2.4-beta.0

1 year ago

100.2.3

1 year ago

100.2.2

1 year ago

100.2.1

1 year ago

100.2.0

1 year ago

100.1.2

1 year ago

100.1.1

1 year ago

100.1.0

1 year ago

100.0.0

1 year ago

100.0.0-rc.1

1 year ago

100.0.0-rc.0

1 year ago