Bitcoind and bitcoin-cli Assignment

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 match what the commands do?
a.) getnewaddress: Produced and return a new Bitcoin address when commanded.
b.) getbalance: Returns balance of specific account.

2.) Try to execute dumpwallet in order to store keys in a file.
">./bitcoin-cli -regtest dumpwallet "C:\Users\Hector Martinez\Desktop\Wallet02.txt
Screenshot 2021-06-30 23.07.17
Screenshot 2021-06-30 23.08.48
3.) Try to execute dumpprivkey on an address you generated with getnewaddress.
">./bitcoin-cli -regtest dumpwallet “wallet address”
Screenshot 2021-06-30 23.29.25 DUMPPRIVKEY

1 Like
  1. Yes, they are listed in alphabetical order and the descriptions are deeply detailed into the functioning within the commands.
  2. ./bitcoin-cli -regtest dumpwallet “file location containing wallet”
  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 what the commands do?
    getnewaddress- yes, with the addition that you can specify the account to create the new address
    getbalance-yes, additionally you could query an account’s balance [account]

  2. Try to execute dumpwallet in order to store keys in a file.
    Error- it requires a ‘filename’ argument

  3. Try to execute dumpprivkey on an address you generated with getnewaddress.
    -generates a lengthy hash

This was helpful, thanks!

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? Yes, apart from the extra parameters we can use.
2. Try to execute dumpwallet in order to store keys in a file. .\bitcoin-cli.exe -regtest dumpwallet “path/filename”
3. Try to execute dumpprivkey on an address you generated with getnewaddress. .\bitcoin-cli.exe -regtest dumpprivkey 2ND5bFcqYn9newZCBy9CRvthTmAz7pQFh6c

1 Like
  1. Works as stated

  2. PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet
    error code: -1
    error message:
    dumpwallet “filename”

Dumps all wallet keys in a human-readable format to a server-side file. This does not allow overwriting existing files.
Imported scripts are included in the dumpfile, but corresponding BIP173 addresses, etc. may not be added automatically by importwallet.
Note that if your wallet contains keys which are not derived from your HD seed (e.g. imported keys), these are not covered by
only backing up the seed itself, and must be backed up too (e.g. ensure you back up the whole dumpfile).

Arguments:

  1. “filename” (string, required) The filename with path (either absolute or relative to bitcoind)

Result:
{ (json object)
“filename” : { (string) The filename with full absolute path
}

Examples:

bitcoin-cli dumpwallet “test”
curl --user myusername --data-binary ‘{“jsonrpc”: “1.0”, “id”:“curltest”, “method”: “dumpwallet”, “params”: [“test”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/

Then:

PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet “C:\Users\Owner\Desktop\Dumpwallet file”
error code: -8
error message:
C:\Users\Owner\Desktop\Dumpwallet file already exists. If you are sure this is what you want, move it out of the way first
PS C:\Program Files\Bitcoin\daemon>

I have no idea what to do here. How do I move it out of the way?

  1. PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest getnewaddress
    2N6SDYVFDoCHUGUqDtRAnkCXwLi6VtNkzEc
    PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpprivkey 2N6SDYVFDoCHUGUqDtRAnkCXwLi6VtNkzEc
    cUYLPgnnQKUv4npbZJtEBWepZjgiCwdJW8UFF5WDR4TBciJHY6FC
    PS C:\Program Files\Bitcoin\daemon>
1 Like

Use a different name or path for the dump file.

You know what’s funny. I actually did this right after about the 3rd try but I didn’t realize when it said filename that it created a file. At least until reading many posts. I now have about 10 dump files. Yep, I’m the new guy. Thanks. :rofl:

PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet “C:\Users\Owner\Desktop\wallet04.txt”
{
“filename”: “C:\Users\Owner\Desktop\wallet04.txt”

1 Like
  1. getnewaddress and getbalance descriptions match what they do. They also include parameters with additional info.

  2. ./bitcoin-cli -regtest dumpwallet “C: … \dump_keys” stored to new file

  3. ./bitcoin-cli -regtest getnewaddress
    bcrt1q0ptd*******3hkwafdy9

./bitcoin-cli -regtest dumpprivkey bcrt1q0ptd********3hkwafdy9
cV34AkFSvo****************8zTMaTvrX

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 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.

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

./bitcoin-cli -regtest dumpwallet walletPrivateKeys

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

./bitcoin-cli -regtest dumpprivkey 2MsspCxYh3W844AoYmbAsdM2PYz2z5g8gKM

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?

Getnewaddress ./bitcoin-cli -regtest getnewaddress
Returns a new Bitcoin address for receiving payments.
Getbalance ./bitcoin-cli -regtest getbalance
Returns the total available balance.

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

PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet “test_dump_wallet”
{
“filename”: “C:\Program Files\Bitcoin\daemon\test_dump_wallet”
}

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

PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest getnewaddress
bcrt1qm8l8v94lkl72z5r3rvs3vnxpzsrdqdtffxgta8

PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpprivkey “bcrt1qm8l8v94lkl72z5r3rvs3vnxpzsrdqdtffxgta8”
cW4Z3h5aRJZTBGXgH6vqAgVuhbbXWhDksSbYfX7fUDt151xi5M8u

1 Like
  1. Yes the description fits with what the commands do, plus an additional function for specified accounts.
  • getnewaddress [account] Returns a new bitcoin address for receiving payments. If [account] is specified payments received with the address will be credited to [account].
  • getbalance [account] [minconf=1] If [account] is not specified, returns the server’s total available balance.
    If [account] is specified, returns the balance in the account.
    • PS D:\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet “testwallet”
      {
      “filename”: “D:\Bitcoin\daemon\testwallet”
    • PS D:\Bitcoin\daemon> ./bitcoin-cli -regtest getnewaddress
      bcrt1q673450k3k9c008f02p3v2m0camx77s4r8kaxfw

    • PS D:\Bitcoin\daemon> ./bitcoin-cli -regtest dumpprivkey “bcrt1q673450k3k9c008f02p3v2m0camx77s4r8kaxfw”
      cUCgYXSGFX2Ptnt5YRkktJqufKoFU6rCcWHXDT84NM3ua6szCiD5

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, the description for getnewaddress and getbalance fit exactly what the commands do.

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

Step 1. We export all the private keys to a file by using the following commands.

PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet “C:\keys\wallet”
{
“filename”: “C:\keys\wallet”
}

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

Step 1. We generate a new address by the following command.

PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest getnewaddress
2N3Bswvahr2LfGVWxA4gwR5ejbpB2ScPwqZ

Step 2. We find out the private key of a particular public key by following command.

PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpprivkey 2N3Bswvahr2LfGVWxA4gwR5ejbpB2ScPwqZ
cUpzMduGxrHBFM6zB7rWsa118oWmbKPfJj7GUMiMRsT76VsaxZuE

1 Like
  1. Yes, the descriptions of both getbalance and getnewaddress fit what the commands do.
    They also tell you what will happen if an account is specified vs. unspecified

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

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

  2. PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet
    “C:\Users\Rob\Desktop\dumpwallet”
    {
    “filename”: “C:\Users\Rob\Desktop\dumpwallet”
    }

    This created a file on my desktop named dumpwallet.txt with the following content.

    Wallet dump created by Bitcoin v0.17.1

    * Created on 2021-08-09T19:19:03Z

    * Best block at time of backup was 104 (5a0e3985fc811a489471d68e0e71c9fc001a719e7e42675dd28981d0866181b5),

    mined on 2021-08-07T17:16:56Z

    extended private masterkey:

tprv8ZgxMBicQKsPdoqbN5Zm1DrnZTLjLpDogMsAhJZwgCaorgHHc8JuB9FqiqVCaBXsu3bh6gd43YzrdUfGYKDUTQzgQvrYyMnq3PQtp2hAuW8

cP2496wkUsu42NMV3HpRqFZmKVxsN1nQnrHXU5muNsr3C4dkdM2a 2021-08-05T14:22:33Z reserve=1 # addr=2N5W8CrqSFTn26gaAc2SyepnxgUToyA5v7i hdkeypath=m/0’/0’/281’…

I didn’t realize you had to create the name of the file you were dumping to in the powershell command line. I thought you were dumping to a pre-existing file. I tried doing it without creating a file name, just going straight to the desktop and got an error. Then I created a .txt file on the desktop and tried dumping it to that file and got an error. If anyone is struggling with this you just specify the directory that you want it to go to in bitcoin-cli and add \walletname at the end. It will create the file for you in the directory you specified.

  1. PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest getnewaddress
    2N8nZGgXHUjyQRujpkvLCwGowaqsQ5Q5S7s
    PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpprivkey
    2N8nZGgXHUjyQRujpkvLCwGowaqsQ5Q5S7s
    cNBLoDTXtAgsnwqwsRCRGF6V92d82ubmiCNeUmVR8AaP1rvGyJGk
1 Like
  1. They do exactly as the description hints. getnewaddress creates a new address that is assigned to the currently loaded wallet, and getbalance returns the total balance of either a specific wallet or (if not specified) the total balance of all the local wallets.
  2. dumpwallet doesn’t execute, if a filepath is not specified. Note that in order to dump the information in a file, the file must not exist (cannot override an existing file) and the shell user must have write access to the directory of writing.
  3. Hint: Logging private keys in the stdout might not be a good idea security-wise. Consider redirecting the key in a file: .\bitcoin-cli.exe dumpprivkey address > test.log
1 Like
  1. Yes, the commands are on the API calls list. The description match the command functionality and also describe some extra features that can be accomplished with the commands with extra input parameters.
  2. The keys are properly dumped into the specified file.
  3. The private key is properly dumped.
1 Like
  1. In the list the description of what getnewaddress and getbalance does
    is correct.

  2. ./bitcoin-cli-regtest dumpwallet “my keys”

  3. ./bitcoin-cli-regtest dumpprivkey [address]

1 Like

Dump wallet accepts path to the dump file as parameter. :slight_smile:

Thank you. I am learning more
than I’ve ever learned in my life!

1 Like

You can always check the parameters for any command by using help:

bitcoin-cli help <COMMAND>