Ethereum Bloom Filters Client

1.2.0 · active · verified Tue Apr 21

ethereum-bloom-filters is a JavaScript/TypeScript library designed to efficiently test Ethereum bloom filters for set membership, currently at version 1.2.0. It provides a lightweight client for probabilistic checks, allowing developers to quickly ascertain if a particular address, topic, or other data might be present within a block's logBlooms without requiring a full node query. The package has a minimal dependency footprint, relying solely on `@noble/hashes` for its cryptographic hashing primitives, which is notably funded by the Ethereum Foundation. This approach helps reduce the computational overhead associated with monitoring on-chain events, such as updating user balances, by minimizing unnecessary database queries. While no explicit release cadence is documented, its active maintenance is implied by npm activity and recent versioning. A key differentiator is its focus on standalone bloom filter testing, offering a direct utility for common Ethereum development patterns.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the core bloom filter testing functions (`isUserEthereumAddressInBloom`, `isTopicInBloom`, `isInBloom`) to check for the probabilistic presence of addresses, topics, or generic values within a given Ethereum bloom filter string.

import { isUserEthereumAddressInBloom, isTopicInBloom, isInBloom } from 'ethereum-bloom-filters';

// Example Ethereum block bloom (a 256-byte hex string, actual bloom from a real block would be much longer)
const blockBloom = '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
// A fake Ethereum address (20 bytes)
const userAddress = '0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B'; 
// A fake topic (32 bytes)
const eventTopic = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';

const isAddressLikelyPresent = isUserEthereumAddressInBloom(blockBloom, userAddress);
const isTopicLikelyPresent = isTopicInBloom(blockBloom, eventTopic);
const isGenericValueLikelyPresent = isInBloom(blockBloom, 'some_arbitrary_value');

console.log(`Is address ${userAddress} likely in bloom? ${isAddressLikelyPresent}`); // Should be false with an empty bloom
console.log(`Is topic ${eventTopic} likely in bloom? ${isTopicLikelyPresent}`);   // Should be false with an empty bloom
console.log(`Is generic value likely in bloom? ${isGenericValueLikelyPresent}`); // Should be false with an empty bloom

// Note: Bloom filters are probabilistic. A 'true' result means it *might* be present (false positive possible).
// A 'false' result means it is *definitely not* present (no false negatives).

view raw JSON →