Developer Guide¶
This page covers the key developer workflows for the Bitcoin Gold (BTG) ecosystem: building a wallet application, performing atomic swaps, and other essential development topics.
Building a wallet¶
When building a BTG wallet, you have several approaches depending on your requirements:
Option 1: Use a library / SDK¶
The most common approach is to build on top of an existing Bitcoin/UTXO library and configure it for BTG's chain parameters:
| Library | Language | Notes |
|---|---|---|
| bitcoinjs-lib | JavaScript | Configure BTG network params (magic bytes, address prefixes, BIPs) |
| rust-bitcoin | Rust | Low-level primitives; wire up BTG-specific validation |
| pycoin | Python | Supports custom altcoin networks with minimal config |
| bitcoin-s | Scala | JVM ecosystem with strong typing |
Option 2: Fork an existing wallet¶
- For a full-node wallet, fork BTCGPU/BTCGPU and customise the RPC, GUI, or wallet backend.
- For a light / SPV wallet, fork electrum — Electrum's plugin architecture makes it straightforward to add BTG support via the
electrumgfork already available in the community. - For a mobile wallet, consider wrapping
libbitcoinconsensusvia JNI (Android) or FFI (iOS) — see theshared-librariesdoc in the BTCGPU source for the C API.
Key BTG network parameters¶
| Parameter | Mainnet value |
|---|---|
| Address prefix (P2PKH) | G (or A for flexible prefix) |
| Address prefix (P2SH) | A |
| WIF prefix | 0x80 |
| BIP44 coin type | 156 (0x9c) |
| BIP44 purpose | 44' |
| Message magic | Bitcoin Gold Signed Message:\n |
| Genesis block hash | 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f |
| Minimum difficulty | powLimit (same as BTC) |
Testing your wallet¶
- Use testnet v3 — see operators/full-node for testnet configuration.
- Run against regtest mode for local development:
bgoldd -regtest. - Verify address generation produces valid P2PKH and P2SH addresses using the Blockbook explorer at explorer.bitcoingold.services.
Atomic swap¶
BTG supports atomic swaps via hashed timelock contracts (HTLC), the same mechanism used across UTXO-based blockchains. Since BTG and BTC share the same opcode set (including OP_CHECKLOCKTIMEVERIFY and OP_CHECKSEQUENCEVERIFY), cross-chain atomic swaps between BTG and BTC (or between BTG and any other UTXO coin) are fully supported.
How it works¶
- Party A (BTG holder) creates a HTLC on the BTG chain that locks funds. The contract includes:
- A hash of a secret
H(x) - A refund timeout (e.g. 48 hours)
- Party B (BTC holder) creates a corresponding HTLC on the BTC chain using the same
H(x). - Party A claims the BTC by revealing
xon the BTC chain. - Party B, now knowing
x, claims the BTG before the timeout expires.
Tools and libraries¶
- atomic-swap-lib (JavaScript) — HTLC creation and redemption for Bitcoin-family chains.
- liquality/chainabstractionlayer (JavaScript) — Unified interface for multiple blockchains including BTG.
- comit-network/xmr-btc-swap — Reference for cross-chain atomic swap design patterns (adaptable to BTG).
- Manual: Use
bgold-clito create raw transactions withOP_CHECKLOCKTIMEVERIFYandOP_SHA256.
Manual HTLC example¶
# Create a P2SH address that encumbers funds with a SHA256 hashlock
# and a timelock refund. This is a simplified conceptual example.
# 1. Generate the redeem script (HTLC)
# OP_IF
# OP_SHA256 <hash> OP_EQUALVERIFY OP_DUP OP_HASH160 <pubkey> OP_EQUALVERIFY OP_CHECKSIG
# OP_ELSE
# <timeout> OP_CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160 <pubkey> OP_EQUALVERIFY OP_CHECKSIG
# OP_ENDIF
# 2. Fund the P2SH address with bgold-cli
bgold-cli sendtoaddress <p2sh_address> <amount>
# 3. Redeem by revealing the preimage
bgold-cli createrawtransaction ...
Additional developer topics¶
RPC API integration¶
BTG Core exposes a JSON-RPC API identical to Bitcoin Core's. Use bgold-cli help to list all commands. Common integration patterns:
- Block monitoring: poll
getblockcountandgetblockfor new blocks. - Transaction broadcasting: use
sendrawtransactionto relay signed txs. - Wallet operations:
getbalance,listunspent,createrawtransaction,signrawtransactionwithwallet.
Building a block explorer¶
The recommended approach is to run Blockbook (see operators/blockbook) which provides a RESTful API and a web frontend out of the box. The Blockbook indexer parses the BTG blockchain into a PostgreSQL database and exposes APIs for addresses, transactions, and blocks.
Creating a mining pool¶
Build a stratum-based mining pool using:
- node-stratum-pool — a BTG-compatible stratum implementation.
- open-ethereum-pool — adapt for BTG's Equihash-BTG (N=144, K=5) algorithm.
Smart contracts¶
BTG does not natively support Turing-complete smart contracts (no EVM). However, you can use: - Custom op_returns to embed arbitrary data on-chain. - Multi-sig wallets for cooperative custody (up to 15 of 15). - HTLC-based contract patterns for conditional payments and atomic swaps.
Development environment setup¶
# Install BTG Core from source or use a pre-built binary
sudo apt install -y build-essential libtool autotools-dev automake pkg-config \
libssl-dev libevent-dev bsdmainutils libboost-all-dev \
libminiupnpc-dev libzmq3-dev libdb-dev libdb++-dev
# Clone and build
git clone https://github.com/BTCGPU/BTCGPU.git
cd BTCGPU
./autogen.sh
./configure --without-gui --with-incompatible-bips
make -j"$(nproc)"
sudo make install
Testing and debugging¶
- regtest mode: Fast, local-only chain for rapid iteration.
- testnet v3: Public test network with faucet.
bgold-cli -generate: In regtest, instantly mine blocks.-debug=1: Enable verbose logging.-printtoconsole: Log to stdout (useful in Docker).
Further reading¶
- BTCGPU/BTCGPU — main repository.
- Bitcoin Core RPC API docs — nearly all endpoints apply to BTG.
- BIP-199 — Hashed timelock contracts (HTLC) specification.
- BIP-44 — Multi-account hierarchy for deterministic wallets.