Skip to content

Repository files navigation

testnet-examples

Small, runnable code examples for the Bitcoin, Litecoin, and Monero testnets.

The companion code repo to TestnetHub. TestnetHub teaches the concepts; this repo is where you run them against real test networks. Every example is short, heavily commented, and does one thing. Nothing here touches real money.

Each recipe comes in Python (python/) and JavaScript / Node (javascript/). The read-only ones need no node and no keys: they call TestnetScan's public, CORS-enabled, Esplora / mempool.space compatible API. The node recipes talk to your own bitcoind / litecoind / monerod.

Recipes

#RecipeNeedsTestnetHub guide
00New key + addresssee fileKeys & seeds
01Current block heightAPI onlyRead the chain
02Address balance + UTXOsAPI onlyUTXOs
03Fee estimatesAPI onlyFees
04Mempool summaryAPI onlyFees
05Broadcast a signed transactionAPI onlyBroadcast a raw tx
06Watch a transaction confirmAPI onlyConfirmations
07Talk to a node over RPCa nodeRun a node
08Build, sign, and send a transactionsee fileBuild a testnet app
09Monero daemon info (stagenet)monerodMonero
10Decode and visualize a transactionAPI onlyRead the chain
11Fetch and visualize a blockAPI onlyRead the chain
12Monero block/tx, and what stays hiddenmonerodMonero
13Monero wallet: address, balance, view keymonero-wallet-rpcMonero
14Write a message on-chain (OP_RETURN)see fileBroadcast a raw tx
15Address types from one key (Legacy, SegWit, Taproot)see fileKeys & seeds

Guided walkthroughs

  • End to end: chain the recipes into one flow, from a fresh key to a confirmed transaction, in both languages.
  • Regtest: run a private local chain where you mine blocks on demand and confirmations are instant.

The API in one line

Base URL: https://testnetscan.com/{net}/api/ where {net} is btc-testnet4 or ltc-testnet. Example: curl https://testnetscan.com/btc-testnet4/api/blocks/tip/height. It follows the Esplora / mempool.space conventions.

Run it

Python (3.8+):

cd python
pip install -r requirements.txt # just `requests`
python 01_tip_height.py

JavaScript (Node 18+, uses built-in fetch):

cd javascript
node 01_tip_height.js
# recipes 00, 08, 14, and 15 need libraries: npm install

Get testnet coins to play with from CypherFaucet. Need a wallet or a node first? See the TestnetHub guides.

Safety

Testnet coins are worth nothing, which is the whole point: experiment freely. Even so, never put a real seed phrase, private key, or mainnet address into these scripts. Generate fresh testnet keys. See why testnet coins have no value.

License

MIT so you can lift any snippet straight into your own project. Part of the Tech1k testnet ecosystem.

About

Small, runnable code examples for the Bitcoin, Litecoin, and Monero testnets, in Python and JavaScript. The companion code repo to TestnetHub.com

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages