Bitcoind and bitcoin-cli Assignment

Welcome to this assignment. Try to complete the tasks below. Feel free to discuss and ask questions in this thread.

  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?
  2. Try to execute dumpwallet in order to store keys in a file.
  3. Try to execute dumpprivkey on an address you generated with getnewaddress.
5 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 fir what the commands do?

    The description confirms what the commands do but also specify extra parameters to use with the commands.

    also with the following line you can get info about any command:
    ./bitcoin-cli -regtest help <command>
    for ex: ./bitcoin-cli -regtest help getbalance

  2. Try to execute dumpwallet in order to store keys in a file.
    ./bitcoin-cli -regtest dumpwallet "<path and filename>"

  3. Try to execute dumpprivkey on an address you generated with getnewaddress.
    ./bitcoin-cli -regtest dumpprivkey <address>

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 fit what the commands do?

They’re listed alphabetically and the description does match the action.

2. Try to execute dumpwallet in order to store keys in a file.
./bitcoin-cli -regtest dumpwallet “mykeys”

3. Try to execute dumpprivkey on an address you generated with getnewaddress.
./bitcoin-cli -regtest dumpprivkey [address]

@Capaburro listed a help feature which is very… well… helpful. Thanks

Even though the dumpwallet command was executed and even when run a second time provides information that the file exists and cannot be overwritten, I cannot find the actual file in the /daemon directory… strange. Any suggestion??

1 Like
  1. Yes they’re on the list with extra description about using an optional [account] parameter.

  2. > .\bitcoin-cli.exe -regtest dumpwallet "test_dumped_keys" The dumped file test_dumped_keys has a long list of the keys, around 2000 in fact, probably pre-generated by the -regtest mode.

  3. The private key is successfully printed to the console

> .\bitcoin-cli.exe -regtest getnewaddress
2N7CmzJhfLkD3bejEkZZgLqNGZv9PJGuXLm
> .\bitcoin-cli.exe -regtest dumpprivkey 2N7CmzJhfLkD3bejEkZZgLqNGZv9PJGuXLm
cMb7PBygXHH1zZ...
  1. Here are the commands taken from the list that I remember from previous lectures, and their description:
  • getbalance
    Returns the server’s total available balance. If an account is specified, returns the balance in the account.

  • getnewaddress
    Returns a new bitcoin address for receiving payments.

  • listunspent
    Returns array of unspent transaction inputs in the wallet.

Yes, getnewaddress and getbalance are in the list, and the description fits the examples in the videos. I just wonder why the term “array” is used, as well as “transaction inputs” instead of simply “transactions”.

  1. I executed dumpwallet in order to export private keys in a txt file I called “wallet”.

./bitcoin-cli -regtest dumpwallet "C:\Users\...\Documents\wallet.txt"

Under the message # extended private masterkey, I got a long key (more than 100 chars) which looks like a private key.

Then further below there are a lot of lines with hundreds of hashes and addresses…

  1. When I execute dumpprivkey on the bitcoin address I generated, I get a new hash, longer than the previous hash (52 chars). According to the list, it should be the private key corresponding to the address.
  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?
  1. Try to execute dumpprivkey on an address you generated with getnewaddress.

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

2 Likes

If you are having trouble using dumpwallet on Windows like I did:
error code: -8
error message:
Cannot open wallet dump file

this is what worked for me:
./bitcoin-cli -regtest dumpwallet “C:\Users\YOURUSER\Desktop\wallet”

6 Likes
  1. getnewaddress - “Returns a new bitcoin address for receiving payments.”
    getbalance - “returns the balance in the account.”
    2.bitcoin-cli -regtest dumpwallet [dumpedwalletfilename.txt]
  2. bitcoin-cli -regtest dumpprivkey [publickey]
  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?
    yess nice.

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

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

There is a new API some commands in the suggested link are depprecated. One can find the latest API calls here - https://bitcoin.org/en/developer-reference#getwalletinfo

on Ubuntu, you don’t need to type ./ before bitcoind or bitcoin-cli.
(weird)

  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?

The description fits what the commands do. The API is a lot older on that page, suggest updating the link in the assignment to: https://bitcoin.org/en/developer-reference#rpc-quick-reference

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

bitcoin-cli -regtest dumpwallet "test"

“test” is saved successfully in the directory I executed the command in

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

I did this assignment a day after doing the rest of the earlier section - so I couldn’t remember what addresses I had generated - found this neat rpc call:

bitcoin-cli -regtest listaddressgroupings

This listed all the addresses I had generated previously
I chose one of the addresses from the output and ran the command

bitcoin-cli -regtest dumpprivkey <address from output of listaddressgroupings>

It generated the private key associated with the address.

1 Like

What an exceedingly mature peace of software.
Awesome what one can learn already from the command line error handling of bitcoin-cli.
For example, using curl to directly call bitcoind instead of using bitcoin-cli.
I am excited!

yeshe ~$ 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/

  1. Both of the commands work exactly as described.

  2. dumpwallet worked by adding the following ./bitcoin-cli -regtest dumpwallet “C:___” and adding a new address in the blank space. The program then creates the file and dumps the information in the file. (hope I worded this correctly).

  3. dumpprivkey shows you the private key assosiated with the address you type in after dumpprivkey.

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.

Yes this fits the description but not described in the easiest way.

  1. WTF

  2. I did not understand this

1.Yes description is what the commands do, and also it says on getbalance command that if the account is not specified it will show the servers total available balance.
2. ./bitcoin-cli -regtest dumpwallet “C:\Users…\Desktop\dump wallet\keys.txt”
3. ./bitcoin-cli -regtest dumpprivkey

  1. What is “fir” in the question? Swedish? But yes, it DESCRIBES what it does. Except for… generate. I am working on version 0.18.1 and i had to use “generatetoaddress (walletaddress)”.
  2. PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet “C:\Users\Gebruiker\Documents\Bitcoin\paulwallet.txt”
    {
    “filename”: “C:\Users\Gebruiker\Documents\Bitcoin\paulwallet.txt”
    }
  3. PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpprivkey 2N72N9ko7LjDaizKkiL2XJd3fsGry67Xf5r
    cU1XBktBFdNNMB4Pf8GC38XRwKsUbM2kKKPmycdHKE8QDNMyeEff
  1. Yes
  2. ./bitcoin-cli -regtest dumpwallet “C:\Users\Knut\Desktop\Ivan on Tech Academy\Coding\Bitcoin\Test.txt”
  3. ./bitcoin-cli -regtest dumpprivkey 2MwGYArPEV5yLh3wtzjxXabDPvjec3hPQH8
    -> cS1YKyLr2gVErKakhzQ8TAY5MZTt9cCcbjdsxXyvfE71f2ur4xSo
  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?
    Descriptions for both entries match what was discussed.

  2. Try to execute dumpwallet in order to store keys in a file.
    A dump file with a long list of addresses was written to the file specified.

  3. Try to execute dumpprivkey on an address you generated with getnewaddress.
    Private key was displayed in the console.

  1. Yes the descriptions do fit what the commands do, although I find the phrasing “returns” for “getnewaddress” interesting as if the address is already being stored somewhere. I had the interpretation that the addresses were randomly generated, but perhaps the blockchain keeps tabs on all addresses simultaneously, or perhaps it is just a feature of more limited addresses in regtest?

  2. Took me a minute to realize I needed to designate where they would be dumped… duh haha

  3. Had an error and realized I had 1 P in “dumpprivkey” but fixed and then worked perfectly!