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.1.tar.gz (180.0 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.1-py3-none-any.whl (43.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chain_sniper-0.1.1.tar.gz
  • Upload date:
  • Size: 180.0 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.1.tar.gz
Algorithm Hash digest
SHA256 06ae1637a984605ebe08962975586731cb028001d836e0b990a33ff798d47f33
MD5 189c3261894875a48c34b7abd8d9f1ef
BLAKE2b-256 123bf65a8663ad734b29945456c70c85fa0ccf3ab178b50406e399537c4c8c51

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chain_sniper-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 72f7bef990ff365e978961eb5bd71bdc4f544c9fa75bd1667d80ed2e38e156cc
MD5 bade6a501d81f7c7a85d0ff43937e77d
BLAKE2b-256 8f625bf38cdac0dfe0168b388fbf9b9f420ff3a1abb4693e91b61b81924ea861

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