Bitcoind and bitcoin-cli Assignment

bitcoin-cli -regtest command test:

  • getnewaddress -> ./bitcoin-cli -regtest getnewaddress -> new address is generated (2NCpFNkCDDmpLWQM6Be8TC5MuM3zJpAgAyh)

  • getbalance -> ./bitcoin-cli -regtest getbalance -> show the current balance (150.00000000)

  • dumpwallet -> ./bitcoin-cli -regtest dumpwallet “…/regtest.txt” -> exports all private keys into “regtest.txt”

  • listaddressgroupings -> ./bitcoin-cli -regtest listaddressgroupings -> get wallet address

  • dumpprivkey-> ./bitcoin-cli -regtest dumpprivkey “address” -> shows the private key to this wallet address

2 Likes

I was going through a lot of the commands on the wiki that was linked in the course and i realised that a lot of them are outdated for the current client. The most up to date version is available here https://bitcoin.org/en/developer-reference#bitcoin-core-apis.

I created a number of different addresses while doing these tutorials and I am struggling to find a way to list them all.

2 Likes

When you dump the wallet you need to put a name for the wallet as well. I find the error codes and messages quite bad on this client.

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?

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.
command:
./bitcoin-cli -regtest getbalance [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].
command:
./bitcoin-cli -regtest getnewaddress [account]

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

./bitcoin-cli -regtest dumpwallet “C:\User\Desktop\walletName.txt”

The wallet(s) address(es) will be a saved in a TXT file on the folder you specify.

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

./bitcoin-cli -regtest dumpprivkey [address]

The console output will be the private key of the address you specify. (keep this private key safe).

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. (this makes so much more sense now)

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

After trying to execute dumpwallet, I received an error stating that I have not specified a filename with a path for powershell to export the files.

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

