Skip to main content

A high-performance Python wrapper for Evrmore blockchain RPC commands with a seamless API

Project description

evrmore-rpc: Python Client for Evrmore Blockchain

PyPI version License: MIT Python Versions

A comprehensive Python client for interacting with Evrmore blockchain nodes through JSON-RPC and ZMQ interfaces, with features optimized for efficient blockchain application development.

Features

  • Seamless Execution Context: Works identically in both synchronous and asynchronous contexts
  • Auto-Detection: Automatically detects execution context (sync/async) and adapts accordingly
  • Type Safety: Comprehensive type hints and structured data models
  • Performance: Optimized connection handling with connection pooling
  • Complete Coverage: Support for all Evrmore RPC commands
  • Asset Support: Special handling for Evrmore asset operations
  • ZMQ Integration: Real-time blockchain notifications via ZMQ
  • Auto-Decoding: Enhanced ZMQ topics with automatic transaction and block decoding
  • Asset Detection: Automatic detection and detailed information for asset transactions
  • Flexible Configuration: Configure via parameters, environment variables, or evrmore.conf

Installation

# Basic installation
pip install evrmore-rpc

# With ZMQ support
pip install evrmore-rpc[zmq]

Quick Start

from evrmore_rpc import EvrmoreClient

# Create a client (auto-configures from evrmore.conf)
client = EvrmoreClient()

# Get blockchain info
info = client.getblockchaininfo()
print(f"Current block height: {info['blocks']}")
print(f"Current difficulty: {info['difficulty']}")

# Get a specific block
block_hash = client.getblockhash(1)
block = client.getblock(block_hash)
print(f"Block #1 hash: {block['hash']}")
print(f"Block #1 time: {block['time']}")

# Get wallet balance
balance = client.getbalance()
print(f"Wallet balance: {balance} EVR")

Asynchronous Usage

The same client works seamlessly in asynchronous contexts:

import asyncio
from evrmore_rpc import EvrmoreClient

async def main():
    # Create a client
    client = EvrmoreClient()

    # Use with await
    info = await client.getblockchaininfo()
    print(f"Current block height: {info['blocks']}")
    
    # When done
    await client.close()

asyncio.run(main())

Client Configuration

The client can be configured in several ways:

# Explicit configuration
client = EvrmoreClient(
    url="http://localhost:8819",
    rpcuser="username",
    rpcpassword="password"
)

# From environment variables
# Set EVR_RPC_USER, EVR_RPC_PASSWORD, EVR_RPC_HOST, EVR_RPC_PORT
client = EvrmoreClient()

# From evrmore.conf
client = EvrmoreClient(datadir="/path/to/evrmore/data/dir")

# Testnet configuration
client = EvrmoreClient(testnet=True)

Authentication Methods

The client supports multiple authentication methods:

Configuration File

The most common method is to specify credentials in evrmore.conf:

rpcuser=username
rpcpassword=password

Cookie Authentication

If RPC credentials are not set in evrmore.conf, the client will automatically look for the .cookie file in the Evrmore data directory. This is useful when running Evrmore with the -server flag but without explicit RPC credentials.

The .cookie file contains authentication information in the format __cookie__:HASH. The client will use this to authenticate with the RPC server.

# This will work even without rpcuser/rpcpassword in evrmore.conf
# as long as the .cookie file exists in the data directory
client = EvrmoreClient()

Direct Specification

You can also provide credentials directly when creating the client:

client = EvrmoreClient(rpcuser="username", rpcpassword="password")

Working with Assets

Evrmore's unique asset functionality is fully supported:

# List all assets
assets = client.listassets()

# Get asset data
asset_info = client.getassetdata("ASSET_NAME")
print(f"Asset supply: {asset_info['amount']}")
print(f"Reissuable: {asset_info['reissuable']}")

# Transfer an asset
tx_id = client.transfer(
    asset_name="ASSET_NAME",
    qty=10.0,
    to_address="EVRAddress"
)

