Python RPC client for Evrmore blockchain
Project description
Evrmore RPC Client
A comprehensive Python client for interacting with Evrmore nodes via RPC and ZMQ interfaces. This module provides a clean, type-safe API for all Evrmore RPC commands with proper error handling and validation.
Features
- 🚀 Complete implementation of all Evrmore RPC commands
- 📡 Real-time notifications via ZMQ with type-safe models
- 🔒 Type-safe request and response models using Pydantic
- 🛡️ Comprehensive error handling and logging
- 🧪 Command-line interfaces for testing RPC and ZMQ
- 📝 Extensive documentation and examples
- 🔧 Automatic configuration from evrmore.conf
Installation
pip install evrmore_rpc
Quick Start
RPC Commands
from evrmore_rpc import evrmore_rpc
# Create client (automatically reads evrmore.conf)
client = evrmore_rpc()
# Basic usage
block_count = client.getblockcount()
print(f"Current block height: {block_count}")
# Get asset information
asset_info = client.getassetdata("CREDITS")
print(f"Asset amount: {asset_info.amount}")
# Send EVR
txid = client.sendtoaddress("EXaMPLEaDDreSS123456789", 1.0)
print(f"Transaction sent: {txid}")
# Transfer assets
client.transfer("MYASSET", 100, "EXaMPLEaDDreSS123456789")
ZMQ Notifications
from evrmore_rpc.zmq import EvrmoreZMQ, HashTxNotification, HashBlockNotification
async def handle_notifications(notification):
if isinstance(notification, HashTxNotification):
print(f"New transaction: {notification.txid}")
elif isinstance(notification, HashBlockNotification):
print(f"New block: {notification.blockhash}")
# Create ZMQ client
zmq = EvrmoreZMQ()
# Subscribe to notifications
zmq.subscribe([b"hashtx", b"hashblock"], handle_notifications)
# Start listening
try:
await zmq.start()
except KeyboardInterrupt:
zmq.close()
Configuration
The module automatically reads configuration from your evrmore.conf file. By default, it looks in:
- The directory specified by the
EVRMORE_ROOTenvironment variable - The default location (
~/.evrmore/evrmore.conf)
Required settings in evrmore.conf:
# Core Settings (Required)
server=1
rpcuser=your_username
rpcpassword=your_password
rpcport=8819
# Optional Settings
rpcbind=127.0.0.1 # Default if not specified
# ZMQ Settings (for notifications)
zmqpubhashtx=tcp://127.0.0.1:28332
zmqpubhashblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28332
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubsequence=tcp://127.0.0.1:28332
Command Line Interface
RPC Commands
# Get current block count
evrmore_rpc getblockcount
# Get asset data
evrmore_rpc getassetdata CREDITS
# Get help for specific command
evrmore_rpc help getblock
# List all available commands
evrmore_rpc help
ZMQ Monitor
# Monitor all ZMQ notifications
python3 -m evrmore_rpc.zmq
# Output example:
# [11:38:57] New transaction: 8ec3c9e86a10d04976249081c10661f0351931dbd9a2e6b98af4e10fbb914cd0
# [11:38:57] Raw transaction: 205 bytes
# [11:39:00] New block: 00000000003e584551ef457c1e194a0e60f86156b12d76b43bbd56d4db1111c4
Security Considerations
RPC Security
- Always use strong, unique credentials for
rpcuserandrpcpassword - Restrict RPC access:
# Only allow local connections (recommended) rpcbind=127.0.0.1 rpcallowip=127.0.0.1 # If remote access is needed, use IP restrictions rpcallowip=192.168.1.0/24 # Allow specific network
- Use a firewall to restrict access to RPC port
- Consider using SSL/TLS for RPC connections (requires reverse proxy)
ZMQ Security
- ZMQ endpoints should only bind to localhost unless remote access is needed
- Use proper network segmentation if remote ZMQ access is required
- Monitor ZMQ connections for unexpected behavior
- Consider implementing message authentication if using over untrusted networks
Production Deployment
-
Environment:
- Use dedicated service accounts
- Implement proper file permissions
- Use systemd or similar for process management
-
Monitoring:
- Monitor RPC and ZMQ connection attempts
- Set up logging for authentication failures
- Monitor system resource usage
-
Backup and Recovery:
- Regularly backup configuration
- Document recovery procedures
- Test failover scenarios
-
Updates:
- Keep Evrmore node updated
- Monitor security advisories
- Update dependencies regularly
Error Handling
The module provides specific error classes for different types of failures:
from evrmore_rpc import evrmore_rpc, NodeConnectionError, NodeAuthError, EvrmoreError
client = evrmore_rpc()
try:
result = client.getassetdata("NONEXISTENT")
except NodeConnectionError as e:
print(f"Connection failed: {e}")
except NodeAuthError as e:
print(f"Authentication failed: {e}")
except EvrmoreError as e:
print(f"Evrmore error {e.code}: {e}")
Integration Examples
Blockchain Explorer Backend
from evrmore_rpc import evrmore_rpc
from evrmore_rpc.zmq import EvrmoreZMQ, HashTxNotification, HashBlockNotification
class ExplorerBackend:
def __init__(self):
self.rpc = evrmore_rpc()
self.zmq = EvrmoreZMQ()
self.zmq.subscribe([b"hashtx", b"hashblock"], self.handle_notifications)
async def handle_notifications(self, notification):
if isinstance(notification, HashTxNotification):
tx = self.rpc.getrawtransaction(notification.txid, True)
await self.update_transaction(tx)
elif isinstance(notification, HashBlockNotification):
block = self.rpc.getblock(notification.blockhash)
await self.update_block(block)
async def start(self):
await self.zmq.start()
Wallet Address Monitor
from evrmore_rpc.zmq import EvrmoreZMQ, RawTxNotification
class AddressMonitor:
def __init__(self, addresses: List[str]):
self.addresses = addresses
self.zmq = EvrmoreZMQ()
self.zmq.subscribe([b"rawtx"], self.check_transaction)
async def check_transaction(self, notification):
if isinstance(notification, RawTxNotification):
# Decode transaction and check if it involves our addresses
if any(addr in notification.txhex for addr in self.addresses):
await self.process_relevant_transaction(notification)
async def start(self):
await self.zmq.start()
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 evrmore_rpc-1.0.2.tar.gz.
File metadata
- Download URL: evrmore_rpc-1.0.2.tar.gz
- Upload date:
- Size: 37.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60ee25d15449ceff2f4213bc018792cf4f63891a67030e8baad9cde24901de9e
|
|
| MD5 |
a564e6acae4df1ef3e8e6aaf23419d51
|
|
| BLAKE2b-256 |
4c0af5677b2e27ba7e6a0eda5813b10a5185cb07090d90e2102338f13ccd4202
|
File details
Details for the file evrmore_rpc-1.0.2-py3-none-any.whl.
File metadata
- Download URL: evrmore_rpc-1.0.2-py3-none-any.whl
- Upload date:
- Size: 52.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9912ad780683abaa24d62dfa1bc1a820610832911c49833dc0e0895fe6f17687
|
|
| MD5 |
b14c74bbbac0381ddf73e4bf5a746e4c
|
|
| BLAKE2b-256 |
918352520d125d73465dc29a8beed06f8d00718aebcbb8d096d8184eaa290916
|