Self-contained Python library for ZHCASH addresses, balances, ZHC sends, and USDZ gas-free sends.
Project description
ZHLink Python Library
zhlink is a self-contained Python library for ZHCASH.
The public API is intentionally small:
- create a new ZHC address;
- check ZHC + USDZ balance;
- send native ZHC from a private key;
- send USDZ with admin-paid ZHC gas;
- optionally read extra ZRC-20 token balances.
The raw transaction engine is bundled inside the package. Normal users only
import zhlink.
Install
Recommended Python:
- Python
3.10or newer is required. - Python
3.10and3.11are the safest choices for deployment. - Python
3.12should work. - Python
3.9and older are not supported.
From PyPI:
pip install zhlink
From this folder:
cd /root/wallet/zhlink
python3 -m venv .venv
. .venv/bin/activate
pip install -e .
For direct local use without install:
cd /root/wallet/zhlink
export PYTHONPATH=/root/wallet/zhlink
Create Address
from zhlink import create_address
wallet = create_address()
print(wallet.address)
print(wallet.priv_key)
Private keys are generated locally. The library never sends private keys to ZeroScan or RPC.
Get Balance
By default get_balance returns ZHC and USDZ.
from zhlink import get_balance
balance = get_balance("Z...")
print(balance["zhc"])
print(balance["usdz"])
Extra ZRC-20 tokens can be requested when needed:
from zhlink import get_balance
balance = get_balance(
"Z...",
tokens={"EDS": "dc71958156a945d3071374521e1a7a42f5ba8038"},
)
print(balance["tokens"]["EDS"])
Send ZHC
from zhlink import send_zhc
result = send_zhc(
private_key_wif="L...",
to_address="Z...",
amount="1.25",
)
print(result)
The sender address is derived from the private key automatically.
Send USDZ Gas-Free
send_usdz_gas_free signs the USDZ transfer with the sender key and pays ZHC
gas from the admin gas wallet.
from zhlink import send_usdz_gas_free
result = send_usdz_gas_free(
sender_private_key_wif="L...",
admin_private_key_wif="K...",
to_address="Z...",
amount="0.1",
)
print(result["broadcast"]["txid"])
The function does the required checks automatically:
- derives sender/admin addresses from WIF keys;
- checks sender USDZ balance;
- runs
callcontractdry-run; - loads admin gas UTXO from ZeroScan;
- skips locally used gas UTXO;
- builds and signs rawtx locally;
- runs
testmempoolaccept; - if one UTXO is rejected, tries another UTXO;
- broadcasts through ZeroScan;
- falls back to RPC
sendrawtransaction.
For mass sends, prepare independent admin gas UTXO first. One gas-free transfer
needs one spendable admin gas UTXO. The recommended ticket size is 0.5 ZHC.
from zhlink import admin_gas_wallet_info
info = admin_gas_wallet_info("K...")
print(info["suitable_gas_utxo_count"])
print(info["recommended_split_count"])
Custom RPC / ZeroScan
Defaults:
- ZeroScan API:
https://ws.zeroscan.st,https://ws.zeroscan.io - RPC:
https://rpc.zeroscan.st - USDZ contract:
a48d0ee7365ce1add8e595de4d54344239f8ca28
Override them when needed:
from zhlink import ZHLinkConfig, get_balance
config = ZHLinkConfig.public_network(
zeroscan_endpoints=("https://ws.zeroscan.st", "https://ws.zeroscan.io"),
public_rpc_urls=("https://rpc.zeroscan.st", "https://my-node.example/rpc"),
)
print(get_balance("Z...", config=config))
Examples
Run examples one by one:
cd /root/wallet/zhlink
PYTHONPATH=. python3 examples/create_wallet.py
PYTHONPATH=. python3 examples/create_bip39_wallet.py
PYTHONPATH=. ZHLINK_ADDRESS="Z..." python3 examples/check_balance.py
Run all safe examples at once:
cd /root/wallet/zhlink
PYTHONPATH=. python3 examples/run_all_examples.py
Send examples are guarded by RUN_REAL_SEND=1 and will not broadcast by
accident. Never commit real private keys.
Publishing
GitHub Actions workflow .github/workflows/python-publish.yml builds, tests,
checks, and publishes the package to PyPI.
Release flow:
git tag v0.1.1
git push origin v0.1.1
The workflow uses PyPI Trusted Publishing, so the PyPI project must allow this GitHub repository/workflow as a trusted publisher.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zhlink-0.1.1.tar.gz.
File metadata
- Download URL: zhlink-0.1.1.tar.gz
- Upload date:
- Size: 49.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8455cf5e9918f9084e7582896da42637254f93d2b8c1dbe22fade1bdc6ddc06e
|
|
| MD5 |
9e0810f47196c6bab7c4bf757c926176
|
|
| BLAKE2b-256 |
b0a42e12d69973951d7f9efe1ccd79249b3441a12b2aacae640c6de7a56f8cd8
|
Provenance
The following attestation bundles were made for zhlink-0.1.1.tar.gz:
Publisher:
python-publish.yml on zerohourcash/zhlink
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zhlink-0.1.1.tar.gz -
Subject digest:
8455cf5e9918f9084e7582896da42637254f93d2b8c1dbe22fade1bdc6ddc06e - Sigstore transparency entry: 2144321018
- Sigstore integration time:
-
Permalink:
zerohourcash/zhlink@43edb46758afd7cf16911731856ed79cd7c284af -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/zerohourcash
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@43edb46758afd7cf16911731856ed79cd7c284af -
Trigger Event:
push
-
Statement type:
File details
Details for the file zhlink-0.1.1-py3-none-any.whl.
File metadata
- Download URL: zhlink-0.1.1-py3-none-any.whl
- Upload date:
- Size: 50.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f2227daa0b8d6dd416b06a10e0a7745c393f78727913562dc92101e361832a4
|
|
| MD5 |
721d2e791a22520a6c468020ce8f4ecf
|
|
| BLAKE2b-256 |
0fa3e2b685357ec5fa4f61f722c5ad16bf3871a5e237cb3e53c81f3b1fab6a3f
|
Provenance
The following attestation bundles were made for zhlink-0.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on zerohourcash/zhlink
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zhlink-0.1.1-py3-none-any.whl -
Subject digest:
0f2227daa0b8d6dd416b06a10e0a7745c393f78727913562dc92101e361832a4 - Sigstore transparency entry: 2144321133
- Sigstore integration time:
-
Permalink:
zerohourcash/zhlink@43edb46758afd7cf16911731856ed79cd7c284af -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/zerohourcash
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@43edb46758afd7cf16911731856ed79cd7c284af -
Trigger Event:
push
-
Statement type: