Clean-room Python implementation of the OrdexCoin (OXC) and OrdexGold (OXG) blockchain protocols.
- Multi-chain support: Single library handles both OXC (SHA-256d) and OXG (Scrypt + MWEB)
- Full primitive types: Block headers, transactions, scripts, and serialization
- Consensus rules: PoW validation, difficulty retargeting, block subsidy
- Address generation: P2PKH, P2SH, Bech32 (P2WPKH), P2TR (Taproot) with correct chain prefixes
- HD Wallet: BIP32 hierarchical deterministic keys, BIP39 mnemonic support
- Transaction signing: ECDSA transaction signing for P2PKH inputs
- Script interpreter: Basic script validation for P2PKH, P2WPKH
- Block validation: PoW and merkle root verification
- Fee estimation: Local fee estimation with RPC fallback
- P2P networking: Async TCP connection, header/block sync, multi-peer management
- RPC client: JSON-RPC interface to ordexcoind / ordexgoldd
- RPC Services: Network Monitor, Health Monitor, Mempool, Block, Address, Transaction, Tx Tracker, Notifications
- CLI Daemon:
ordex-rpccommand-line tool for wallet and blockchain operations
# Install dependencies
pip install -r requirements.txt
# Install in development mode
pip install -e .
# Run tests
pytest tests/ -vfrom ordex.chain.chainparams import oxc_mainnet, oxg_mainnet
from ordex.wallet.address import generate_keypair
# OrdexCoin address
kp = generate_keypair(oxc_mainnet())
print(f"OXC P2PKH: {kp['p2pkh']}") # X...
print(f"OXC P2SH: {kp['p2sh']}") # 7...
print(f"OXC Bech32: {kp['p2wpkh']}") # oxc1...
print(f"OXC WIF: {kp['wif']}")
# OrdexGold address
kp = generate_keypair(oxg_mainnet())
print(f"OXG P2PKH: {kp['p2pkh']}") # G...
print(f"OXG Bech32: {kp['p2wpkh']}") # oxg1...from ordex.chain.chainparams import oxc_mainnet
from ordex.wallet.hd import HDWallet
from ordex.wallet.bip39 import mnemonic_to_seed
# From mnemonic
mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
wallet = HDWallet.from_mnemonic(oxc_mainnet(), mnemonic)
# Derive addresses
account = wallet.derive_account(0)
external = wallet.derive_external_chain(account)
addr = wallet.derive_address(external, 0)
print(f"Address: {addr['p2pkh']}")
print(f"Path: {addr['path']}") # m/44'/0'/0'/0/0from ordex.wallet.signing import create_signed_transaction
from ordex.core.key import PrivateKey
# Create and sign a transaction
privkey = PrivateKey.generate()
inputs = [
('0000...0000', 0, 100000000), # (prevout_hash, prevout_index, amount)
]
outputs = [
('Xu9T...nQw', 50000000), # (address, amount in satoshis)
]
tx = create_signed_transaction(inputs, outputs, privkey)
print(f"Signed txid: {tx.txid().hex()}")from ordex.rpc import OrdexServices, create_services
# Initialize all services
services = create_services([{
"url": "http://localhost:8332",
"user": "rpcuser",
"password": "rpcpass"
}])
# Use services
fees = services.mempool.get_fees()
tip = services.blocks.get_tip()
stats = services.get_stats()# Start RPC server
ordex-rpc start --network ordexcoin
# Get blockchain info
ordex-rpc getblockchaininfo
# Wallet operations
ordex-rpc wallet list
ordex-rpc wallet create my_wallet
ordex-rpc wallet getnewaddress my_walletfrom ordex.rpc.client import RpcClient
from ordex.wallet.utxo import UTXO, CoinSelector, CoinSelectionStrategy
rpc = RpcClient()
# Get UTXOs from node
result = rpc.listunspent(minconf=1)
utxos = [UTXO.from_rpc(u) for u in result]
# Select coins using greedy strategy
selector = CoinSelector(strategy=CoinSelectionStrategy.GREEDY)
result = selector.select(utxos, target_amount=50000000, fee_per_byte=1)
print(f"Selected {len(result.utxos)} UTXOs")
print(f"Total: {result.total_amount} satoshis")
print(f"Fee: {result.fee} satoshis")from ordex.rpc.client import RpcClient
from ordex.wallet.utxo import WalletManager, CoinSelectionStrategy
from pathlib import Path
rpc = RpcClient()
# Create manager with persistent storage
manager = WalletManager(rpc, storage_path=Path("./wallets"))
# Create multiple wallets
manager.create_wallet("Savings", "wallet_savings", addresses=["XvX26g..."])
manager.create_wallet("Spending", "wallet_spending")
# Generate addresses for spending wallet
manager.generate_address("wallet_spending")
# Sync and get stats
stats = manager.sync_wallet("wallet_savings")
print(stats.summary())
# Full report
print(manager.full_stats_report())from ordex.rpc.client import RpcClient
rpc = RpcClient("http://127.0.0.1:25175", "rpcuser", "rpcpass")
info = rpc.getblockchaininfo()
print(f"Chain: {info['chain']}, Height: {info['blocks']}")import asyncio
from ordex.chain.chainparams import oxc_mainnet
from ordex.net.connection import NodeConnection
async def main():
conn = NodeConnection("127.0.0.1", 25174, oxc_mainnet())
await conn.connect()
await conn.handshake()
print(f"Peer: {conn.peer_version.user_agent}")
await conn.close()
asyncio.run(main())import asyncio
from ordex.chain.chainparams import oxc_mainnet
from ordex.net.connection import NodeConnection
from ordex.net.sync import BlockSynchronizer
async def main():
conn = NodeConnection("127.0.0.1", 25174, oxc_mainnet())
await conn.connect()
await conn.handshake()
sync = BlockSynchronizer(conn, oxc_mainnet())
headers = await sync.download_headers(peer_height=800000)
print(f"Downloaded {len(headers)} headers")
await conn.close()
asyncio.run(main())ordex/
├── core/ # Serialization, hashing, keys, base58, script
├── primitives/ # CTransaction, CBlock, CBlockHeader
├── consensus/ # PoW, difficulty, subsidy, amount
├── chain/ # Chain parameters (OXC/OXG × mainnet/testnet/regtest)
├── net/ # P2P protocol, messages, async connections, sync
├── rpc/ # JSON-RPC client
└── wallet/ # Address generation, HD wallet, BIP39
| Feature | OrdexCoin (OXC) | OrdexGold (OXG) |
|---|---|---|
| PoW Algorithm | SHA-256d | Scrypt |
| MWEB | No | Yes |
| Max Supply | 8,450,000 | 1,001,000 |
| Halving Interval | 210,000 blocks | 239,000 blocks |
| Address Prefix | X (76) | G (39) |
| Bech32 HRP | oxc | oxg |
| Default Port | 25174 | 25466 |
# Run all tests
pytest tests/ -v
# Run specific test file
pytest tests/test_hd.py -v
# Run with coverage
pytest tests/ --cov=ordexTest Status: 598 tests passing
This is an open-source project maintained by Timh Bergstrom and the OrdexNetwork community. To support the development efforts you can donate to the following addresses:
* BTC: bc1qkmzc6d49fl0edyeynezwlrfqv486nmk6p5pmta
* ETH/ERC-20: 0xC13D012CdAae7978CAa0Ef5B1E30ac6e65e6b17F
* LTC: ltc1q0ahxru7nwgey64agffr7x89swekj7sz8stqc6x
* SOL: HB2o6q6vsW5796U5y7NxNqA7vYZW1vuQjpAHDo7FAMG8
* XRP: rUW7Q64vR4PwDM3F27etd6ipxK8MtuxsFs
To support tests and implementation with the ordexnetwork, you can help by donating tokens that will be used for testing and refining the system.
* OXC: oxc1q3psft0hvlslddyp8ktr3s737req7q8hrl0rkly
* OXG: oxg1q34apjkn2yc6rsvuua98432ctqdrjh9hdkhpx0t
You can also Buy me a coffee. For issues and contributions, visit the GitHub repository.
See LICENSE.md for details.
Copyright (c) 2026 ORDEX PROTOCOL/Timh Bergstrom. All rights reserved.