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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for chain_sniper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bf6c61d34e042babd8a09438c27e198eb15603ae4ea6f1e4cf473d00de08253e
MD5 3854a2c2b84c27dcd5241c1db921ce1d
BLAKE2b-256 175fbe06528e3ed5e040243a4952bbb50a960f472db88ef1b8d5688fffd08d3f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chain_sniper-0.1.2-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.20

File hashes

Hashes for chain_sniper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 862c2696bd974099366269a89aeb0699d8f01327fd362a7c92d1e83381866d18
MD5 06417703723b6227b3c99547a43fda12
BLAKE2b-256 5dd7a53a57ea5898d0477db0fed9f6a0f5f04c007c49483ddb980c5a25d0c503

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