Skip to main content

Cointime economics framework implementation for the Ergo blockchain.

Project description

boxtime

Cointime economics framework implementation for the Ergo blockchain.

Description

Boxtime is a Python library that implements the Cointime Economics framework for Ergo. It connects to one or more Ergo nodes to compute coinblocks created, destroyed, and stored — using concurrent async I/O for high throughput. It optionally enriches the data with ERG/USD prices from CoinGecko for plotting and analysis.

Installation

pip install boxtime

Prerequisites

  • Python 3.10+
  • Ergo Node — one or more running nodes with the extra blockchain indexer enabled (ergo.node.extraIndex = true).
  • CoinGecko API key (optional) — a free Demo API key from coingecko.com/en/api. Required only for price-related methods.

Quickstart

Basic cointime metrics

from boxtime import Cointime

# Single node (default: http://127.0.0.1:9053)
ct = Cointime()

# Coinblocks created at a single height (= circulating supply in nanoERGs)
cbc = ct.coinblocks_created(500_000)

# Coinblocks destroyed at a single height
cbd = ct.coinblocks_destroyed(500_000)

# Coinblocks stored (CBC - CBD)
cbs = ct.coinblocks_stored(500_000)

# Totals over a range — runs concurrently
total_cbc = ct.total_coinblocks_created(500_000, 500_100)

Multi-node with concurrency

Distribute requests across multiple nodes with round-robin load balancing:

ct = Cointime(
    node_urls=["http://node1:9053", "http://node2:9053"],
    max_concurrent=50,  # default
)

# Same sync API — concurrency handled internally
# Works in scripts, Jupyter notebooks, async frameworks, etc.
total_cbc = ct.total_coinblocks_created(0, 1_000_000)
total_cbd = ct.total_coinblocks_destroyed(0, 1_000_000)
total_cbs = ct.total_coinblocks_stored(0, 1_000_000)

Price-enriched data (for plotting)

Pass a CoinGecko API key to unlock price methods:

ct = Cointime(
    node_urls=["http://127.0.0.1:9053"],
    coingecko_api_key="CG-your-demo-key",
)

# Current ERG/USD spot price
price = ct.get_price()

# Price history between two block heights
history = ct.get_price_history(500_000, 510_000)

# Coinblocks created with matched price data — ready to plot
data_points = ct.get_coinblocks_created(500_000, 510_000)
for dp in data_points:
    print(dp.height, dp.timestamp, dp.value, dp.price)

Each CointimeDataPoint bundles height, timestamp, value (cointime metric in nanoERG-blocks), and price (ERG/USD). Only block timestamps that exactly match a CoinGecko price timestamp are included.

API Overview

Cointime(node_urls, coingecko_api_key, max_concurrent)

Parameter Default Description
node_urls ["http://127.0.0.1:9053"] List of Ergo node URLs for round-robin load balancing
coingecko_api_key None CoinGecko Demo API key (enables price methods)
max_concurrent 50 Maximum concurrent requests

Primitive metrics (single height):

  • coinblocks_created(height) — circulating supply at height
  • coinblocks_destroyed(height) — sum of input.value × lifespan for all inputs
  • coinblocks_stored(height) — CBC − CBD

Aggregate metrics (height range, inclusive — runs concurrently):

  • total_coinblocks_created(start_height, end_height)
  • total_coinblocks_destroyed(start_height, end_height)
  • total_coinblocks_stored(start_height, end_height)

Price methods (require CoinGecko API key):

  • get_price() — current ERG/USD spot price
  • get_price_history(start_height, end_height)List[PricePoint]

Convenience methods (require CoinGecko API key):

  • get_coinblocks_created(start_height, end_height)List[CointimeDataPoint]
  • get_coinblocks_destroyed(start_height, end_height)List[CointimeDataPoint]
  • get_coinblocks_stored(start_height, end_height)List[CointimeDataPoint]

ErgoNodeClient(session, node_url) — async Ergo node client

All methods are async def. Requires an aiohttp.ClientSession:

import asyncio
import aiohttp
from boxtime import ErgoNodeClient

async def main():
    async with aiohttp.ClientSession() as session:
        node = ErgoNodeClient(session, "http://127.0.0.1:9053")
        info = await node.get_node_info()
        tx = await node.get_transaction("tx_id_here")
        emission = await node.get_emission_at(500_000)

asyncio.run(main())

CoinGeckoClient(api_key) — price data

Synchronous client using the coingecko-sdk:

  • get_current_price(vs_currency) — current ERG price
  • get_price_history(days, vs_currency) — price history
  • get_price_history_range(from_ts, to_ts, vs_currency) — price history between timestamps
  • get_price_at_date(date, vs_currency) — price on a specific date

Development

# Install with test dependencies
pip install -e ".[test]"

# Run tests
pytest

License

This project is licensed under the MIT License.

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

boxtime-1.0.1.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

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

boxtime-1.0.1-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: boxtime-1.0.1.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for boxtime-1.0.1.tar.gz
Algorithm Hash digest
SHA256 67c036de1e8c8f05a75b84060853ea5dec23ff7887dd6a41888d1cdee8f3ba73
MD5 e793d8508ebc71999dc0e076696fc96e
BLAKE2b-256 0df89f188000abb74d38b991da9fce55645f6a9055b0c069d2319190acb52b60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: boxtime-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for boxtime-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e1d1c0160a945ad68d498b15e81c93119f20dbd471c7e829e4459eb69bdc44f
MD5 a72a3d7306fd94b8dde4a79df1b25b4a
BLAKE2b-256 a24c6062c55c6d0a7acafbbb3d846ce12ea9e1613476e662b42059689ad8b037

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