Bitcoind and bitcoin-cli Assignment

Hello sir, good jobs with the answers :slight_smile:.

I see you find yourself with some error code with dumpwallet & dumpprivkey commands, you might check this one to give you a better idea on how to use them:
bitcoin-cli examples.

Also remember you can use the Bitcoin Developers Examples to even have a better understanding on those commands and more.
PD: i suppose you have the bitcoind daemon running on a different powershell window in order to use properly the bitcoin-cli.

Any doubt you may have, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Hello and thank you for the heads up on my errors
Yes, i had the bitcoind daemon running on a different powershell window to bitcoin-cli also I had to run another bitcion-cli in order to practice and finally solve my errors. it is a matter of practice and perseverance

thanks again !

best regards

1 Like

Wallet dump created by Bitcoin v0.19.1
Created on 2020-05-13T10:29:59Z
Best block at time of backup was 320 (03ce3f02cd6001dc3970b271d993456b966e91cc8c4ee285508d625d9c70507b),
mined on 2020-05-13T10:03:53Z

extended private masterkey: tprv8ZgxMBicQKsPdLqpLWLoqbEL6eSvw496hqfXVDkEgmDvRxQ6X3jLB2mfmRN6Zjx9sdP4MqJmzBD83AHMsrKSbpybcz4UWdYuCUbdVYezMC2

➜ ~ bitcoin-cli -regtest dumpprivkey 2NDbnsyeE8udY7TiJDZNUvE9hJwpE9FQhvf
cSP9MZfyzKPbDVfh4CM8hkFzjAm8Kiwhzi8fTHKYpRenbBbKKqEB

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?
  • Those commands do exactly what they are described to do in the API call list.
  1. Try to execute dumpwallet in order to store keys in a file.
  • ./bitcoin-cli -regtest dumpwallet “C:\Users\Arthimis\Documents\SCHOOL\Ivan On Tech\regtestwallet2.txt”
  1. Try to execute dumpprivkey on an address you generated with getnewaddress.
  • ./bitcoin-cli -regtest dumpprivkey 2Mxob6q4dY338ERvbHrpi14PNRmd8oP5pK4
    -> cQUshLmyXqEZWsEyeoUwKHkzzmasN8RtExMXbvea6QhGww2Hgh6w
1 Like
  1. In the description, we can know that adding more parameter we can have more data return from the function.

  2. Done

  3. Done

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.

Hello sir, could you please post which are the commands that you use?

If you have any doubt, please let us know so we can help you! :slight_smile:

Carlos Z.

Assignment

Check this site (https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list).
It lists all the different command we can give to bitcoind through bitcoin-cli.

  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?
  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.
    Leave your answers here: https://forum.toshitimes.com/t/bitcoind-and-bitcoin-cli-assignment/7920

a. Can you find getnewaddress and getbalance in the list? Yes

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

Getbalance
PS C:\Program Files\bitcoin\daemon> ./bitcoin-cli -regtest getbalance
199.99994880

b. Does the description fir what the commands do? Yes

Dumpwallet

a. Can you run the command Dumpwallet ? No
Receive an error -1 as indicated below

https://bitcoin-rpc.github.io/en/doc/0.16.0/rpc/wallet/dumpwallet/

I also tried a second option. Please Option 1 and 2

Option1

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/

Option 2

b. Can you run the command Dumpwallet [Filename]? No
Receive an error -8 as indicated below

PS C:\Program Files\bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet 2MvwJwUBLwjw3mBUVa4cD3qHquXZFistXak

error code: -8
error message:
Cannot open the wallet dump file

I confirmed that the file exists
C:\Users\DEV\AppData\Roaming\Bitcoin\wallets\wallet.dat
I opened the .dat with note++ but it is unreadable (Engrypted)

I researched the reason. It is leading me in a different direction

https://bitcoincore.org/en/doc/0.16.0/rpc/wallet/importwallet/

PS C:\Program Files\bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet test

error code: -8
error message:
Cannot open wallet dump file

https://bitcointalk.org/index.php?topic=5230883.0

Talks about a replacing the dump File. Hoop it will be addressed in the next lesson

Dumpprivkey

Please see Option 1 and 2
a. Can you run the command Dumpprivkey ? No
Receive an error -1 as indicated below

Option 1

PS C:\Program Files\bitcoin\daemon> ./bitcoin-cli -regtest dumpprivkey

error code: -1
error message:
dumpprivkey “address”

Reveals the private key corresponding to ‘address’.
Then the importprivkey can be used with this output

Arguments:

  1. address (string, required) The bitcoin address for the private key

Result:
“key” (string) The private key

Examples:

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

Option2

b. Can you run the command Dumpprivkey ? Yes
Receive an Key

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

cSukhep6bQXZEzZ5KgPMytuPCyyHQ9j49Sh3rZf2WeYimby3nCuB

1 Like

Hello sir, the issue is that you have to indicate in which folder you want to dump the wallet file, so the command should be something like this:

