Professional async crypto payment monitoring library for Python
Project description
CryptoScan ๐
Professional Async Crypto Payment Monitoring Library for Python
CryptoScan is a fast, reliable, and extensible Python library for monitoring cryptocurrency payments across multiple blockchain networks. Built with async/await support, HTTP/2 integration, and enterprise-grade reliability.
โจ Features
- ๐ Multi-Network Support: Bitcoin, Ethereum, Solana, TON, USDT Tron (TRC-20)
- โก Async/Await: Built for high-performance async applications
- ๐ HTTP/2 Ready: Optimized API calls with HTTP/2 support
- ๐ Proxy Support: Full proxy configuration for all providers
- ๐ฏ Exact Matching: Precise payment amount detection
- ๐ Auto-Stop: Automatic monitoring termination after payment detection
- ๐ Real-time Events: Payment callbacks and event handling
- ๐ก๏ธ Enterprise Ready: Robust error handling and retry mechanisms
๐ Quick Start
Installation
pip install cryptoscan
Basic Usage
import asyncio
from cryptoscan import create_monitor
async def main():
# Create a payment monitor
monitor = create_monitor(
network="bitcoin",
wallet_address="3DVSCqZdrNJHyu9Le7Sepdh1KgQTNR8reG",
expected_amount="0.00611813",
auto_stop=True
)
# Set up payment handler
@monitor.on_payment
async def handle_payment(event):
payment = event.payment_info
print(f"๐ฐ Payment received: {payment.amount} {payment.currency}")
print(f"๐ Transaction: {payment.transaction_id}")
print(f"๐ค From: {payment.from_address}")
# Start monitoring
await monitor.start()
if __name__ == "__main__":
asyncio.run(main())
๐ Supported Networks
| Network | Symbol | Factory Names | Status |
|---|---|---|---|
| Bitcoin | BTC | bitcoin, btc |
โ Ready |
| Ethereum | ETH | ethereum, eth |
โ Ready |
| Solana | SOL | solana, sol |
โ Ready |
| TON | TON | ton |
โ Ready |
| USDT Tether (TRC-20) | USDT | usdt_tron, usdt, trc20 |
โ Ready |
๐ Examples
Basic Payment Monitoring
import asyncio
from decimal import Decimal
from cryptoscan import create_monitor
async def bitcoin_example():
monitor = create_monitor(
network="bitcoin", # or "btc"
wallet_address="3DVSCqZdrNJHyu9Le7Sepdh1KgQTNR8reG",
expected_amount=Decimal("0.00611813"),
poll_interval=30.0,
auto_stop=True
)
@monitor.on_payment
async def on_payment(event):
payment = event.payment_info
print(f"๏ฟฝ Payment received: {payment.amount} {payment.currency}")
print(f" Transaction: {payment.transaction_id}")
print(f" From: {payment.from_address}")
await monitor.start()
asyncio.run(bitcoin_example())
Multi-Network Monitoring
import asyncio
from cryptoscan import create_monitor
async def multi_network_example():
# Monitor multiple networks simultaneously
btc_monitor = create_monitor(
network="bitcoin",
wallet_address="3DVSCqZdrNJHyu9Le7Sepdh1KgQTNR8reG",
expected_amount="0.00611813"
)
usdt_monitor = create_monitor(
network="usdt_tron",
wallet_address="TVRzaRqX9soeRpcJVT6zCAZjGtLtQXacCR",
expected_amount="200.0"
)
# Unified payment handler
async def handle_payment(event):
payment = event.payment_info
print(f"๏ฟฝ {payment.currency} payment: {payment.amount}")
btc_monitor.on_payment(handle_payment)
usdt_monitor.on_payment(handle_payment)
# Start all monitors
await asyncio.gather(
btc_monitor.start(),
usdt_monitor.start()
)
asyncio.run(multi_network_example())
๐ง Advanced Configuration
User Configuration (Recommended)
from cryptoscan import create_monitor, create_user_config, ProxyConfig
# Create user configuration with proxy and custom settings
user_config = create_user_config(
proxy_url="https://proxy.example.com:8080",
proxy_auth="username:password",
timeout=60,
max_retries=5,
ssl_verify=True
)
monitor = create_monitor(
network="ethereum",
wallet_address="0x...",
expected_amount="1.0",
user_config=user_config
)
Direct UserConfig Creation
from cryptoscan import create_monitor, UserConfig, ProxyConfig
# Create proxy configuration
proxy_config = ProxyConfig(
https_proxy="https://proxy.example.com:8080",
proxy_auth="username:password",
proxy_headers={"Custom-Header": "value"}
)
# Create user configuration
user_config = UserConfig(
proxy_config=proxy_config,
timeout=60,
max_retries=5,
retry_delay=2.0,
ssl_verify=True,
connector_limit=50
)
monitor = create_monitor(
network="solana",
wallet_address="39eda9Jzabcr1HPkmjt7sZPCznZqngkfXZn1utwE8uwk",
expected_amount="0.000542353",
user_config=user_config
)
Multiple Payment Monitoring
import asyncio
from cryptoscan import create_monitor
async def multi_network_monitoring():
# Monitor multiple networks simultaneously
monitors = []
# Bitcoin monitor
btc_monitor = create_monitor(
network="bitcoin",
wallet_address="3DVSCqZdrNJHyu9Le7Sepdh1KgQTNR8reG",
expected_amount="0.001",
monitor_id="btc-payment-1"
)
# Ethereum monitor
eth_monitor = create_monitor(
network="ethereum",
wallet_address="0xD45F36545b373585a2213427C12AD9af2bEFCE18",
expected_amount="0.15",
monitor_id="eth-payment-1"
)
# Unified payment handler
async def handle_any_payment(event):
payment = event.payment_info
monitor_id = event.monitor_id
print(f"๐ฐ Payment on {monitor_id}: {payment.amount} {payment.currency}")
btc_monitor.on_payment(handle_any_payment)
eth_monitor.on_payment(handle_any_payment)
# Start all monitors
await asyncio.gather(
btc_monitor.start(),
eth_monitor.start()
)
asyncio.run(multi_network_monitoring())
๐ก๏ธ Error Handling & Reliability
Robust Error Handling
import asyncio
from cryptoscan import create_monitor, NetworkError, PaymentNotFoundError
async def reliable_monitoring():
monitor = create_monitor(
network="bitcoin",
wallet_address="3DVSCqZdrNJHyu9Le7Sepdh1KgQTNR8reG",
expected_amount="0.001",
max_transactions=20, # Check more transactions
poll_interval=30.0
)
@monitor.on_payment
async def on_payment(event):
print(f"โ
Payment confirmed: {event.payment_info.amount} BTC")
@monitor.on_error
async def on_error(event):
error = event.error
if isinstance(error, NetworkError):
print(f"๐ Network error: {error.message}")
print("๐ Will retry automatically...")
else:
print(f"โ Unexpected error: {error}")
try:
await monitor.start()
except Exception as e:
print(f"๐ฅ Monitor failed: {e}")
finally:
await monitor.stop()
asyncio.run(reliable_monitoring())
Timeout and Retry Configuration
from cryptoscan import create_monitor
# High-reliability configuration
monitor = create_monitor(
network="ethereum",
wallet_address="0x...",
expected_amount="1.0",
poll_interval=15.0,
timeout=60, # 60 second timeout
max_retries=5, # Retry failed requests 5 times
auto_stop=True
)
๐ Integration Examples
Aiogram v3.x (Telegram Bot) Integration
from aiogram import Bot, Dispatcher
from aiogram.types import Message
from aiogram.filters import Command
from cryptoscan import create_monitor
import asyncio
import logging
# Configure logging
logging.basicConfig(level=logging.INFO)
# Initialize bot and dispatcher
bot = Bot(token="YOUR_BOT_TOKEN")
dp = Dispatcher()
@dp.message(Command("start"))
async def start_handler(message: Message):
await message.answer(
"๐ CryptoScan Bot\n\n"
"Monitor crypto payments with ease!\n"
"Usage: /monitor <network> <address> <amount>\n\n"
"Supported networks: bitcoin, ethereum, solana, usdt_tron, ton"
)
@dp.message(Command("monitor"))
async def monitor_payment(message: Message):
# Parse command: /monitor bitcoin 3DVSCqZdrNJHyu9Le7Sepdh1KgQTNR8reG 0.001
args = message.text.split()[1:]
if len(args) != 3:
await message.answer(
"โ Invalid format!\n"
"Usage: /monitor <network> <address> <amount>\n\n"
"Example: /monitor bitcoin 3DVSCqZdrNJHyu9Le7Sepdh1KgQTNR8reG 0.001"
)
return
network, address, amount = args
try:
monitor = create_monitor(
network=network,
wallet_address=address,
expected_amount=amount,
auto_stop=True
)
@monitor.on_payment
async def on_payment(event):
payment = event.payment_info
await message.answer(
f"โ
Payment Received!\n\n"
f"๐ฐ Amount: {payment.amount} {payment.currency}\n"
f"๐ Transaction: {payment.transaction_id[:16]}...\n"
f"๐ค From: {payment.from_address[:16]}...\n"
f"โฐ Time: {payment.timestamp}"
)
@monitor.on_error
async def on_error(event):
await message.answer(f"โ Monitoring error: {event.error}")
await message.answer(
f"๐ Monitoring started!\n\n"
f"Network: {network.upper()}\n"
f"Amount: {amount}\n"
f"Address: {address[:16]}...\n\n"
f"I'll notify you when payment is received!"
)
# Start monitoring in background
asyncio.create_task(monitor.start())
except Exception as e:
await message.answer(f"โ Error: {str(e)}")
async def main():
# Start polling
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
๐ API Reference
Core Functions
create_monitor()
Creates a payment monitor for any supported network.
def create_monitor(
network: str, # Network name: "bitcoin", "ethereum", etc.
wallet_address: str, # Wallet address to monitor
expected_amount: str | Decimal, # Expected payment amount (exact match)
poll_interval: float = 15.0, # Seconds between checks
max_transactions: int = 10, # Max transactions to check per poll
auto_stop: bool = False, # Stop after finding payment
rpc_url: str = None, # Custom RPC URL
**kwargs # Additional configuration
) -> PaymentMonitor
PaymentMonitor Class
Methods
async start()- Start monitoring for paymentsasync stop()- Stop monitoringon_payment(callback)- Register payment event handleron_error(callback)- Register error event handler
Properties
provider- Access to the underlying network provideris_running- Check if monitor is currently runningmonitor_id- Unique identifier for this monitor
PaymentInfo Class
Payment information returned when a payment is detected.
@dataclass
class PaymentInfo:
transaction_id: str # Transaction hash/ID
wallet_address: str # Receiving wallet address
amount: Decimal # Payment amount in main units
currency: str # Currency symbol (BTC, ETH, etc.)
status: PaymentStatus # PENDING, CONFIRMED, FAILED
timestamp: datetime # Transaction timestamp
block_height: int # Block number (if available)
confirmations: int # Number of confirmations
fee: Decimal # Transaction fee (if available)
from_address: str # Sender address
to_address: str # Receiver address
raw_data: dict # Raw API response data
Network Providers
Direct access to network providers for advanced use cases.
from cryptoscan import BitcoinProvider, EthereumProvider, SolanaProvider
# Create provider directly
provider = BitcoinProvider()
# Validate address
is_valid = await provider.validate_wallet_address("3DVSCqZdrNJHyu9Le7Sepdh1KgQTNR8reG")
# Get recent transactions
transactions = await provider.get_recent_transactions("3DVSCqZdrNJHyu9Le7Sepdh1KgQTNR8reG", limit=10)
# Get specific transaction
tx_details = await provider.get_transaction_details("0fc6173f52a52d1c4701264db0dccb3dbe413a0716a3cd2805fed79990573ea3")
๐ง Configuration
Environment Variables
# Optional: Override default RPC URLs
export CRYPTOSCAN_BITCOIN_RPC_URL="https://your-bitcoin-node.com"
export CRYPTOSCAN_ETHEREUM_RPC_URL="https://your-ethereum-node.com"
export CRYPTOSCAN_SOLANA_RPC_URL="https://your-solana-node.com"
# Optional: Set default polling interval
export CRYPTOSCAN_POLL_INTERVAL="30.0"
Proxy Configuration
from cryptoscan import create_monitor, create_user_config
# Simple proxy configuration
monitor = create_monitor(
network="ethereum",
wallet_address="0x...",
expected_amount="1.0",
user_config=create_user_config(
proxy_url="https://proxy.example.com:8080",
proxy_auth="username:password",
timeout=60,
max_retries=5
)
)
# Advanced proxy configuration
from cryptoscan import UserConfig, ProxyConfig
proxy_config = ProxyConfig(
https_proxy="https://proxy.example.com:8080",
http_proxy="http://proxy.example.com:8080",
proxy_auth="username:password",
proxy_headers={"Custom-Header": "value"}
)
user_config = UserConfig(
proxy_config=proxy_config,
timeout=60,
max_retries=5
)
monitor = create_monitor(
network="solana",
wallet_address="39eda9Jzabcr1HPkmjt7sZPCznZqngkfXZn1utwE8uwk",
expected_amount="0.1",
user_config=user_config
)
๐ Performance Tips
- Use HTTP/2: All providers support HTTP/2 for better performance
- Optimize Poll Intervals: Balance between responsiveness and API rate limits
- Proxy Rotation: Use proxy rotation for high-volume applications
- Connection Pooling: Providers automatically manage connection pools
- Async Best Practices: Use
asyncio.gather()for concurrent monitoring
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Made with โค๏ธ for the crypto community
CryptoScan - Making crypto payment monitoring simple, fast, and reliable.
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 pycryptoscan-1.0.0.tar.gz.
File metadata
- Download URL: pycryptoscan-1.0.0.tar.gz
- Upload date:
- Size: 33.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69a5e7dde631724c9cacc10509d8a71e8e6ea86b8ed0562d579bf78ccb79adc3
|
|
| MD5 |
7bdfff61bfa156be7e58499dd77b0014
|
|
| BLAKE2b-256 |
47c08cbdab31f5a480ebc06fb751cf3b64b2341176a96acdff318e8d3eebf5c5
|
File details
Details for the file pycryptoscan-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pycryptoscan-1.0.0-py3-none-any.whl
- Upload date:
- Size: 38.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffdf06a51f4dcb218f4d116ff5672c51ec5e514db29fabebf2d84a8c201ad3a5
|
|
| MD5 |
de3e51fe0292739e36af12eb80609af6
|
|
| BLAKE2b-256 |
96c4ea6c21bd3d62f74c5f09eab755225640e50987750b9884eb728b4f9e256a
|