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.1.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.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: denarolib-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 910cde4a751f87c536dc16d66100c3e76fda0fecbd16e25dd552f4afb1e48617
MD5 52b4824f4ad8aa4b1cc10a784e0d92d3
BLAKE2b-256 61d7f680840f1ea8b31d34c081cd690f2283f10f7110806930a756c57cbe47ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: denarolib-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68a0fd94a0811f67b4be0be71293b2138748b718976c21a74f31020b4ce728c8
MD5 21f2df6eae89f014d4f9cee161fb526f
BLAKE2b-256 76c007825f99f5eef54fed7725a8d5d4c3f030fae3a02346de38e70d95a384ba

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