ZMQ Notifications

Real-time blockchain monitoring with ZMQ:

from evrmore_rpc import EvrmoreClient
from evrmore_rpc.zmq import EvrmoreZMQClient, ZMQTopic

# Create RPC client for decoding
rpc = EvrmoreClient()

# Create ZMQ client
zmq = EvrmoreZMQClient(
    zmq_host="127.0.0.1", 
    zmq_port=28332,
    rpc_client=rpc
)

# Register handlers with decorators
@zmq.on(ZMQTopic.HASH_BLOCK)
def on_block(notification):
    print(f"New block: {notification.hex}")
    
@zmq.on(ZMQTopic.HASH_TX)
def on_tx(notification):
    print(f"New transaction: {notification.hex}")

# Register for enhanced topics with auto-decoding
@zmq.on(ZMQTopic.BLOCK)
def on_decoded_block(notification):
    print(f"Block at height {notification.height} with {notification._tx_count} transactions")

@zmq.on(ZMQTopic.TX)
def on_decoded_tx(notification):
    print(f"Transaction with {notification._vin_count} inputs and {notification._vout_count} outputs")
    if notification.has_assets:
        print(f"Contains asset operations: {notification.asset_info}")

# Start the client
zmq.start()

Asset Transaction Detection

Automatic detection of asset transactions:

from evrmore_rpc import EvrmoreClient
from evrmore_rpc.zmq import EvrmoreZMQClient, ZMQTopic

# Create clients
rpc = EvrmoreClient()
zmq = EvrmoreZMQClient(rpc_client=rpc, topics=[ZMQTopic.TX])

# Register for asset transactions
@zmq.on(ZMQTopic.TX)
def on_transaction(notification):
    if notification.has_assets:
        print(f"Asset transaction detected: {notification.hex}")
        
        for asset_info in notification.asset_info:
            print(f"Asset: {asset_info['asset_name']}")
            print(f"Type: {asset_info['type']}")
            print(f"Amount: {asset_info['amount']}")
            print(f"Address: {asset_info['address']}")
            
            # Access enhanced asset information
            if 'asset_details' in asset_info:
                details = asset_info['asset_details'] 
                print(f"Total supply: {details['amount']}")

# Start the client
zmq.start()

Handling Connection Management

For efficient resource usage, you should close connections when done:

# Synchronous cleanup
client.close_sync()

# Asynchronous cleanup
await client.close()

Advanced Usage

For more advanced usage, please refer to the examples directory and API documentation.

Requirements

  • Python 3.8+
  • Evrmore node (with RPC and optionally ZMQ enabled)

License

MIT License - See LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

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

evrmore_rpc-3.2.4.tar.gz (46.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

evrmore_rpc-3.2.4-py3-none-any.whl (49.5 kB view details)

Uploaded Python 3

File details

Details for the file evrmore_rpc-3.2.4.tar.gz.

File metadata

  • Download URL: evrmore_rpc-3.2.4.tar.gz
  • Upload date:
  • Size: 46.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for evrmore_rpc-3.2.4.tar.gz
Algorithm Hash digest
SHA256 54f0595622009650f69483ebbae1a6df9a94302daf599038db0e760cf31dea24
MD5 e3081ed3a7cf032e645879bba0a1712d
BLAKE2b-256 a9671c455e675d6c1d75eb7443f4a0a0b3ada76909c5fc7f1ac2eba20104b257

See more details on using hashes here.

File details

Details for the file evrmore_rpc-3.2.4-py3-none-any.whl.

File metadata

  • Download URL: evrmore_rpc-3.2.4-py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for evrmore_rpc-3.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 093a06b5be7fe2f110e411c5512b991569365f2da8ac4cf3b1ebd42ea57b857f
MD5 58c31dec52d86cbab750a10a3ff4e46f
BLAKE2b-256 a4bc2d1082a825619f24f307a9a5dc2f83385c507b69fa2e47910116ceec3db4

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