How to use the web3-core-subscriptions.subscriptions function in web3-core-subscriptions

To help you get started, we’ve selected a few web3-core-subscriptions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vechain / thorify / src / extend / methods.ts View on Github external
name: 'getChainTag',
                call: 'eth_getChainTag',
                params: 0,
            }),
            new web3.extend.Method({
                name: 'getPastLogs',
                call: 'eth_getLogs',
                params: 1,
                inputFormatter: [web3.extend.formatters.inputLogFormatter],
                outputFormatter: web3.extend.formatters.outputLogFormatter,
            }),
        ],
    })

    // subscriptions
    const subs = new Subscriptions({
        name: 'subscribe',
        type: 'eth',
        subscriptions: {
            newBlockHeaders: {
                subscriptionName: 'newHeads',
                params: 1,
                inputFormatter: [inputBlockFilterFormatter],
                subscriptionHandler(subscriptionMsg: any) {
                    if (subscriptionMsg.error) {
                        this.emit('error', subscriptionMsg.error)
                         // web3-core-subscriptions/subscription sets a default value for this.callback
                        this.callback(subscriptionMsg.error, null, this)
                    } else {
                        const result = web3.extend.formatters.outputBlockFormatter(subscriptionMsg.data)
                        if (result.removed) {
                            this.emit('changed', result)
github ethereum / web3.js / packages / web3-shh / src / index.js View on Github external
var _this = this;

    // sets _requestmanager
    core.packageInit(this, arguments);

    // overwrite setProvider
    var setProvider = this.setProvider;
    this.setProvider = function () {
        setProvider.apply(_this, arguments);
        _this.net.setProvider.apply(_this, arguments);
    };

    this.net = new Net(this.currentProvider);

    [
        new Subscriptions({
            name: 'subscribe',
            type: 'shh',
            subscriptions: {
                'messages': {
                    params: 1
                    // inputFormatter: [formatters.inputPostFormatter],
                    // outputFormatter: formatters.outputPostFormatter
                }
            }
        }),

        new Method({
            name: 'getVersion',
            call: 'shh_version',
            params: 0
        }),
github ethereum / web3.js / packages / web3-eth / src / index.js View on Github external
}),
        new Method({
            name: 'getWork',
            call: 'eth_getWork',
            params: 0
        }),
        new Method({
            name: 'getPastLogs',
            call: 'eth_getLogs',
            params: 1,
            inputFormatter: [formatter.inputLogFormatter],
            outputFormatter: formatter.outputLogFormatter
        }),

        // subscriptions
        new Subscriptions({
            name: 'subscribe',
            type: 'eth',
            subscriptions: {
                'newBlockHeaders': {
                    // TODO rename on RPC side?
                    subscriptionName: 'newHeads', // replace subscription with this name
                    params: 0,
                    outputFormatter: formatter.outputBlockFormatter
                },
                'pendingTransactions': {
                    subscriptionName: 'newPendingTransactions', // replace subscription with this name
                    params: 0
                },
                'logs': {
                    params: 1,
                    inputFormatter: [formatter.inputLogFormatter],
github poanetwork / bridge-ui / lib / web3-eth / index.js View on Github external
}),
        new Method({
            name: 'getWork',
            call: 'eth_getWork',
            params: 0
        }),
        new Method({
            name: 'getPastLogs',
            call: 'eth_getLogs',
            params: 1,
            inputFormatter: [formatter.inputLogFormatter],
            outputFormatter: formatter.outputLogFormatter
        }),

        // subscriptions
        new Subscriptions({
            name: 'subscribe',
            type: 'eth',
            subscriptions: {
                'newBlockHeaders': {
                    // TODO rename on RPC side?
                    subscriptionName: 'newHeads', // replace subscription with this name
                    params: 0,
                    outputFormatter: formatter.outputBlockFormatter
                },
                'pendingTransactions': {
                    subscriptionName: 'newPendingTransactions', // replace subscription with this name
                    params: 0
                },
                'logs': {
                    params: 1,
                    inputFormatter: [formatter.inputLogFormatter],
github jpmorganchase / quorum.js / lib / index.js View on Github external
property: 'eth',
    methods: [{
      name: 'getBlock',
      call: blockCall,
      params: 2,
      inputFormatter: [web3.extend.formatters.inputBlockNumberFormatter, function (val) {
        return !!val;
      }],
      outputFormatter: quorumOutputBlockFormatter
    }]
  });

  // Creating a modified 'newBlockHeaders' subscription to replace the output formatter in the case of Quorum
  var Subscriptions = require('web3-core-subscriptions').subscriptions;

  const patchedSub = new Subscriptions({
    name: 'subscribe',
    type: 'eth',
    subscriptions: {
      'newBlockHeaders': {
        subscriptionName: 'newHeads',
        params: 0,
        outputFormatter: quorumOutputBlockFormatter
      }
    }
  });

  let _quorumSubObject = {};
  patchedSub.setRequestManager(web3._requestManager);
  patchedSub.attachToObject(_quorumSubObject);
github poanetwork / tokenbridge / ui / lib / web3-eth / index.js View on Github external
}),
        new Method({
            name: 'getWork',
            call: 'eth_getWork',
            params: 0
        }),
        new Method({
            name: 'getPastLogs',
            call: 'eth_getLogs',
            params: 1,
            inputFormatter: [formatter.inputLogFormatter],
            outputFormatter: formatter.outputLogFormatter
        }),

        // subscriptions
        new Subscriptions({
            name: 'subscribe',
            type: 'eth',
            subscriptions: {
                'newBlockHeaders': {
                    // TODO rename on RPC side?
                    subscriptionName: 'newHeads', // replace subscription with this name
                    params: 0,
                    outputFormatter: formatter.outputBlockFormatter
                },
                'pendingTransactions': {
                    subscriptionName: 'newPendingTransactions', // replace subscription with this name
                    params: 0
                },
                'logs': {
                    params: 1,
                    inputFormatter: [formatter.inputLogFormatter],