-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·27 lines (20 loc) · 841 Bytes
/
init.sh
File metadata and controls
executable file
·27 lines (20 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
# Set bitcoin-cli with regtest option as a variable for simplicity
BITCOIN_CLI="bitcoin-cli -regtest"
# Try to create the wallet "testwallet"
WALLET_CREATE_RESULT=$($BITCOIN_CLI createwallet "testwallet" 2>&1)
# If the wallet already exists, load it
if [[ $WALLET_CREATE_RESULT == *"Database already exists"* ]]; then
echo "Wallet 'testwallet' already exists. Loading it..."
$BITCOIN_CLI loadwallet "testwallet"
fi
# Get a new address from "testwallet"
NEW_ADDRESS=$($BITCOIN_CLI -rpcwallet=testwallet getnewaddress)
# Check for valid address before proceeding
if [[ -z $NEW_ADDRESS ]]; then
echo "Failed to get a new address."
exit 1
fi
# Generate 300 blocks, sending the block reward to the new address
$BITCOIN_CLI generatetoaddress 300 $NEW_ADDRESS
echo "Generated 300 blocks to address: $NEW_ADDRESS"