Bitcoind and bitcoin-cli Assignment

:one: We have already used some commands in previous lectures, let’s find them in the list and verify how they are described. Can you find getnewaddress and getbalance in the list? Does the description for what the commands do?

  • getnewaddress: Returns a new bitcoin address for receiving payments. If [account] is specified payments received with the address will be credited to [account].
  • getbalance: If [account] is not specified, returns the server’s total available balance.
    If [account] is specified, returns the balance in the account.

:two: Try to execute dumpwallet in order to store keys in a file.

Code to execute dumpwallet:

./bitcoin-cli -regtest dumpwallet "C:\Users\Jack\Downloads\dumpfile"

Output:

{
  "filename": "C:\\Users\\Jack\\Downloads\\dumpfile"
}

:three: Try to execute dumpprivkey on an address you generated with getnewaddress.

  1. Code To get New Address: ./bitcoin-cli -regtest getnewaddress
    => Output: 2NAqwPpZjRprSZ339Sf2pcWnxsv9NXK9AT7
  2. Code To Dump Private Key: ./bitcoin-cli -regtest dumpprivkey 2NAqwPpZjRprSZ339Sf2pcWnxsv9NXK9AT7
    => Output: cUjjchWcae4qt9GUFSPRX6mUQx4tSDt8e3HPwtGV82LezYZhXX3C
2 Likes
  1. Yes, they both can be found in the command table and the description makes sense
  2. dumpwallet exports all private keys to a file
  3. dumpprivkey shows the private key of the address that was generated using getnewaddress
1 Like

1. We have already used some commands in previous lectures, let’s find them in the list and verify how they are described. Can you find getnewaddress and getbalance in the list? Does the description for what the commands do?
I believe this question is asking if the description does what we are familiar with the commands doing, and the answer is yes.
2. Try to execute dumpwallet in order to store keys in a file.
Very interesting!

./bitcoin-cli -regtest dumpwallet

3. Try to execute dumpprivkey on an address you generated with getnewaddress.
ahh I tried and could not figure this out

1 Like

What trouble did you had? You just have to use the newly generated address as a parameter to dumpprivkey to get the private key.

  1. Yes, it works.
  2. For me to get this to work, I had to include the pathway after ‘dumpwallet’. Plus, the pathway had to include ‘xxx.txt’ (name of the text file)
  3. Yes, this worked. Only frustration was that I couldn’t paste from the output of the command line. I only to retype the address.
1 Like

We have already used some commands in previous lectures, let’s find them in the list and verify how they are described. Can you find getnewaddress and getbalance in the list? Does the description fir what the commands do?

getnewaddress
Returns a new bitcoin address for receiving payments.
If [account] is specified payments received with the address will be credited to [account].

getbalance
If [account] is not specified, returns the server’s total available balance.
If [account] is specified, returns the balance in the account.

Try to execute dumpwallet in order to store keys in a file.
C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet “C:\Program Files\Bitcoin\daemon\mywallet.txt”

Try to execute dumpprivkey on an address you generated with getnewaddress.
C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpprivkey 2N7dqicRJjr2jDyD6PfNsuDDMwgs9ErjxWe

1 Like
  1. We have already used some commands in previous lectures, let’s find them in the list and verify how they are described. Can you find getnewaddress and getbalance in the list? Does the description fit what the commands do?
    Found both commands on the list, and indeed the description of what they do is spot on.

  2. Try to execute dumpwallet in order to store keys in a file.
    This command exports all wallet private keys to a file.

  3. Try to execute dumpprivkey on an address you generated with getnewaddress.
    This command reveals the private key belonging to the new address.

1 Like
  1. Yes

getnewaddress returns a new bitcoin address controlled by the same wallet (account)
getbalance returns the total balance for the account - we can use an extra parameter as we did on the course for minimum confirmations - if we add 0 it will provide balance including unconfirmed transactions

  1. ./bitcoin-cli -regtest dumpwallet testwallet - this command exported my private keys into a txt file

  2. ./bitcoin-cli -regtest dumpprivkey bcrt1qcp7p2v8xkzjn2pm75r78kfq9sdllx0j32kcy47 returned the private key of this address