After trying to execute dumpprivkey on an address, I received another hash, from seeing other people’s answers, I feel that it is safe to say this is my privatekey.

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 [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] f [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.**
./bitcoin-cli -regtest dumpwallet

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

1 Like
  1. Yep, seems to.
    2., 3. I assume these will do what is specified in the docs.
    (I’m still downloading the chain so I can’t try it yet.)
  1. Consulting https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list :
    ‘getnewaddress’ is described as “Returns a new bitcoin address for receiving payments. If [account] is specified payments received with the address will be credited to [account].”
    We have not yet been using account parameter, and so it default to use the single default account. Specifically we have used ‘getnewaddress’ via the bitcoin-cli in regtest mode, calling it as follows (in a PowerShell window from 'C:\Program Files\Bitcoin\daemon directory):
    ./bitcoin-cli -regtest getnewaddress
    eg. returns: “2NAYTnsqTPW3xnAuq9yVNmJW2UmK7Sya53P” (36 characters).
    So yes the description fits what the command does, as it returns a new bitcoin address.

‘getbalance’ is described as “If [account] is not specified, returns the server’s total available balance. If [account] is specified, returns the balance in the account.”
Therefore as we have been using the default account (not specifying accounts) then the total balance is returned. Specifically we have used ‘getbalance’ via the bitcoin-cli in regtest mode, calling it as follows (in PowerShell window from the 'C:\Program Files\Bitcoin\daemon directory):
./bitcoin-cli -regtest getbalance
eg. returns “199.99996680”
So yes, the description fits what the command does, since it returns the bitcoin balance,

  1. dumpwallet description says “Exports all wallet private keys to file.”
    Executing this command by typing (in PowerShell window from the 'C:\Program Files\Bitcoin\daemon directory):
    ./bitcoin-cli -regtest dumpwallet testdumpwalletfile
    Gives an error code: -8: Cannot open wallet dump file
    This is probably as there are no permissions to write files to this directory. Therefore trying again with a new directory also specified:
    ./bitcoin-cli -regtest dumpwallet “C:\Users\marks\Documents\Bitcoin\testdumpwalletfile”
    Returns:
    {
    “filename”: “C:\Users\marks\Documents\Bitcoin\testdumpwalletfile”
    }
    And checking the directory the ‘testdumpwalletfile’ has indeed been created. This text file contains the ‘extended private masterkey’ and other (public & private) keys.

  2. dumpprivkey is described as “Reveals the private key corresponding to < bitcoinaddress >”.
    Executing this command by typing (in PowerShell window from the 'C:\Program Files\Bitcoin\daemon directory):
    ./bitcoin-cli -regtest dumpprivkey 2NAYTnsqTPW3xnAuq9yVNmJW2UmK7Sya53P
    Returns another key, which must be the private key, ie. cUyhCcTRsW6J3z8ebrmgezHAkaTxdsc61YS9A6Mj68XnTramNMbv
    (Both of these public and private keys can be found in the dumpwallet file produced previously.)

1 Like
  1. getnewaddress Returns a new bitcoin address for receiving payments. If [account] is specified payments received with the address will be credited to [account]. This matches what we discussed except we did not discuss accounts.
    getbalance If [account] is not specified, returns the server’s total available balance.
    If [account] is specified, returns the balance in the account. This matches what we discussed except we did not discuss accounts.
  2. Executed: .\bitcoin-cli -regtest dumpwallet “PATH\dumpwallet.txt” and got a text file full of keys:
    {
    “filename”: “PATH\dumpwallet.txt”
    }
  3. Executed: .\bitcoin-cli -regtest dumpprivkey 2N1pqx2xyDTYZACPbXdsutWmpEqowHgS66H and got a private key listed in the console:
    cScCgD3A3NWRmRTonzmdKmKYe1M79CGRwhW52mtvwioC2dinRDoY
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?

Yes, except that reading the description I learn that bitcoind has also an “account” feature. This is good to know in case somebody wants to manage bitcoins for friends and relatives and mix them in the same wallet, just like a bank does.

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

The file looks really big. It is a collection of all private keys managed by the wallet.

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

dumpprivkey: returns just the private key of a specific address.

1 Like
  1. getnewaddress and getbalance
    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. dumpwallet.
    Successfully dumped into a txt file.

Description from powershell:
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. dumpprivkey on address generated with getnewaddress
    This reveals the private key of the 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?
    Yes they do.

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

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

1 Like
  1. getnewaddress functions as expected, but getbalance mentions that if no account is specified, the command will output the entire wallet’s balance.
  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?
    Yes.
    getnewaddress - gives a new bitcoin address for receiving payments
    getbalance - gives either the balance of the account or if not specified of the total balance on the server

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

./bitcoin-cli -regtest dumpwallet “filename”

  1. Try to execute dumpprivkey on an address you generated with getnewaddress.
    ./bitcoin-cli -regtest dumpprivkey “addressname”
1 Like

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.

./bitcoin-cli -regtest dumpwallet “C:\Users\File\Desktop\btcwallet”

bitcoin-cli -regtest dumpprivkey

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.

    bitcoin-core.daemon -printtoconsole -regtest
    bitcoin-core.cli -regtest [command]

    a. Can you find getnewaddress and getbalance in the list? YES
    
    	bitcoin-core.cli -regtest getnewaddress
    	bitcoin-core.cli -regtest getbalance
    
    b. Does the description fir what the commands do? YES
    
  2. Try to execute dumpwallet in order to store keys in a file.

    	bitcoin-core.cli -regtest dumpwallet "[file name]"
    
  3. Try to execute dumpprivkey on an address you generated with getnewaddress.

    	bitcoin-core.cli -regtest dumpprivkey [address]
1 Like

hello sir, if you can, please describe question 2 and 3, if your finding diffitult to finish, let us know so we can help you! :slight_smile:

Carlos Z.

  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, i believe the description fits the operation, although the actual command given to the daemon may be different the outcome is still what we wanted.

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

THERE IS NO TRY.

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

Hello sir, i trust that you know how to use the commands on question 2 and 3. Although maybe you would like to write which are the commands that you use? (Does not need to write your exact command, look other post from students so you can have an idea, still, i trust you know how to use them). :slight_smile:

Carlos Z.

1- Can you find getnewaddress and getbalance in the list? Does the description fir what the commands do?
R: found getnewaddress C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest getnewaddress
2N7Dh97SZpPMbmyU9p4htyo6PTwhqaUiBzx - and the description described what the command does - Returns a new bitcoin address for receiving payments. If [account] is specified payments received with the address will be credited to [account].
R: found getbalance C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest getbalance
150.00000000 … and also the description does what the command does - 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.
R- done and the returned reply I got was :
PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet and I got
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).

  1. Try to execute dumpprivkey on an address you generated with getnewaddress.
    R: I ran: PS C:\Program Files\Bitcoin\daemon> ./bitcoin-cli -regtest 2N7Dh97SZpPMbmyU9p4htyo6PTwhqaUiBzx dumpprivkey and got:
    error code: -32601
    error message:
    Method not found

Im practicing

1 Like