chainweb-mining-client: Mining Client for Kadena Chainweb

[ bsd3, data, mathematics, program ] [ Propose Tags ]

A mining client for Kadena Chainweb. It supports

  • mining with ASICs through a stratum server,

  • simulated mining for testing,

  • multi threaded CPU mining,

  • external mining workers (e.g. a GPU).

Competitive mining on the Kadena Mainnet requires special mining hardware (ASIC), which connects to a Stratum Server from where it obtains work.

All other mining modes (GPU, CPU, and simulation) are intended only for testing.

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS] 0.2, 0.5
Change log
Dependencies aeson (>=1.5), async (>=2.2), attoparsec (>=0.14), base (>=4.10 && <5), base16-bytestring (>=1.0), bytes (>=0.17), bytestring (>=0.10), clock (>=0.8), configuration-tools (>=0.5), connection (>=0.3), cryptonite (>=0.27), exceptions (>=0.10), hashable (>=1.3), hostaddress (>=0.2), http-client (>=0.7), http-client-tls (>=0.3), http-types (>=0.12), lens (>=4.19), loglevel (>=0.1), memory (>=0.15), mwc-random (>=0.14), process (>=1.6), retry (>=0.8), stm (>=2.5), streaming (>=0.2), streaming-commons (>=0.2.2), streaming-events (>=1.0), text (>=1.2), time (>=1.9), unordered-containers (>=0.2), wai-extra (>=3.0) [details]
License BSD-3-Clause
Copyright Copyright (c) 2019 - 2022, Kadena LLC
Author Lars Kuhtz
Category Data, Mathematics
Home page
Bug tracker
Source repo head: git clone
Uploaded by larsk at 2022-11-23T23:21:20Z
Executables chainweb-mining-client
Downloads 437 total (7 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2022-11-24 [all 2 reports]

Readme for chainweb-mining-client-0.5

[back to package description]

Mining Client for Kadena

A mining client for Kadena's chainweb node mining API. It supports

  • mining with ASICs through a stratum server,
  • simulated mining for testing,
  • multi threaded CPU mining,
  • external mining workers (e.g. a GPU).

Competitive mining on the Kadena Mainnet requires special mining hardware (ASIC), which connects to a Stratum Server from where it obtains work.

All other mining modes (GPU, CPU, and simulation) are intended only for testing.


A docker image of the latest version is available at

Binaries can also be compiled with a recent version of GHC and cabal directly from Hackage

cabal install chainweb-mining-client

or from the GitHub sources

git clone
cd chainweb-mining-client
cabal build
cabal run chainweb-mining-client -- --help


Calling chainweb-mining-client --help provides an overview of the available usage options:

Usage: chainweb-mining-client [--info] [--long-info] [-v|--version] [--license]
                              [--print-config-as full|minimal|diff |
                                --print-config] [--config-file FILE]
                              [-r|--hash-rate ARG] [-n|--node DOMAIN:PORT]
                              [(-t|--tls) | --no-tls]
                              [(-x|--insecure) | --no-insecure]
                              [-k|--public-key ARG] [-a|--account ARG]
                              [-c|--thread-count ARG]
                              [--generate-key | --no-generate-key]
                              [-l|--log-level error|warn|info|debug]
                              [-w|--worker cpu|external|simulation|stratum]
                              [--external-worker-cmd ARG] [--stratum-port ARG]
                              [--stratum-interface ARG]
                              [--stratum-difficulty ARG] [-s|--stratum-rate ARG]

  Kadena Chainweb Mining Client

Available options:
  --info                   Print program info message and exit
  --long-info              Print detailed program info message and exit
  -v,--version             Print version string and exit
  --license                Print license of the program and exit
  -?,-h,--help             Show this help message
  --print-config-as full|minimal|diff
                           Print the parsed configuration to standard out and
  --print-config           Print the parsed configuration to standard out and
                           exit. This is an alias for --print-config-as=full
  --config-file FILE       Configuration file in YAML or JSON format. If more
                           than a single config file option is present files are
                           loaded in the order in which they appear on the
                           command line.
  -r,--hash-rate ARG       hashes per second (only relevant for mining
                           simulation, ignored by the cpu worker)
  -n,--node DOMAIN:PORT    node to which to connect
  -t,--tls                 use TLS to connect to node
  --no-tls                 unset flag tls
  -x,--insecure            accept self-signed TLS certificates
  --no-insecure            unset flag insecure
  -k,--public-key ARG      public-key for the mining rewards account
  -a,--account ARG         account for the mining rewards (default: public-key
                           prefixed with 'k:')
  -c,--thread-count ARG    number of concurrent mining threads
  --generate-key           Generate a new key pair and exit
  --no-generate-key        unset flag generate-key
  -l,--log-level error|warn|info|debug
                           Level at which log messages are written to the
  -w,--worker cpu|external|simulation|stratum
                           The type of mining worker that is used
  --external-worker-cmd ARG
                           command that is used to call an external worker. When
                           the command is called the target value is added as
                           last parameter to the command line.
  --stratum-port ARG       the port on which the stratum server listens
  --stratum-interface ARG  network interface that the stratum server binds to
  --stratum-difficulty ARG How the difficulty for stratum mining shares is
                           choosen. Possible values are "block" for using the
                           block target of the most most recent notification of
                           new work, or number between 0 and 256 for specifiying
                           a fixed difficulty as logarithm of base 2 (number of
                           leading zeros).
  -s,--stratum-rate ARG    Rate (in milliseconds) at which a stratum worker
                           thread emits jobs.

Configurations are loaded in order from the following sources:
  1. Configuration files from locations provided through --config-file options
     in the order as they appear.
  2. Command line options.

Configuration file locations can be either local file system paths or remote
HTTP or HTTPS URLs. Remote URLs must start with either "http://" or "https://".

Configuration settings that are loaded later overwrite settings that were loaded

Usage Examples

Generating a New Key Pair

chainweb-mining-client --generate-key

This outputs a public and a private key. The public key is given to the mining client. The private key must be kept secret.

public:  87ef8fdb229ad10285ae191a168ea2ec0794621a127df21e372f41fd0246e4cf
private: 64ef6379db5ef6004aff98182688c6e8b4a5229e706f1ccf6a73b05b1432aedf

Mining on Mainnet With an ASIC

chainweb-mining-client needs access to the mining API of a full Chainweb node in the Kadena Mainnet. The node must be configured to enable the mining API with the Pact public key (and, optionally, account name) of the miner. Rewards for mined blocks will be credited to that account. The default is to use the k: account for the key.

The --enable-mining-coordination, --mining-public-key can be used to configure chainweb-node for mining. The mining API is served on the service API port (default is 1848).

Assuming that serves the chainweb-node mining API on port 1848, the following command can be used to run chainweb-mining-client with the stratum server on port 1917:

chainweb-mining-client \
    --public-key 87ef8fdb229ad10285ae191a168ea2ec0794621a127df21e372f41fd0246e4cf \
    --node \
    --stratum-port 1917

Assuming that the host on which chainweb-mining-client runs is, the pool address that is used to configure the ASIC miner is stratum+tcp://

One can point more than a single ASIC miner to the same chainweb-mining-client stratum server. All connected clients work together and all mining rewards are credited to the same account, that is configured in chainweb node.

By default the stratum server sets the difficulty of the work that is sent to the mining clients to the actual difficulty of the block of the most recent work. This means that it can take a long time before the client solves any work. It also means that the target is reset for each new block.

It is also possible to set a custom difficulty. As a consequence not all accepted solutions qualify as solved blocks, but ASIC miner may provide a more continuous feedback on its current performance. Some devices may also be more efficient in this mode an yield higher returns.

The thread count determines how many independent stratum works are used to concurrently provide work to the clients. Each stratum worker receives one work header at a time from the chainweb-node mining API and emits jobs for that work to all clients at a configurable rate. The effective rate of jobs is higher than then configured rate because when upstream work gets preempted. Each client receives are all jobs from all workers.

The following command runs two stratum workers that serve jobs at least every 500 milliseconds at a fixed difficulty level of 50.

chainweb-mining-client \
    --public-key 87ef8fdb229ad10285ae191a168ea2ec0794621a127df21e372f41fd0246e4cf \
    --node \
    --stratum-port 1917 \
    --stratum-difficulty=50 \
    --stratum-rate=500 \

The solution space for each mining job is about 280 terra hashes. The --stratum-rate should be chosen such that the mining devices does not perform more than that number of hashes within the provided time range. For instance, for an miner that performs 140TH/s the --stratum-rate should be at least 2000 (2 seconds).

The --stratum-difficulty parameter expects a integral number between 0 and 256. It denotes the difficulty as a logarithm of base 2. In practice the actual target uses a difficulty level of at least 42 and at most the difficulty of block of the current work.

It may help to experiment a little with the --stratum-difficulty, --stratum-rate, and the --thread-count parameters. We found, that small values for --thread-count (one to three) and moderate values for --stratum-difficulty (in the upper forties / lower fifties) yielded good results. The But that may differ between different devices and setups.

If the chainweb-node mining API is served via a reverse proxy with TLS the --tls flag must be used to enable HTTPS.

CPU Mining

Assuming that serves the chainweb-node mining API on port 1848, the following command can be used for CPU mining to the from the previous example:

chainweb-mining-client \
    --public-key 87ef8fdb229ad10285ae191a168ea2ec0794621a127df21e372f41fd0246e4cfa \
    --node \
    --worker cpu \
    --thread-count 16 \

GPU Mining

GPU mining is supported via calling an external worker that does the mining work. An example for such a GPU mining tool for Kadena is bigolchunugus.

chainweb-mining-client \
    --public-key 87ef8fdb229ad10285ae191a168ea2ec0794621a127df21e372f41fd0246e4cf \
    --node \
    --worker external \
    --external-miner-cmd bigolchunus

For selecting the GPU or passing additional arguments to the external tools, the extra parameters are appended to the command. E.g.

chainweb-mining-client \
    --public-key 87ef8fdb229ad10285ae191a168ea2ec0794621a127df21e372f41fd0246e4cf \
    --node \
    --worker external \
    --external-worker-cmd "bigolchunus -d 2"

The external mining tool is called by adding the target as the last command line parameter and passing the work bytes on stdin.

Creating a Configuration File

The current configuration of chainweb-mining-client can be stored in a configuration file by adding the --print-config parameter

chainweb-mining-client \
    --public-key 87ef8fdb229ad10285ae191a168ea2ec0794621a127df21e372f41fd0246e4cf \
    --node \
    --stratum-port 1917 \
    --print-config > config.yml

This results in the following configuration file:

account: null
externalWorkerCommand: echo 'no external worker command configured' && /bin/false
generateKey: false
hashRate: 1000000.0
insecure: true
logLevel: info
publicKey: 87ef8fdb229ad10285ae191a168ea2ec0794621a127df21e372f41fd0246e4cf
stratumDifficulty: 50
stratumInterface: '*'
stratumPort: 1917
threadCount: 10
useTls: true
worker: stratum

The configuration can then be used via

chainweb-mining-client --config-file config.yml