1 Like
  1. Descriptions reasonably match the commands for both getnewaddress and getbalance
  2. This can be done by entering this command in powershell ./bitcoin-cli -regtest dumpwallet “filename”`
  3. This can be done by entering these commands in powershell
    ./bitcoin-cli -regtest getnewaddress
    ./bitcoin-cli -regtest dumpprivkey [bitcoinaddress]
1 Like
  1. We have already used some commands in previous lectures, let’s find them in the list and verify how they are described. Can you find getnewaddress and getbalance in the list? Does the description for what the commands do?

The description of for both bitcoin commands matches what they do.

  1. Try to execute dumpwallet in order to store keys in a file.

Trying to execute ./bitcoin-cli -regtest dumpwallet returns error code “-1” because it requires a filename where to dump the information requested.

Executing ./bitcoin-cli -regtest dumpwallet “C:********” with a new file path creates a file with all the dumped information for the wallet.

  1. Try to execute dumpprivkey on an address you generated with getnewaddress. requires the argument (new address)

Executing ./bitcoin-cli -regtest dumpprivkey ************************* returned:

cTrrmah8r65qQsf4PMv87jM35PRoHw5cC4cM5KZmac4FTfnWWuPL

2 Likes
  1. We have already used some commands in previous lectures, let’s find them in the list and verify how they are described. Can you find getnewaddress and getbalance in the list? Does the description for what the commands do?

Yes I can but first I had to create and load a wallet with the following commands:

./bitcoin-cli -regtest createwallet wallet
./bitcoin-cli -regtest loadwallet wallet

  1. Try to execute dumpwallet in order to store keys in a file.

./bitcoin-cli -regtest dumpwallet “C:\temp\walletdump.txt”

  1. Try to execute dumpprivkey on an address you generated with getnewaddress.

./bitcoin-cli -regtest dumpprivkey “private key”

2 Likes
  1. We have already used some commands in previous lectures, let’s find them in the list and verify how they are described. Can you find getnewaddress and getbalance in the list? Does the description for what the commands do?

The description of the command match the action they are doing. That’s fantastic!

  1. Try to execute dumpwallet in order to store keys in a file.

./bitcoin-cli -regtest dumpwallet “C:\Users\jsnev\AppData\Roaming\Bitcoin\regtest\wallets_dump.txt”

  1. Try to execute dumpprivkey on an address you generated with getnewaddress.

./bitcoin-cli -regtest dumpprivkey “bcrt1qp0lsru4uw389wm9ddfwad3vhcfn35n07jvcjl0”

1 Like

Answers

  1. Yes, we can find getnewaddress and getbalance on the list and it also describes what the commands do.

  2. ./bitcoin-cli -regtest dumpwallet “filename”

  3. ./bitcoin-cli -regtest dumpprivkey “address”

1 Like
  1. We have already used some commands in previous lectures, let’s find them in the list and verify how they are described. Can you find getnewaddress and getbalance in the list? Does the description fir for what the commands do?
    Yes.
    Getnewaddress - Returns a new bitcoin address for receiving payments. If [account] is specified payments received with the address will be credited to [account].
    getbalance - If [account] is not specified, returns the server’s total available balance.
    If [account] is specified, returns the balance in the account.

  2. Try to execute dumpwallet in order to store keys in a file.
    Done, thanks to Sabine’s suggestion

  3. Try to execute dumpprivkey on an address you generated with getnewaddress.
    Done - pretty simple :slight_smile:

1 Like
  1. The commands were found on the list, and the description matches what the commands were used for to get a new address and to get wallet balances.
    2 Tried to execute dumpwallet but kept getting error message and do not have enough experience yet to figure out the problem.
    PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet
    error code: -1
    error message:
    dumpwallet “filename”
  2. Had the same problem as above.

You have to provide the filename to dump the wallet to.

1. We have already used some commands in previous lectures, let’s find them in the list and verify how they are described. Can you find getnewaddress and getbalance in the list? Does the description for what the commands do?

Screenshot 2022-03-29 at 08.54.19
Returns a new bitcoin address for receiving payments. If [account] is specified payments received with the address will be credited to [account].

Screenshot 2022-03-29 at 08.57.15
If [account] is not specified, returns the server’s total available balance.
If [account] is specified, returns the balance in the account.

Both make sense, the list is also very helpful to find extra options in the commands.

@Capaburro post on top was also helpful! As i first installed the latest Bitcoin core, but some things showed in the course have being outdated. Then i moved to just install the Bitcoin Core 17.1 which is the version the course was recorded with. (But then i don’t learn the updated correct way) So the help for all commands is very useful. This way i can figure out what changed since the course was recorded without having to waste time on google.

2. Try to execute dumpwallet in order to store keys in a file.

./bitcoin-cli -regtest dumpwallet "path and filename"

This worked and stored the file in the desired location.

3. Try to execute dumpprivkey on an address you generated with getnewaddress.

I did this from a fresh regtest. The commands are as follows :

    1. Run Bitcoind in regtest.
./bitcoind -regtest
    1. Run bitcoind-cli in regtest and create new address.
./bitcoin-cli -regtest getnewaddress

Returns new address. “2N7CmzJhfLkD3bejEkZZgLqNGZv9PJGuXLm
cMb7PBygXHH1zZ”

    1. Print private key to console.
./bitcoin-cli -regtest dumpprivkey 2N7CmzJhfLkD3bejEkZZgLqNGZv9PJGuXLm
cMb7PBygXHH1zZ

Prints private key to the console.

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
Question : I found myself deleting and reinstalling Bitcoin core, because after some tinkering with the commands eventually i get errors for the basics. After some googling, i found that the best way to start a fresh regtest is to delete the data in the “roaming” folder. However, having done this a couple of times. It does not appear to reset everything. Anybody have a tip on how to quickly start fresh when i mess things up?

1 Like
  1. We have already used some commands in previous lectures, let’s find them in the list and verify how they are described. Can you find getnewaddress and getbalance in the list? Does the description for what the commands do?
    Yes commands are on the list and they do what it says, plus there’s description.
  2. Try to execute dumpwallet in order to store keys in a file.
    ./bitcoin-cli -regtest dumpwallet “finename - where it should be stored”
  3. Try to execute dumpprivkey on an address you generated with getnewaddress
    ./bitcoin-cli -regtest dumpprivkey “ctrl+c address generated with command getnewaddress” (without " ")
1 Like

Hmm, removing the data folder should completely restart the node, as if it was ran the first time. I’m not aware of any other folder that would contain any user data. You can try removing the folder entirely in case there are hidden files inside, the node should create a new folder as soon as you run it for the first time.

1 Like

Thank you @Alko89.

I deleted the entire bitcoin folder in LocalAppData. And have not gotten a error since.
It does seem i did something else wrong before. No clue what it was though.