Skip to content

Official data streaming Typescript libraries and tools for the Fuel Network.

License

Notifications You must be signed in to change notification settings

FuelLabs/fuel-streams-js

Repository files navigation

Logo

Fuel Streams TypeScript SDK

A TypeScript SDK for working with streams of Fuel blockchain data

CI npm

📚 Documentation   🐛 Report Bug   ✨ Request Feature

📝 About The Project

Warning

This project is currently under development and is not yet ready for production use.

The Fuel Streams TypeScript SDK provides a simple and robust way to interact with a NATS server, enabling seamless integration of pub/sub patterns, message streaming, and typed data structures. This SDK extends the capabilities of NATS by supporting type-safe interactions and convenient utilities for developers.

🚀 Features

  • Typed Pub/Sub: Publish and subscribe to NATS subjects with strong typing support
  • Wildcard Filtering: Consume messages from subjects with wildcards for flexible subscription patterns
  • Stream Management: Efficiently handle streaming data with utilities like BlockStream
  • Ease of Use: Intuitive APIs for initializing clients and managing subjects
  • Type Safety: Full TypeScript support with typed data structures
  • Multiple Stream Types: Support for blocks, transactions, receipts, inputs, outputs, and logs

🛠 Installation

Install the SDK using npm, yarn, or pnpm:

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

📊 Usage

Here are some examples to get you started with the Fuel Streams TypeScript SDK:

Connecting to NATS

import { Client, ClientOpts } from '@fuels/streams';

async function main() {
  const opts = new ClientOpts();
  const client = await Client.connect(opts);
  console.log('Connected to NATS');
}

main().catch(console.error);

Subscribing to Blocks

import { Client, ClientOpts, BlocksSubject, BlockStream } from '@fuels/streams';

async function main() {
  const opts = new ClientOpts();
  const client = await Client.connect(opts);
  const stream = await BlockStream.init(client);
  const subscription = await stream.subscribe(BlocksSubject.all());

  for await (const msg of subscription) {
    console.log(`Received block message: ${msg.key}`);
  }

  await stream.flushAwait();
}

main().catch(console.error);

Filtered Streams

import { BlockStream, BlocksSubject, Client, ClientOpts } from '@fuels/streams';

async function main() {
  const opts = new ClientOpts();
  const client = await Client.connect(opts);
  const stream = await BlockStream.init(client);

  // Create a filtered subject for blocks at height 1000
  const filteredSubject = new BlocksSubject().withHeight(1000);
  const consumer = await stream.subscribeConsumer({
    filterSubjects: [filteredSubject],
  });

  const iter = await consumer.consume({ max_messages: 10 });
  for await (const msg of iter) {
    console.log(`Received filtered block message: ${msg.subject}`);
  }

  await stream.flushAwait();
}

main().catch(console.error);

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For more information on contributing, please see our Contributing Guidelines.

📜 License

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

About

Official data streaming Typescript libraries and tools for the Fuel Network.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •