Skip to content

Commit f6eef54

Browse files
committed
populate_mempool.sh
1 parent f232854 commit f6eef54

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

populate_mempool.sh

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#!/bin/bash
22

3-
#OP_RETURN_DATA="Hello From @RandyMcMillan $(date +%s)" # Data to embed in OP_RETURN
4-
53
# Configuration
6-
NUM_TRANSACTIONS=25 # Number of transactions to create
7-
AMOUNT_PER_OUTPUT=0.00001 # BTC amount for each recipient output
8-
INITIAL_FEE_RATE=1 # Starting fee rate in sat/vB
9-
FEE_RATE_INCREMENT=1 # Increment for fee rate per transaction
4+
NUM_TRANSACTIONS=10 # Number of transactions to create
5+
AMOUNT_PER_OUTPUT=0.00001 # BTC amount for each recipient output
6+
INITIAL_FEE_RATE=1 # Starting fee rate in sat/vB
7+
FEE_RATE_INCREMENT=1 # Increment for fee rate per transaction
108

119
echo "Starting mempool population script for testnet..."
1210
echo "Creating $NUM_TRANSACTIONS transactions, starting with fee rate $INITIAL_FEE_RATE sat/vB"
@@ -19,14 +17,14 @@ then
1917
fi
2018

2119
# Get a new address to receive change (and for initial funding if needed)
22-
CHANGE_ADDRESS=$(bitcoin-cli --testnet4 getnewaddress "mempool_filler_change")
20+
CHANGE_ADDRESS=$(bitcoin-cli --testnet4 --rpcwallet="testnet4" getnewaddress "mempool_filler_change")
2321
echo "Using change address: $CHANGE_ADDRESS"
2422

2523
# Get an initial unspent transaction output (UTXO) from your wallet
2624
# This assumes your wallet already has some funds.
2725
# If this fails, you need to fund your wallet first.
2826
echo "Searching for an initial UTXO in your wallet..."
29-
INITIAL_UTXO=$(bitcoin-cli --testnet4 listunspent 1 999999 '[]' true '{"minimumAmount":0.0001}' | jq -r '.[0]')
27+
INITIAL_UTXO=$(bitcoin-cli --testnet4 --rpcwallet="testnet4" listunspent 1 999999 '[]' true '{"minimumAmount":0.0001}' | jq -r '.[0]')
3028

3129
if [ -z "$INITIAL_UTXO" ] || [ "$INITIAL_UTXO" == "null" ]; then
3230
echo "Error: No suitable UTXO found in your wallet. Please ensure your testnet wallet has funds."
@@ -45,26 +43,25 @@ CURRENT_FEE_RATE=$INITIAL_FEE_RATE
4543
for i in $(seq 1 $NUM_TRANSACTIONS); do
4644
echo "--- Transaction $i ---"
4745

48-
OP_RETURN_DATA="mempool_recipient_$i-$(date +%s)" # Data to embed in OP_RETURN
4946
# Generate a new recipient address for each transaction
50-
RECIPIENT_ADDRESS=$(bitcoin-cli --testnet4 getnewaddress "mempool_recipient_$i-$(date +%s)")
47+
RECIPIENT_ADDRESS=$(bitcoin-cli --testnet4 --rpcwallet="testnet4" getnewaddress "mempool_recipient_$i")
5148

5249
# Create a raw transaction: spend CURRENT_UTXO, send to RECIPIENT_ADDRESS
5350
# fundrawtransaction will add the change output and calculate the fee
5451
INPUTS="[{\"txid\":\"$CURRENT_TXID\",\"vout\":$CURRENT_VOUT}]"
55-
OUTPUTS="{\"$RECIPIENT_ADDRESS\":$AMOUNT_PER_OUTPUT, \"data\":\"$(echo -n $OP_RETURN_DATA | xxd -p -c 200)\"}"
52+
OUTPUTS="{\"$RECIPIENT_ADDRESS\":$AMOUNT_PER_OUTPUT}"
5653

57-
RAW_TX_HEX=$(bitcoin-cli --testnet4 createrawtransaction "$INPUTS" "$OUTPUTS")
54+
RAW_TX_HEX=$(bitcoin-cli --testnet4 --rpcwallet="testnet4" createrawtransaction "$INPUTS" "$OUTPUTS")
5855

5956
# Fund the raw transaction, specifying the fee rate and change address
60-
FUNDED_TX_JSON=$(bitcoin-cli --testnet4 fundrawtransaction "$RAW_TX_HEX" '{"fee_rate":'$CURRENT_FEE_RATE', "changeAddress":"'$CHANGE_ADDRESS'"}')
57+
FUNDED_TX_JSON=$(bitcoin-cli --testnet4 --rpcwallet="testnet4" fundrawtransaction "$RAW_TX_HEX" "{\"fee_rate\":$CURRENT_FEE_RATE, \"changeAddress\":\"$CHANGE_ADDRESS\"}")
6158
FUNDED_TX_HEX=$(echo "$FUNDED_TX_JSON" | jq -r '.hex')
6259
FEE=$(echo "$FUNDED_TX_JSON" | jq -r '.fee')
6360

6461
echo " Fee rate: $CURRENT_FEE_RATE sat/vB, Estimated Fee: $FEE BTC"
6562

6663
# Sign the funded transaction
67-
SIGNED_TX_JSON=$(bitcoin-cli --testnet4 signrawtransactionwithwallet "$FUNDED_TX_HEX")
64+
SIGNED_TX_JSON=$(bitcoin-cli --testnet4 --rpcwallet="testnet4" signrawtransactionwithwallet "$FUNDED_TX_HEX")
6865
SIGNED_TX_HEX=$(echo "$SIGNED_TX_JSON" | jq -r '.hex')
6966
COMPLETE=$(echo "$SIGNED_TX_JSON" | jq -r '.complete')
7067

@@ -75,11 +72,11 @@ for i in $(seq 1 $NUM_TRANSACTIONS); do
7572
fi
7673

7774
# Broadcast the transaction
78-
BROADCAST_TXID=$(bitcoin-cli --testnet4 sendrawtransaction "$SIGNED_TX_HEX")
75+
BROADCAST_TXID=$(bitcoin-cli --testnet4 --rpcwallet="testnet4" sendrawtransaction "$SIGNED_TX_HEX")
7976
echo " Broadcasted TXID: $BROADCAST_TXID"
8077

8178
# Find the change output from the broadcasted transaction to use as the next UTXO
82-
DECODED_TX=$(bitcoin-cli --testnet4 decoderawtransaction "$SIGNED_TX_HEX")
79+
DECODED_TX=$(bitcoin-cli --testnet4 --rpcwallet="testnet4" decoderawtransaction "$SIGNED_TX_HEX")
8380
CHANGE_VOUT_INDEX=-1
8481
for j in $(seq 0 $(($(echo "$DECODED_TX" | jq '.vout | length') - 1))); do
8582
SCRIPT_PUB_KEY_ADDRESS=$(echo "$DECODED_TX" | jq -r ".vout[$j].scriptPubKey.address")
@@ -107,5 +104,4 @@ for i in $(seq 1 $NUM_TRANSACTIONS); do
107104
done
108105

109106
echo "Mempool population script finished."
110-
echo "You can check the mempool with: bitcoin-cli --testnet4 getrawmempool"
111-
bitcoin-cli --testnet4 getrawmempool
107+
echo "You can check the mempool with: bitcoin-cli getrawmempool"

0 commit comments

Comments
 (0)