RPC cheatsheet¶
The most useful bgold-cli calls, grouped by task. All examples assume you're talking to a local daemon with rpcuser=explorer and rpcpassword=.... Substitute the actual values.
Use jq for parsing
bgold-cli returns JSON. Pipe through jq to extract fields. Install with apt install jq.
Quick health check¶
# Is the daemon up and synced?
bgold-cli getblockchaininfo | jq '{blocks, headers, verificationprogress, chain, size_on_disk}'
# Peer count
bgold-cli getnetworkinfo | jq '{version, subversion, protocolversion, connections, networks}'
# Memory usage
bgold-cli getmemoryinfo | jq '.locked'
# Uptime
ps -o etime= -p "$(pgrep -d, bgoldd)"
Network¶
# List connected peers
bgold-cli getpeerinfo | jq '.[] | {addr, subver, version, bytessent, bytesrecv, conntime}'
# Add a static peer
bgold-cli addnode "btg.example.com:8338" "add"
# Ban a peer (forks / misbehaving)
bgold-cli setban "1.2.3.4" "add" 86400
# List bans
bgold-cli listbanned
Blocks¶
# Current tip
bgold-cli getbestblockhash
bgold-cli getblockcount
# Block by height
HASH=$(bgold-cli getblockhash 800000)
bgold-cli getblock "$HASH" | jq '{height, hash, confirmations, time, nTx: .tx | length}'
# Block by hash
bgold-cli getblock "00000000abc..." | jq '.difficulty'
# Block header only (smaller payload)
bgold-cli getblockheader "00000000abc..." | jq '{height, merkleroot, time, bits, difficulty}'
Transactions¶
# Look up a tx
bgold-cli getrawtransaction "txid" 1 | jq
# Decode a raw tx
bgold-cli decoderawtransaction "0200000001..."
# Send a tx
bgold-cli sendtoaddress "GYf8nyo1c8oWsHzbvL1fD3Ckgg68UzBi5J" 0.5
# Create + sign + send (full control)
UTXO=$(bgold-cli listunspent | jq -c '.[] | select(.amount > 1) | {txid, vout}' | head -1)
TXID=$(echo "$UTXO" | jq -r .txid)
VOUT=$(echo "$UTXO" | jq -r .vout)
RAW=$(bgold-cli createrawtransaction "[{\"txid\":\"$TXID\",\"vout\":$VOUT}]" \
"{\"GYf8nyo1c8oWsHzbvL1fD3Ckgg68UzBi5J\":0.5}")
SIGNED=$(bgold-cli signrawtransaction "$RAW" | jq -r .hex)
bgold-cli sendrawtransaction "$SIGNED"
Mempool¶
# Mempool summary
bgold-cli getmempoolinfo | jq '{size, bytes, usage, maxmempool, mempoolminfee}'
# All tx in mempool
bgold-cli getrawmempool
# Mempool entry detail
bgold-cli getmempoolentry "txid" | jq '{wtxid, vsize, time, fees, depends}'
Mining¶
# Network hashrate estimate
bgold-cli getnetworkhashps 120 # 120-block window
# Mining info
bgold-cli getmininginfo | jq '{blocks, difficulty, networkhashps, pooledtx, chain}'
# Block template
TEMPLATE=$(bgold-cli getblocktemplate '{"rules":["segwit"]}')
echo "$TEMPLATE" | jq '{height, target, mintime, curtime, bits}'
Wallet¶
# Get a new receive address
bgold-cli getnewaddress "" "bech32" # native segwit
bgold-cli getnewaddress "" "p2sh-segwit" # wrapped segwit
bgold-cli getnewaddress "" "legacy" # P2PKH
# Balance
bgold-cli getbalance
bgold-cli getbalances | jq
# Unspent outputs
bgold-cli listunspent | jq '.[] | {txid, vout, amount, address, confirmations}'
# Backup
cp ~/.bitcoingold/wallet.dat /backup/wallet-$(date +%F).dat
# Dump all private keys (DANGER)
bgold-cli dumpprivkey "GYf8nyo1c8oWsHzbvL1fD3Ckgg68UzBi5J"
# Import a private key
bgold-cli importprivkey "L1aW4aubDFB7yfras2S1mKx8jJ..." "" false
Chain info¶
# Difficulty
bgold-cli getdifficulty
# Txoutset summary
bgold-cli gettxoutsetinfo | jq
# Total supply (in satoshis)
bgold-cli gettxoutsetinfo | jq '.total_amount'
v0.17.3 specific¶
# Finalized block (rolling checkpoint)
bgold-cli getfinalizedblockhash
# Block subsidy at a given height
bgold-cli getblocksubsidy 800000
# Chain tips (in case of a recent reorg)
bgold-cli getchaintips | jq '.[] | {height, hash, status, branchlen}'
Useful one-liners¶
# Last 10 block heights + hashes
for h in $(seq $(($(bgold-cli getblockcount) - 9)) $(bgold-cli getblockcount)); do
bgold-cli getblockhash $h
done | xargs -I {} sh -c 'echo "{} $(bgold-cli getblock {} | jq .height) $(bgold-cli getblock {} | jq -r .time | xargs -I {} date -d @{} +%FT%TZ)"'
# Top 10 addresses by balance (requires indexing)
bgold-cli listaddressgroupings | jq '.. | .address? // empty' | sort -u | head
HTTP form¶
Every RPC can be called over HTTP. Useful for shell scripts without bgold-cli.
curl -u explorer:PASSWORD \
-H 'Content-Type: application/json' \
-d '{"id":1,"method":"getblockchaininfo","params":[]}' \
http://127.0.0.1:8332 | jq
Error handling¶
bgold-cli returns an error object in JSON on failure:
Common error codes:
| Code | Meaning |
|---|---|
| -1 | Generic JSON-RPC parse error |
| -5 | Invalid address / parameter |
| -6 | Insufficient funds |
| -8 | Transaction not found |
| -28 | Loading… (initial sync not complete) |
| -32601 | Method not found (typo, version-specific) |
If you see -28 a lot, your node is still syncing. Wait.
Source¶
- Bitcoin Core RPC docs — the BTC version applies; Bitcoin Gold (BTG) adds a few coin-specific methods.
bgold-cli help— auto-generated from the binary.bgold-cli help <method>— detailed parameter docs.