Skip to main content

A Python library for interacting with the Denaro cyptocurrency

Project description

Denaro Python Client Module Documentation

This module is a lightweight Python client for interacting with a Denaro blockchain node.
It provides helper functions to query node state, blockchain data, addresses, transactions, and to build, sign, and submit transactions.

Important:
All functions that communicate with the node return a requests.Response object, not parsed data.
You must explicitly call .json(), .text, .status_code, etc., on the returned value.


Requirements

Python

  • Python 3.8+

Dependencies

pip install requests ecdsa

Configuration

DECIMALS = 10**6
NODE = "http://denaro.mine.bz:3006/"
DEBUG = True

Description

  • DECIMALS Atomic units per Denaro coin (1 DNR = 1,000,000 units).

  • NODE Base URL of the Denaro node API.

  • DEBUG If enabled, prints the raw requests.Response object and its decoded JSON payload.


Return Value Convention (IMPORTANT)

All network-related functions return:

requests.Response

This allows you to manually inspect:

response.status_code
response.headers
response.text
response.json()

Example:

resp = get_status()
if resp.status_code == 200:
    data = resp.json()

Node & Blockchain API Functions

All functions below return requests.Response.


get_node_info() -> requests.Response

Fetches general node information.

resp = get_node_info()

get_status() -> requests.Response

Returns blockchain and node status.

resp = get_status()

get_peers() -> requests.Response

Returns the list of known peers.

resp = get_peers()

get_block() -> requests.Response

Returns the latest block.

resp = get_block()

get_blocks() -> requests.Response

Returns a list of recent blocks.

resp = get_blocks()

get_transaction(txhash) -> requests.Response

Fetches a transaction by its hash.

resp = get_transaction("TX_HASH")

get_pending_transactions() -> requests.Response

Returns all pending (mempool) transactions.

resp = get_pending_transactions()

get_address_info(addr) -> requests.Response

Returns balance and transaction history for an address.

resp = get_address_info("DNR_ADDRESS")

submit_tx(tx_hex) -> requests.Response

Submits a hex-encoded transaction to the network.

resp = submit_tx(tx_hex)

sync_blockchain() -> requests.Response

Triggers a blockchain synchronization.

resp = sync_blockchain()

get_mining_info() -> requests.Response

Returns mining-related information.

resp = get_mining_info()

submit_block(id, content, txs) -> requests.Response

Submits a mined block.

resp = submit_block(
    id="BLOCK_ID",
    content="BLOCK_CONTENT",
    txs=[tx_hex_1, tx_hex_2]
)

Cryptographic Utilities

These functions do not return requests.Response.


sha256(b: bytes) -> bytes

Computes a SHA-256 hash.


double_sha256(b: bytes) -> bytes

Computes SHA256(SHA256(data)).


amount_to_int(amount: float) -> int

Converts a human-readable Denaro amount to atomic units.

amount_to_int(1.0)  # 1000000

Transaction Construction


build_tx_object(from_addr, to_addr, amount_int) -> dict

Creates an unsigned transaction object.


serialize_tx(tx: dict) -> bytes

Serializes a transaction deterministically (sorted keys, compact JSON).


sign_tx(tx_bytes, privkey_hex) -> dict

Signs a serialized transaction using ECDSA secp256k1.

Returns a dictionary containing:

  • signature (hex)
  • public_key (hex)

make_tx_hex(from_addr, to_addr, amount, privkey_hex) -> str

Builds, signs, serializes, and hex-encodes a transaction.

tx_hex = make_tx_hex(...)

Sending Transactions


send(from_addr, to_addr, amount, privkey_hex) -> requests.Response

High-level convenience function.

  • Builds the transaction
  • Signs it
  • Submits it to the node
resp = send(
    from_addr="FROM_ADDRESS",
    to_addr="TO_ADDRESS",
    amount=0.5,
    privkey_hex="PRIVATE_KEY_HEX"
)

Returned value is a requests.Response.


Notes & Limitations

  • All node interactions return requests.Response
  • Private keys must be raw hex strings
  • No UTXO selection, fee calculation, or balance validation
  • Debug mode may expose sensitive data in logs

Example Usage

resp = get_address_info("FROM_ADDRESS")
print(resp.status_code)
print(resp.json())

resp = send(
    from_addr="FROM_ADDRESS",
    to_addr="TO_ADDRESS",
    amount=1.0,
    privkey_hex="PRIVATE_KEY"
)
print(resp.json())

Disclaimer

This module is provided as-is for development and experimentation. Use extreme caution when handling real funds.

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

denarolib-1.0.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

denarolib-1.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file denarolib-1.0.0.tar.gz.

File metadata

  • Download URL: denarolib-1.0.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for denarolib-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c7da9cd778a72e925db89e858de55f10522588d14fd87c5eea7341a3595a8ad4
MD5 033bd1e2154f8491b0079b766cab196a
BLAKE2b-256 46efd22cf4592638460030a864468ac6153d6697a19659bef17ace88604e5d2f

See more details on using hashes here.

File details

Details for the file denarolib-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: denarolib-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for denarolib-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b03389274bb09aa4520763d69441dcec95f9c2e2e0a2260fd958e8d51fca27a
MD5 276070253944b60484064829c7241aa5
BLAKE2b-256 d499668bd17fcd7056c9e3fb8d76aa90e0a2a21cc184320c6c3f095def8224fe

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