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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
230486b30f122bdbecfaf2300555045b1d3bc2c998bee8cc58693c7cd258d733
|
|
| MD5 |
59610f4a5badf7e61d9032c63a88fdcf
|
|
| BLAKE2b-256 |
a7b8134f850e4eb30606d0e84fb17d4b51aa7702ae28166027993d38b4ae5f6c
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db6008a8b2dbb858905a5e19519b5273eb1ce23cbfa4aeb04d3e7a67c678a7f4
|
|
| MD5 |
54609282d9cd10c76cc474de9766ce81
|
|
| BLAKE2b-256 |
3214cfb4caf9fe2b6aba77cbff445a2fc83c24c0e0e5bc9130ad816781ce7207
|