Build and inspect a Bitcoin transaction on local regtest
Use isolated Bitcoin Core wallets to generate practice coins, construct, fund, decode and sign a transaction, then mine its confirmation.
The quick answer
Regtest is a private test chain you control. You can create valueless practice coins and mine blocks on demand, making it useful for learning transactions without using mainnet funds.
Each stage changes what the transaction can do
An output request becomes a funded transaction after inputs and change are added. Signing authorizes the spend. Mempool acceptance is a policy check, broadcast submits it, and mining records it in a local block. These are separate steps.
Before you start
- Verified Bitcoin Core with bitcoind and bitcoin-cli available in your PATH.
- Linux or macOS with Bash, mktemp and jq installed.
- One terminal session kept open for all commands and variables.
- Local TCP port 19443 free for this isolated test node.
Step by step
- 1
Start an isolated test chain
Use the test-only commands below in one Bash session with a fresh data directory. Confirm that getblockchaininfo reports regtest before creating wallets.
- 2
Construct and sign a payment
Create two practice wallets, mine spendable coins and prepare a 1-BTC test payment. Inspect the funded inputs, change and fee before signing.
- 3
Submit and confirm it
Check local mempool acceptance, submit the signed transaction and mine one block. Compare the receiver’s pending and confirmed balances, then stop the test node.
Worked example
The miner wallet spends a generated 50-BTC practice output. The receiver gets 1 BTC, the wallet creates change and the difference becomes the fee. None of these regtest coins can be transferred to Bitcoin mainnet.
Detailed walkthrough
TEST ONLY: start a fresh isolated regtest node
Run these commands only for the local practice chain. The temporary directory separates its wallets and chain data from any normal Core installation. Peer listening and outbound connections are disabled; RPC binds to the local computer. The labcli function always supplies regtest, the fresh directory and the dedicated RPC port. Keep this Bash session open because later commands depend on its variables.
The first response must contain chain: regtest and, for this fresh chain, blocks: 0. Stop if it reports another chain or the daemon fails to start. Port conflicts must be resolved rather than silently connecting a command to a different node. Authentication uses Core’s cookie in the isolated data directory; do not copy or publish it.
LAB_DATADIR="$(mktemp -d -t bitcoin-regtest.XXXXXX)"
chmod 700 "$LAB_DATADIR"
bitcoind -regtest -datadir="$LAB_DATADIR" -daemon -server -listen=0 -connect=0 -dnsseed=0 -rpcbind=127.0.0.1 -rpcallowip=127.0.0.1 -rpcport=19443
labcli() { bitcoin-cli -regtest -datadir="$LAB_DATADIR" -rpcport=19443 "$@"; }
labcli -rpcwait getblockchaininfoCreate practice wallets and mature a coinbase output
Create a miner wallet to receive generated coins and a receiver wallet for the payment. These are disposable descriptor wallets with local signing keys. Their names are technical identifiers used throughout the commands. Generate an address in the miner wallet, then mine 101 blocks to it. On a fresh regtest chain, this makes the earliest 50-BTC coinbase output spendable.
Newly generated rewards have a maturity rule; seeing many immature coins does not mean they can all be spent immediately. The miner’s getbalance result should be 50.00000000 at this checkpoint. Hashes and addresses vary on every run. Do not copy someone else’s example address into the commands, and do not treat the large practice balance as a mainnet mining result.
labcli -named createwallet wallet_name=miner descriptors=true
labcli -named createwallet wallet_name=receiver descriptors=true
LAB_MINER_ADDRESS="$(labcli -rpcwallet=miner getnewaddress "" bech32)"
labcli generatetoaddress 101 "$LAB_MINER_ADDRESS"
labcli -rpcwallet=miner getbalance
LAB_RECEIVE_ADDRESS="$(labcli -rpcwallet=receiver getnewaddress "" bech32)"Construct the request, then add inputs and change
Build a JSON output request with jq so the generated receive address is inserted correctly. The 1.00000000 value is in BTC, while the fundrawtransaction fee_rate option below is in sat/vB. createrawtransaction initially has no inputs; this is only a transaction skeleton. The funding operation selects wallet coins and adds change without broadcasting or signing the transaction.
Inspect the returned fee and changepos and decode the funded hexadecimal data. Expect an input referencing a generated transaction and outputs for 1 BTC plus change. The fee is not a separate output; input value minus all output values pays it. Confirm the recipient matches LAB_RECEIVE_ADDRESS. Output ordering can vary, so use changepos rather than assuming change is always last.
LAB_OUTPUTS="$(jq -nc --arg address "$LAB_RECEIVE_ADDRESS" '[{($address):1.00000000}]')"
LAB_RAW="$(labcli createrawtransaction '[]' "$LAB_OUTPUTS")"
LAB_FUNDED="$(labcli -rpcwallet=miner fundrawtransaction "$LAB_RAW" '{"fee_rate":2,"replaceable":true}')"
LAB_FUNDED_HEX="$(printf '%s' "$LAB_FUNDED" | jq -r '.hex')"
printf '%s\n' "$LAB_FUNDED" | jq '{fee,changepos}'
labcli decoderawtransaction "$LAB_FUNDED_HEX"Sign the funded transaction and test local acceptance
The miner wallet controls the selected input and can sign this disposable transaction. Check the complete field before extracting its hex. A false value means required authorization is missing; broadcasting incomplete data will not repair it. In a real hardware or multisig workflow, the corresponding stage would require the appropriate external signing process rather than placing production secrets in a Core test wallet.
testmempoolaccept checks this node’s current policy without submitting the transaction. Expect allowed: true for the signed transaction in this fresh lab. An accepted test is not a confirmation or a guarantee of acceptance by every other node. This exercise has no external peers, so its result describes only your isolated node at this moment.
LAB_SIGNED="$(labcli -rpcwallet=miner signrawtransactionwithwallet "$LAB_FUNDED_HEX")"
printf '%s\n' "$LAB_SIGNED" | jq '{complete}'
LAB_SIGNED_HEX="$(printf '%s' "$LAB_SIGNED" | jq -r '.hex')"
labcli testmempoolaccept "[\"$LAB_SIGNED_HEX\"]"Submit, observe the mempool and mine confirmation
sendrawtransaction submits the signed transaction and returns its transaction ID. getmempoolentry should now find that ID. Before mining, the receiver’s getbalances response should show 1 BTC under untrusted_pending. This distinguishes a received unconfirmed payment from the trusted balance after a block. The miner’s change may already be treated as trusted under wallet rules; that does not give the receiver a confirmation.
Generate one more block to the miner address, then query the receiver’s transaction. Expect amount: 1.00000000 and confirmations: 1. Its getbalance should become 1.00000000, and getrawmempool should be empty in this isolated exercise. Mining a block is a separate action from broadcasting; on mainnet you cannot produce a confirmation on demand.
LAB_TXID="$(labcli sendrawtransaction "$LAB_SIGNED_HEX")"
labcli getmempoolentry "$LAB_TXID"
labcli -rpcwallet=receiver getbalances
labcli generatetoaddress 1 "$LAB_MINER_ADDRESS"
labcli -rpcwallet=receiver gettransaction "$LAB_TXID"
labcli -rpcwallet=receiver getbalance
labcli getrawmempoolReview the evidence and stop the practice node
Compare the decoded input and output totals with the fee returned during funding. Record which action first created signatures, which action entered the mempool and which action changed the confirmation count. These checkpoints are more useful than memorizing a long hexadecimal transaction. You can repeat the lab using a fresh directory to obtain a clean starting state.
Stop the daemon cleanly through the same wrapper. Keep the temporary directory if you want to inspect the disposable wallet history later. It contains practice private keys and authentication data, so do not reuse its wallets or copy its configuration into a production setup. A later terminal will need the original directory path and matching connection options; shell variables do not survive automatically.
labcli stopTroubleshooting
| Problem | Likely cause | What to do |
|---|---|---|
| RPC cannot connect | The daemon is not ready, failed to start or port 19443 is occupied. | Check the daemon result and isolated debug log, then verify the directory and port match the wrapper. |
| The wallet reports insufficient funds | Coinbase outputs have not matured or commands targeted the wrong wallet. | Check regtest height 101 and the miner wallet’s confirmed spendable balance. |
| jq reports invalid JSON or an address is empty | A command failed or a different shell session lost the variables. | Stop and inspect the preceding result; rerun the lab in order in one Bash session. |
| The transaction remains unconfirmed | Submission does not generate a block on regtest. | Confirm it is in the local mempool, then run the one-block generation step. |
Before you continue
A related question
Do I need a faucet or another participant?
No. This lab mines its own local regtest blocks. It does not connect to signet, testnet or mainnet peers.
More questions
Can I send these coins to a mainnet address?
No. Regtest is a separate chain with valueless local coins. Keep the chain selection and all generated addresses within this exercise.
Why create the raw transaction with no inputs?
It separates the requested payment outputs from wallet funding. fundrawtransaction then selects real practice inputs and adds change before signing.
Why use an explicit fee rate on an empty test chain?
A new regtest chain lacks the fee-market history needed for a useful estimator. The fixed practice rate makes this lab reproducible and says nothing about current mainnet fees.
Try it with a tool
Sources & further reading
Source links checked on 16 Oct 2026. Examples explain the mechanics; provider fees and features can change.
- Bitcoin Core: regression test mode developer.bitcoin.org
- Bitcoin Core: RPC interface and authentication github.com
- Bitcoin Core 31: createwallet bitcoincore.org
- Bitcoin Core 31: createrawtransaction bitcoincore.org
- Bitcoin Core 31: fundrawtransaction bitcoincore.org
- Bitcoin Core 31: signrawtransactionwithwallet bitcoincore.org
- Bitcoin Core 31: testmempoolaccept bitcoincore.org
- Bitcoin Core 31: sendrawtransaction bitcoincore.org
- Bitcoin Core 31: getbalances bitcoincore.org
- Bitcoin Core 31: gettransaction bitcoincore.org
- Bitcoin Core: generatetoaddress github.com