./bitcoin-cli -regtest dumpwallet "[folderLocation]"

An example that should work for you is:

./bitcoin-cli -regtest dumpwallet "C:\User\DEV\Desktop\walletName.txt"

It will work if your User name is DEV, so you are pointing to save a “walletName.txt” file to your desktop.

Try it and let me know if it works for you.

Hope you find this useful! :slight_smile:

If you have any doubt, please let us know so we can help you!

Carlos Z.

  1. The description does fit what the commands do, but they also offer options that can be specified if desired. In both cases, the option is to specify an account.

  2. When dumpwallet executed, a file with many private and public keys was created in the location specified.

  3. When dumpprivkey executed, the terminal returned a private key. It matches the one in dumpwallet file that is paired with the public address that Id entered.

1 Like

Dear Carlos

Thank for your reply and the assistance

Can you run the command Dumpwallet [Filename]? Yes

Kind Regards

Ernst

image005.jpg

image006.jpg

1 Like
  1. Yes, exactly what I expected

  2. ./bitcoin-cli -regtest dumpwallet “test2”
    Returned a file with a number of public addresses and their private keys

  3. ./bitcoin-cli -regtest dumpprivkey “bcrt1qe53snle8466knejp43ap2049xxk54p9nh3y53j”
    Returned the privat key of the address

1 Like

1a. getnewaddress

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

1b. getbalance

If an account is not specified, returns the server’s total available balance
If an account is specified, returns the balance in the account

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

Johns-MacBook-Pro:~ johnhokkanen$ bitcoin-cli -regtest dumpwallet privatekeys
{
"filename": "/Users/johnhokkanen/privatekeys"
}

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

Johns-MacBook-Pro:~ johnhokkanen$ bitcoin-cli -regtest getnewaddress

2NA1HRC43UDdHGKSGLfF5EowxTrvxYQpaYX

Johns-MacBook-Pro:~ johnhokkanen$ bitcoin-cli -regtest dumpprivkey 2NA1HRC43UDdHGKSGLfF5EowxTrvxYQpaYX

cSFE4cBxkUPcnxaGXxz1avpewQs7uNpjFkNTbztJ1gWbS6HiPP9Q

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 - getNewAddress generates a new Bitcoin address from the private key, and getBalance lists the current Bitcoin balance held by the node. However getBalance also supports optional parameter “account”, that is now deprecated
  2. Try to execute dumpwallet in order to store keys in a file.
    Did that - suprised that there where multpile private keys, I thought there would be only one - but I have learned that there are several, to support privacy options of using a new address for each transaction
  3. Try to execute dumpprivkey on an address you generated with getnewaddress.
    Did it twice - and the private key shown is a new one each time as expected
1 Like
  1. Yes the description makes sense, plus reveals some extra parameters that can be used.

  2. Done. Although I had to use the full path starting with C:\ in order for it to work

  3. Done

1 Like

Hello sir, could you please share the command that you use for dumpwallet and dumpprivkey?
I’m sure you did it properly, but I would love to see which are the commands that you used.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

Thanks to the user @tendi who provided an updated version for the API calls so I can test more arguments:

  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
    It can contain two optional argument: (“label” “address_type”)
    (edited) Getbalance - returns the total available balance. It can contain three optional arguments (“dummy” minconf include-watchonly)

  2. Try to execute dumpwallet in order to store keys in a file.
    dumpwallet “filename” = imports all wallet keys to a server-side files
    I executed
    bin % ./bitcoin-cli -regtest dumpwallet test
    and I got a file with a bunch of private keys.

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

User bin % ./bitcoin-cli -regtest getnewaddress Try bcrt1qyhhusnta04qf0sslv4mvmhjw6397aru32fu56c

User bin % ./bitcoin-cli -regtest dumpprivkey bcrt1qyhhusnta04qf0sslv4mvmhjw6397aru32fu56c
cNJLZ2CvUBk1aos59azcZyMvE3sYooGPqfAYTdvwXaBVQLvR3RPS

1 Like

You mean getbalance? :slight_smile:

2 Likes

Yes you are right, it is getbalance. sorry about my typo

1 Like
  1. 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.|
    | — | — |
    getnewaddress [account] Returns a new bitcoin address for receiving payments. If [account] is specified payments received with the address will be credited to [account].

  2. ./bitcoin-cli -regtest dumpwallet “C:\Users[Username]\Documents\mytestwallet.txt”

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

1 Like
  1. yes i can find them. both have can be used with an account parameter. The description fits.

  2. done. I dumped it in a txt file in my downloads folder:
    ./bitcoin-cli -regtest dumpwallet “C:\Users\Sabine\Downloads\wallet.txt”.
    Btw: don’t create the file before executing (produces a “file already existing” message). The file will be created during execution.

  3. done:
    ./bitcoin-cli -regtest dumpprivkey ADDRESS_FORMERLY_CREATED

1 Like