Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including ethereum-transaction-stream with all npm packages installed. Try it out:

var ethereumTransactionStream = require("ethereum-transaction-stream")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ethereum-transaction-stream v1.1.0

Relatime Ethereum transactions tracking library

ethereum-transaction-stream

Relatime Ethereum transactions tracking library

Installation

npm install ethereum-transaction-stream

Features

  • Works in Node.js and browsers (incl. websocket fallback)
  • Fetches historical transactions besides realtime tracking
  • Handles transactions tracking for testnet (despite lack of Etherscan support)
  • Possibility to include internal transactions (per tx)
  • Possibility to include ERC20 tokens minting logs (per tx)

Usage

// import EthTS from 'ethereum-transaction-stream/dist/browser';
// import EthTS from 'ethereum-transaction-stream';
// const { EthTS } = window;
const EthTS = require('ethereum-transaction-stream');

(async (EthTS) => {
  const ets = EthTS

      // EthTS.PROVIDERS.Etherscan
      // EthTS.PROVIDERS.EtherscanWS
      // EthTS.PROVIDERS.EtherscanHTTP
      .create(EthTS.PROVIDERS.EtherscanWS)

      // EthTS.EtherscanConfig.MAINNET (default)
      // EthTS.EtherscanConfig.ROPSTEN
      // EthTS.EtherscanConfig.RINKEBY
      .configure('network', EthTS.EtherscanConfig.ROPSTEN)

      // Include internal txs (e.g. proxy value to another address)
      // Default: false
      .configure('includeInternal', true)

      // Include logs (e.g. token minting)
      // Important: this is currently available for EtherscanHTTP only
      // Default: false
      .configure('includeLogs', true);

  // Creates a new stream.
  // Note that "startblock", "endblock", "ERC20TokenAddress" and "mintOnly" options
  // are only available for "EtherscanHTTP" provider. By including "ERC20TokenAddress"
  // there will be included transactions for ERC20 token only and enabling "mintOnly"
  // option will result in leaving only token minting events.
  // Important: "ERC20TokenAddress" and "mintOnly" options are available only when "includeLogs" enabled
  // Important: the result will INCLUDE transactions from the "startblock"
  const stream = await ets.stream(
    '0x4a1eade6b3780b50582344c162a547d04e4e8e4a'
    /*, startblock, endblock, ERC20TokenAddress, mintOnly */
  );

  console.log('in use:', ets.streamInUse); // false

  const txs = [];

  // Subscribes to the stream.
  // There is a "const txs = await stream.waitAll()" method
  // however you should avoid it- it might hang your process (e.g. with ws provider)
  await stream.subscribe((tx) => {
    txs.push(tx);

    console.log('+1');
  });

  console.log('in use:', ets.streamInUse); // true

  // Keep alive the connection for 10 seconds
  await new Promise((resolve) => {
    setTimeout(async () => {
      await stream.close(); // or "await ets.close()" which is an alias
      resolve();
    }, 10000);
  });

  console.log('Transactions received:', txs.length);
})(EthTS);

Enabling includeInternal option might slow down the performance considerably

For more examples check out /example folder.

Testing

npm run test # npm run test:v|vvv for debugging

Roadmap

  • [ ] Add ERC20 tokens transfer fetching
  • [ ] Add custom events processing
  • [ ] Include logs into the native WS provider

Support development

I really love open source, however i do need your help to keep the library up to date. There are several ways to do it: open issues, submit PRs, share the library w/ community or simply-

Donate ETH

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free