Note

This documentation is under construction and the web3.js 1.0 stable version isn’t released. If your using a version v0.x.x of web3.js then please have a look at github.com/ethereum/wiki/wiki/JavaScript-API.

Core Subscriptions Module

The Core Subscriptions Module does provide all the subscriptions classes to extend and execute them.

AbstractSubscription

Source: AbstractSubscription

The AbstractSubscription class extends from the EventEmitter object and does have the following constructor parameters:

  • type - String The subscriptions type eth_subscribe or shh_subscribe.
  • method - String The subscription method which is the first parameter in the JSON-RPC payload object.
  • options - Object The options object of the subscription.
  • formatters - Object The formatters object.
  • moduleInstance - AbstractWeb3Module An AbstractWeb3Module instance.

The AbstractSubscription class is the base subscription class of all subscriptions.

You’re able to overwrite these methods:

subscribe

subscription.subscribe(callback)

This method will start the subscription.

Parameters

  • callback - Function

Returns

AbstractSubscription


unsubscribe

subscription.unsubscribe(callback)

This method will end the subscription.

Parameters

  • callback - Function

Returns

Promise<boolean|Error>


beforeSubscription

subscription.beforeSubscription(moduleInstance)

This method will be executed before the subscription happens. The beforeSubscription method gives you the possibility to customize the subscription class before the request will be sent.

Parameters

  • moduleInstance - AbstractWeb3Module The current AbstractWeb3Module.

onNewSubscriptionItem

subscription.onNewSubscriptionItem(moduleInstance)

This method will be executed on each subscription item. The onNewSubscriptionItem method gives you the possibility to map the response.

Parameters

  • item - any

Returns

any


type

subscription.type

The property type does contain the subscription type.

Returns

String - eth_subscribe or shh_subscribe


method

subscription.method

The property method does contain the subscription method.

Returns

String


options

subscription.options

The property options does contain the subscription options.

Returns

Object


id

subscription.id

The property id does contain the subscription id when the subscription is running.

Returns

String