npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@fuels/streams

v0.9.1

Published

Official data streaming Typescript library for Fuel Network

Readme

📝 About

The @fuels/streams library provides a simple and robust TypeScript SDK for connecting to and consuming real-time data from the Fuel blockchain. It enables developers to subscribe to blockchain events with type-safe interfaces and powerful filtering capabilities.

🚀 Features

  • WebSocket-Based Streaming: Real-time data streaming using WebSocket connections
  • Type-Safe Interfaces: Full TypeScript support with comprehensive type definitions
  • Flexible Filtering: Filter blockchain data by various criteria
  • Multiple Data Types: Support for blocks, transactions, receipts, inputs, outputs, and more
  • Customizable Delivery Policies: Control how you receive data (new events or from a specific block)
  • ABI-Based Decoding: Decode contract events using ABI definitions
  • Error Handling: Comprehensive error handling and reporting

📦 Installation

npm install @fuels/streams
# or
yarn add @fuels/streams
# or
pnpm add @fuels/streams
# or
bun install @fuels/streams

🛠️ Usage

Connecting to the Fuel Network

import { Client, FuelNetwork } from "@fuels/streams";

async function main() {
  // Connect to the Fuel network with your API key
  const connection = await Client.connect(FuelNetwork.Mainnet, "your_api_key");
  console.log("Connected to Fuel Network");
}

main().catch(console.error);

Subscribing to Blocks

import {
  BlocksSubject,
  Client,
  DeliverPolicy,
  FuelNetwork,
} from "@fuels/streams";

async function main() {
  const connection = await Client.connect(FuelNetwork.Mainnet, "your_api_key");

  // Create a subject for all blocks
  const subjects = [BlocksSubject.build()];

  // Subscribe to blocks with new deliver policy
  const stream = await connection.subscribe(subjects, DeliverPolicy.new());

  for await (const message of stream) {
    console.log("Block:", message.payload);
  }
}

main().catch(console.error);

Filtering Transactions

import {
  Client,
  DeliverPolicy,
  FuelNetwork,
  TransactionStatus,
  TransactionType,
  TransactionsSubject,
} from "@fuels/streams";

async function main() {
  const connection = await Client.connect(FuelNetwork.Mainnet, "your_api_key");

  // Create a filtered subject for successful script transactions
  const subjects = [
    TransactionsSubject.build({
      txType: TransactionType.Script,
      status: TransactionStatus.Success,
    }),
  ];

  // Subscribe from a specific block height
  const stream = await connection.subscribe(
    subjects,
    DeliverPolicy.fromBlock(1000000),
  );

  for await (const message of stream) {
    console.log("Transaction:", message.payload);
  }
}

main().catch(console.error);

Decoding Contract Events

import {
  Client,
  DeliverPolicy,
  FuelNetwork,
  ReceiptsLogDataSubject,
} from "@fuels/streams";

// Import your contract ABI
import contractAbi from "./contract_abi.json";

async function main() {
  // Pass the ABI when connecting
  const connection = await Client.connect(FuelNetwork.Mainnet, "your_api_key", {
    abi: contractAbi,
  });

  // Filter log data from a specific contract
  const subjects = [
    ReceiptsLogDataSubject.build({
      contract:
        "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
    }),
  ];

  const stream = await connection.subscribe(subjects, DeliverPolicy.new());

  for await (const message of stream) {
    console.log("Event:", message.payload);
    // The payload will be automatically decoded using the provided ABI
  }
}

main().catch(console.error);

Using Event Handlers

import {
  BlocksSubject,
  Client,
  DeliverPolicy,
  FuelNetwork,
} from "@fuels/streams";

async function main() {
  const connection = await Client.connect(FuelNetwork.Mainnet, "your_api_key");

  const subjects = [BlocksSubject.build()];
  const stream = await connection.subscribe(subjects, DeliverPolicy.new());

  // Use event handlers instead of async iteration
  const unsubscribe = stream.onMessage((message) => {
    console.log("New block:", message.payload);
  });

  // Handle errors
  stream.onMessageError((error) => {
    console.error("Stream error:", error);
  });

  // Later, when you want to stop receiving events
  // unsubscribe();
}

main().catch(console.error);

📊 Available Subjects

The library provides various subject types for different blockchain data:

  • BlocksSubject: Subscribe to blocks
  • TransactionsSubject: Subscribe to transactions
  • InputsSubject: Subscribe to transaction inputs
  • OutputsSubject: Subscribe to transaction outputs
  • ReceiptsSubject: Subscribe to transaction receipts
  • PredicatesSubject: Subscribe to predicate executions
  • UtxosSubject: Subscribe to UTXOs
  • MessagesSubject: Subscribe to messages

Each subject type supports specific filter criteria. For a complete list of available filters, see the Filters List in the main repository README.

🔄 Delivery Policies

Control how you receive data with delivery policies:

  • DeliverPolicy.new(): Receive only new data from the point of subscription
  • DeliverPolicy.fromBlock(blockNumber): Receive data starting from a specific block height

🏗️ Architecture

The library is organized into several key components:

  • Client: Manages WebSocket connections to the Fuel Network
  • Connection: Handles the subscription lifecycle and message processing
  • Subjects: Define what data to subscribe to and how to filter it
  • DeliverPolicy: Controls the starting point for data delivery
  • Parsers: Convert raw blockchain data into typed objects

🤝 Contributing

Contributions are welcome! Please see the Contributing Guide for more information.

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.