The main API used to interact with Streamr.

Hierarchy

  • StreamrClient

Important

  • Creates a new stream.

    Remarks

    when creating a stream with an ENS domain, the returned promise can take several minutes to settle

    Parameters

    • propsOrStreamIdOrPath: string | Partial<StreamMetadata> & {
          id: string;
      }

      the stream id to be used for the new stream, and optionally, any associated metadata

    Returns Promise<Stream>

  • Gets a stream, creating one if it does not exist.

    Remarks

    when creating a stream with an ENS domain, the returned promise can take several minutes to settle

    Parameters

    • props: {
          id: string;
          partitions?: number;
      }

      the stream id to get or create. Field partitions is only used if creating the stream.

      • id: string
      • Optional partitions?: number

    Returns Promise<Stream>

  • Gets a stream.

    Returns

    rejects if the stream is not found

    Parameters

    • streamIdOrPath: string

    Returns Promise<Stream>

  • Publishes a message to a stream partition in the network.

    Returns

    the published message (note: the field content is encrypted if the stream is private)

    Parameters

    • streamDefinition: StreamDefinition

      the stream or stream partition to publish the message to

    • content: unknown

      the content (the payload) of the message (must be JSON serializable)

    • Optional metadata: PublishMetadata

      provide additional metadata to be included in the message or to control the publishing process

    Returns Promise<Message>

  • Subscribes to a stream partition in the network.

    Returns

    a Subscription that can be used to manage the subscription etc.

    Parameters

    • options: SubscribeOptions

      the stream or stream partition to subscribe to, additionally a resend can be performed by providing resend options

    • Optional onMessage: MessageListener

      callback will be invoked for each message received in subscription

    Returns Promise<Subscription>

  • Unsubscribes from streams or stream partitions in the network.

    Remarks

    no-op if subscription does not exist

    Parameters

    • Optional streamDefinitionOrSubscription: StreamDefinition | Subscription

      leave as undefined to unsubscribe from all existing subscriptions.

    Returns Promise<unknown>

Other

id: string
generateEthereumAccount: (() => {
    address: string;
    privateKey: string;
}) = _generateEthereumAccount

Type declaration

    • (): {
          address: string;
          privateKey: string;
      }
    • Returns {
          address: string;
          privateKey: string;
      }

      • address: string
      • privateKey: string
  • Adds an encryption key for a given publisher to the key store.

    Remarks

    Keys will be added to the store automatically by the client as encountered. This method can be used to manually add some known keys into the store.

    Parameters

    Returns Promise<void>

  • Assigns a stream to a storage node.

    Parameters

    • streamIdOrPath: string
    • storageNodeAddress: string

    Returns Promise<void>

  • Used to manually initialize the network stack and connect to the network.

    Remarks

    Connecting is handled automatically by the client. Generally this method need not be called by the user.

    Returns Promise<void>

  • Deletes a stream.

    Parameters

    • streamIdOrPath: string

    Returns Promise<void>

  • Destroys an instance of a StreamrClient by disconnecting from peers, clearing any pending tasks, and freeing up resources. This should be called once a user is done with the instance.

    Remarks

    As the name implies, the client instance (or any streams or subscriptions returned by it) should not be used after calling this method.

    Returns Promise<void>

  • Returns the list of all permissions in effect for a given stream.

    Parameters

    • streamIdOrPath: string

    Returns Promise<PermissionAssignment[]>

  • Gets the metadata of a storage node from the storage node registry.

    Returns

    rejects if the storage node is not found

    Parameters

    • nodeAddress: string

    Returns Promise<StorageNodeMetadata>

  • Gets a list of storage nodes.

    Parameters

    • Optional streamIdOrPath: string

      if a stream is given, returns the list of storage nodes the stream has been assigned to; leave as undefined to return all storage nodes

    Returns Promise<EthereumAddress[]>

  • Gets all streams assigned to a storage node.

    Returns

    a list of Stream as well as blockNumber of result (i.e. blockchain state)

    Parameters

    • storageNodeAddress: string

    Returns Promise<{
        blockNumber: number;
        streams: Stream[];
    }>

  • Gets all ethereum addresses that have PUBLISH permission to the stream.

    Parameters

    • streamIdOrPath: string

    Returns AsyncIterable<EthereumAddress>

  • Gets all ethereum addresses that have SUBSCRIBE permission to the stream.

    Parameters

    • streamIdOrPath: string

    Returns AsyncIterable<EthereumAddress>

  • Grants permissions on a given stream.

    Parameters

    Returns Promise<void>

  • Checks whether the given permission is in effect.

    Parameters

    Returns Promise<boolean>

  • Checks whether a stream is assigned to a storage node.

    Parameters

    • streamIdOrPath: string
    • storageNodeAddress: string

    Returns Promise<boolean>

  • Checks whether a given ethereum address has PUBLISH permission to a stream.

    Parameters

    • streamIdOrPath: string
    • userAddress: string

    Returns Promise<boolean>

  • Checks whether a given ethereum address has SUBSCRIBE permission to a stream.

    Parameters

    • streamIdOrPath: string
    • userAddress: string

    Returns Promise<boolean>

  • Unassigns a stream from a storage node.

    Parameters

    • streamIdOrPath: string
    • storageNodeAddress: string

    Returns Promise<void>

  • Revokes permissions on a given stream.

    Parameters

    Returns Promise<void>

  • Sets a list of permissions to be in effect.

    Remarks

    Can be used to set the permissions of multiple streams in one transaction. Great for doing bulk operations and saving gas costs. Notice that the behaviour is overwriting, therefore any existing permissions not defined will be removed (per stream).

    Parameters

    Returns Promise<void>

  • Sets the metadata of a storage node in the storage node registry.

    Remarks

    Acts on behalf of the wallet associated with the current StreamrClient instance.

    Parameters

    • metadata: undefined | StorageNodeMetadata

      if undefined, removes the storage node from the registry

    Returns Promise<void>

  • Updates the metadata of a stream.

    Parameters

    • props: Partial<StreamMetadata> & {
          id: string;
      }

      the stream id and the metadata fields to be updated

    Returns Promise<Stream>

  • Waits for a message to be stored by a storage node.

    Returns

    rejects if message was found in storage before timeout

    Parameters

    • message: Message

      the message to be awaited for

    • Optional options: {
          count?: number;
          interval?: number;
          timeout?: number;
      }

      additional options for controlling waiting and message matching

      • Optional count?: number

        Controls size of internal resend used in polling.

      • Optional interval?: number

        Determines how often should storage node be polled.

      • Optional timeout?: number

        Timeout after which to give up if message was not seen.

    Returns Promise<void>

Generated using TypeDoc