Skip to main content

A high-performance EVM blockchain listener and transaction monitor

Project description

Chain Sniper

A high-performance EVM blockchain listener and transaction monitor.

Install

git clone https://github.com/rakibhossain72/chain-sniper.git
cd chain-sniper
uv sync

Or with pip:

pip install chain-sniper

Quick Start

from chain_sniper import ChainSniper

ERC20_ABI = [...]  # Transfer event ABI
USDT = "0x55d398326f99059fF775485246999027B3197955"

sniper = ChainSniper("wss://bsc-ws-node.nariox.org:443")

@sniper.event(contract=USDT, abi=ERC20_ABI, name="Transfer")
async def handle_transfer(event):
    print(f"Transfer: {event['args']['value'] / 10**18} USDT")

await sniper.start()

Use a WebSocket URL (wss:// or ws://) — that's the only supported transport.

RPC Pool (fault-tolerant)

from chain_sniper.rpc_pool import RPCPool

pool = await RPCPool.create(
    rpcs=[
        "https://bsc-dataseed1.binance.org",
        "wss://bsc-ws-node.nariox.org:443",
    ],
    expected_chain_id=56,
)
sniper = ChainSniper(pool)

Transaction Monitoring

sniper.block_detail("full_block")

@sniper.on_transaction
async def handle_tx(tx):
    print(f"{tx['hash']} | {tx['from']} -> {tx['to']}")

Filtering

MongoDB-style rules with operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $regex, $exists.

from chain_sniper import Filter

f = Filter()
f.add_tx_rule({"value": {"_op": "$gte", "_value": 10**18}})
f.add_log_rule({"args.value": {"_op": "$gte", "_value": 1000 * 10**18}})

sniper.filter(f)

Dynamic Rules via Redis

Inject or remove filter rules at runtime without restarting:

from chain_sniper.listener import RedisRuleListener

redis_listener = RedisRuleListener(
    dynamic_filter=f,
    redis_url="redis://localhost",
    channel="sniper_rules",
)
await redis_listener.start()

Push rules from anywhere:

import redis, json

r = redis.Redis(host="localhost", port=6379, decode_responses=True)
r.publish("sniper_rules", json.dumps({"action": "add_tx", "rule": {"to": "0x..."}}))

Key API

Method Description
@sniper.event(contract, abi, name) Register an event handler
@sniper.on_transaction Handle individual transactions
@sniper.on_block Handle new blocks
@sniper.on_reorg Handle chain reorgs
sniper.filter(f) Attach a Filter
sniper.block_detail("header" | "full_block") Set block detail level
sniper.start() / .stop() Start or stop monitoring

See examples/ for complete usage patterns.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chain_sniper-0.1.0.tar.gz (174.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chain_sniper-0.1.0-py3-none-any.whl (43.4 kB view details)

Uploaded Python 3

File details

Details for the file chain_sniper-0.1.0.tar.gz.

File metadata

  • Download URL: chain_sniper-0.1.0.tar.gz
  • Upload date:
  • Size: 174.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for chain_sniper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 230486b30f122bdbecfaf2300555045b1d3bc2c998bee8cc58693c7cd258d733
MD5 59610f4a5badf7e61d9032c63a88fdcf
BLAKE2b-256 a7b8134f850e4eb30606d0e84fb17d4b51aa7702ae28166027993d38b4ae5f6c

See more details on using hashes here.

File details

Details for the file chain_sniper-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: chain_sniper-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for chain_sniper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db6008a8b2dbb858905a5e19519b5273eb1ce23cbfa4aeb04d3e7a67c678a7f4
MD5 54609282d9cd10c76cc474de9766ce81
BLAKE2b-256 3214cfb4caf9fe2b6aba77cbff445a2fc83c24c0e0e5bc9130ad816781ce7207

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page