How to use web3-core-promievent - 3 common examples

To help you get started, we’ve selected a few web3-core-promievent 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 ninabreznik / voting-ethereum-contract / node_modules / web3-core-method / src / index.js View on Github external
var checkConfirmation = function (existingReceipt, isPolling, err, blockHeader, sub) {
        if (!err) {
            // create fake unsubscribe
            if (!sub) {
                sub = {
                    unsubscribe: function () {
                        clearInterval(intervalId);
                    }
                };
            }
            // if we have a valid receipt we don't need to send a request
            return (existingReceipt ? promiEvent.resolve(existingReceipt) : _ethereumCall.getTransactionReceipt(result))
            // catch error from requesting receipt
            .catch(function (err) {
                sub.unsubscribe();
                promiseResolved = true;
                utils._fireError({message: 'Failed to check for transaction receipt:', data: err}, defer.eventEmitter, defer.reject);
            })
            // if CONFIRMATION listener exists check for confirmations, by setting canUnsubscribe = false
            .then(function(receipt) {
                if (!receipt || !receipt.blockHash) {
                    throw new Error('Receipt missing or blockHash null');
                }

                // apply extra formatters
                if (method.extraFormatters && method.extraFormatters.receiptFormatter) {
                    receipt = method.extraFormatters.receiptFormatter(receipt);
                }
github JoinColony / tailor / src / adapters / Web3Adapter / index.js View on Github external
sendSignedTransaction(transaction: SignedTransaction) {
    const promiEvent = new PromiEvent();
    const txPromiEvent = this._web3.eth.sendSignedTransaction(transaction);

    txPromiEvent.on('transactionHash', hash =>
      promiEvent.eventEmitter.emit('transactionHash', hash),
    );
    txPromiEvent.on('receipt', receipt => {
      try {
        const decoded = this._decodeReceipt(receipt);
        promiEvent.eventEmitter.emit('receipt', decoded);
      } catch (error) {
        promiEvent.eventEmitter.emit('error', error);
        promiEvent.eventEmitter.emit('receipt', receipt);
      }
    });
    txPromiEvent.on('confirmation', (confirmationNumber, receipt) => {
      try {
github trufflesuite / truffle / packages / contract / lib / promievent.js View on Github external
function PromiEvent() {
  const { resolve, reject, eventEmitter } = Web3PromiEvent.apply(
    null,
    arguments
  );

  const originalStackTrace = new Error().stack;

  function rejectHijacker(e) {
    try {
      const stackTrace = originalStackTrace.replace(
        /^Error: \n/,
        e.stack.split("\n")[0]
      );

      e.hijackedStack = e.stack;
      e.stack = stackTrace;
    } catch (_) {

web3-core-promievent

This package extends the EventEmitter with the Promise class to allow chaining as well as multiple final states of a function.

LGPL-3.0
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis

Similar packages