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

Yes these commands can be found in the list and they do exactly what is described in the list

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

Here are the output in the “test” file:

Wallet dump created by Bitcoin v0.20.1

* Created on 2020-10-25T05:34:49Z

* Best block at time of backup was 104 (10ecf405441b7004a1911952c389add38da7c0859529789231ce80c0a098bb5b),

mined on 2020-10-25T03:46:19Z

extended private masterkey: tprv8ZgxMBicQKsPeg5kU72fb6EGCG4yrRPKKjoFrVmQVgZ5YLwJNQEZe8n7SAPudDkqLmenrXoaWFa6mxnk8QMcotzLSwjknQy3vcNK4s9LNxf

cUhDHy4fgfQMy6yc8UoNDopJrss9vFRMYCXCQHhts5gumjtFpS1p 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqx9uu8ytsmac8dc4260pl6tzfq5cje9wpf5gv2 hdkeypath=m/0’/0’/404’
cVKeetec4wPbkBJt5xgvtmMDtsoZY9wTKMaHxqz8emD9DmfK6y3V 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqxse5e97p46clg7zp7uw5mpdz07wenyvgx08sx hdkeypath=m/0’/0’/441’
cRe8Bi11rjpXos7QrWq54i8jfwU3QTs51sWURVWhi8Hnw6UtsvqC 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqxh7mesy8ys97kaf6pvtx2jhv6ylnunq72v64e hdkeypath=m/0’/0’/267’
cS7Zf8RftgK15BoJhWZvwnBwtkGtHUzR4nxucMUTaKV5KRYXBScb 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qq8sthg7ms0prr900gfww0e9455pe9c2ssefhtc hdkeypath=m/0’/0’/41’
cPcNXU2uXX2uSA9ghcoHDVXXFiNmD6edYZ34vkZ9aJ1okcA89Ft6 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqf93rxhyekq2gtpuls7tdv4svctnn46g8f8e00 hdkeypath=m/0’/0’/108’
cVzMYjk1MH4tQdccsRBoFWv4zmGBCusKSSpdTXsk1w21Yrfuefc5 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqfhv7q0uqklm5kmfavvcs2rdegjnsk6hmv0j9x hdkeypath=m/0’/0’/275’
cQttw3Hx7ohrHS2j1zztHdTTDnuvm48DJsHUrYhjA5Fie2wtFq3m 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qq27nf5qzxeny4rkhp39k45duz4f2xva2rvmwz7 hdkeypath=m/0’/0’/348’
cR87GVdbDN64n56m7omeUSLCEH3BJAKWiTtkC9xZkjPKeWomD4eR 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqd8xtyta77vzxs0jn34wjhnku4ceprq5qq5vuh hdkeypath=m/0’/0’/224’
cSqrFaQHfbDvmVH2EAWTz4t3oiKbAkcxAZuz6Z7AedJerYbcp8zE 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqdses9cf097amdufm9m3gqqupx7fvt8racq5r3 hdkeypath=m/0’/0’/397’
cS8pbpP6ZnyVsvLNZawb1ns2XUB5a3VEQvxrBSnj5iBTQu4ZGh5P 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qq0xc9p2nyrc4xwc3t3g6agnw4xw0m5rcewue2f hdkeypath=m/0’/0’/388’
cUMBjzchs43MZJoiuSUNxRkqfFM5KpFPjuMLeN4NDXRDEZSr9s1V 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqj8ceuc9x064l9jr4f4ktf5aefm4d3cu7cxqnn hdkeypath=m/0’/0’/517’
cRtGKiT4kR3VqcXkdYn6LE3jpgr5KTsQ4vNJKAHJnGMWsq6N9Hha 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqjttpv5jehlrdmr3x7f5hxkh30srsqtwnljqc0 hdkeypath=m/0’/0’/216’
cTWasUDAhJxF8Zm42ryaWzmzxkMFSDGE8KFBzVJ7xFWAzpNWfMbP 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqkz6awxupaqgwzsznqj2zj0vkzfsj9p4d0tqxm hdkeypath=m/0’/0’/149’
cPSJoWyQFzxxWCcC4JvEXsGDaP8z7H3Uv1McMPtaiHV34NUyNL9c 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqk26vvrw6ny8l4zppxjqrmrhp3cjwc2xs0m79l hdkeypath=m/0’/0’/307’
cUhkDEQ3arWvLWJeczZvpcPPrtUK9okrSTwtjs7R6CgPAtWhq1JA 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qq674dm0enpmnwglvlvz9trwyxlugkzq7cspjr7 hdkeypath=m/0’/0’/127’
cPh5GFhR9kiVuwWm2y3SnQnUHr1hNgx6FCNAsbiZhQwExU1svYDf 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qq67h5w2f238qlstn6d92t7q8pze85hl63qyadl hdkeypath=m/0’/0’/58’
cNAskNBp3RCLkEKAygTR1zKEBntkLGspEnGL1KthS3E9rzEhJSYx 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqmf0fsufggn7cpyevvpk24wjrxmzs67pfatjv4 hdkeypath=m/0’/0’/450’
cNDRoTdVyMAyfcTbjUuh9fJqi6Cxr7u1EjxxNoYTm2C54PTbsi12 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqa93na39j4drrh73mr3j53jgf2x0055cfmc9et hdkeypath=m/0’/0’/332’
cVbSh6Pj9Ew6N4HtHd22y2Dy7MDpc9rnvNR3HH1ggKrtFCW9KzEB 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qqag4y34jpgyuzrp5xe5rqugau2g2640rvppvk7 hdkeypath=m/0’/0’/523’
cU3PSEPMUtYeh4THpSW45uN92MFu91RqHH9CEhsdwQoofDyWbJBa 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qpqvul7f6w2a0vkerupnq3ss4xecw34vw2nufpl hdkeypath=m/0’/0’/73’
cTQBPEkfceH8Ap45BPiSVU89PEsx6dfywU4yJcLg8H4HMzFZwPEG 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qpzehhlk5zlchtawks48w4v2nw6y96eqe24qcvz hdkeypath=m/0’/0’/117’
cTjXKAEz6jBFBhG5Q3oVBWdu6Cx7HFn4PQLHfmzKz4M3GPo6FUY4 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qprq8ylwk282h4aftt60lzsnxffcpk5ms72ntup hdkeypath=m/0’/0’/549’
cU6cXab7jf2QDXVAHXcYTmub5mRihDwi7pEuV96KvYYhTSDu8hRc 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qprrdxg2lsjh59tellkenmmfq50yc4jz337v402 hdkeypath=m/0’/0’/165’
cQApPbE3h2s74ePvLikYursySbPJqiDJK6EHzRAfgnX2maJ3zRDU 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qprypty0aymy9eevzghgqfmmnrkq2cjya3ga27x hdkeypath=m/0’/0’/269’
cN1uLHPc7qnN3dUJgFvv91gvGDEMDsvguM2ZrckKwgvWTaeQrTaG 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qpr7m3uej6dqjgqcvd0cmpvcfnufj3ddah689dq hdkeypath=m/0’/0’/27’
cShTKjecJzcuvfaDgoH5gSkjsApH6tBBggqsaQWdSD5AMWtwSukL 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qp9z05fdmfewjvwxqq0hhrygdj49n4820r3ga05 hdkeypath=m/0’/0’/123’
cQ8QPUVhaezvMRZXGW4Kisbhe2ud9z3EiyGQcDQkbqwuyuvrscKb 2020-10-24T09:41:25Z reserve=1 # addr=bcrt1qp9sw28jld808myaswxljxdtegavgdnn75dwm7m hdkeypath=m/0’/0’/69’

  1. Try to execute dumpprivkey on an address you generated with getnewaddress.
    PS D:\blockchain\bitcoin\daemon> ./bitcoin-cli -regtest dumpprivkey bcrt1qtha5j6e3jupj37t2mj7yzvxdc8usvherdfxuts
    cMtHGRNajbKU1sf3myAE1rHdmgW7dL6KiUpJ5ckfq4qnaLZs6sTp
1 Like
  1. Uhhh… Yes?
  2. success
  3. success.

How about showing some proof :wink:

1 Like

wallet dump


private key dump

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].
    getbalance - If [account] is not specified, returns the server’s total available balance.
    If [account] is specified, returns the balance in the account.
    I’ll have to revisit two and three, I keep getting errors I think I’m on a different version of bitcoind

What kind of errors do you get?
I think these particular commands didn’t change much during versions. :slight_smile:

1 Like
  1. getnewaddress generates a new address for receiving payments. getbalance computes the balance for an account if one is specified, otherwise it gives the sum of balances for all accounts on the server.
  2. dumpwallet exports the private key info to a file (filename required).
  3. dumpprivkey shows the private key of an address (address required).
1 Like
  1. yes indeed

1 Like

You got an error in dumpwallet you forgot to provide the filename where the CLI should dump the keys. :slight_smile:

1 Like

ah Thank you very much sir. I will definitely be giving this course another run through👌

is this right?

You can open that file with a text editor to verify :wink:

1 Like

1 Like
  1. Yes. Yes
  2. Done.
  3. Done

This link really helped:
https://developer.bitcoin.org/reference/rpc/index.html

1 Like

The CLI also has a help function that lists all commands :slight_smile:

@ivan
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 did find them. Descriptions of their tasks and interactions.

2.Try to execute dumpwallet in order to store keys in a file.
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:
    “str” (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/

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

1 Like

To dump the entire wallet you use the dumpwallet command with a provided filename.

bitcoin-cli also contains a help command you can use.:

bitcoin-cli help <COMMANDNAME> :slight_smile:

1 Like

Same for me in Centos8

If you installed bitcoin as a package you have the binary instaled in a directory in your path (like /usr/bin). Binaries that are in directories defined in the PATH (to see your path variable check echo $PATH) variable can be accessed without providing path to the executable (./ if its in the same directory).
You can do this on windows as well by setting the environment variable to the bitcoin install directory. Same if you would install Bitcoin core without a package manager but download the executable manually, you would have to provide the path to it.
In this reguard M$ and Linux are the same. Both have their own PATH variable.

To set it on Windows do something like this:
https://www.techjunkie.com/environment-variables-windows-10/

To set it on Linux (non persistant, just do):
export PATH=$PATH:<Path to Bitcoin binary>
To keep it persistant set this into your .bashrc file or whatever shell you are using :slight_smile:

2 Likes
  1. Yes, the descriptions match the actions.

  2. I cant get this to work. Im getting this error message;
    error code: -8
    error message:
    Cannot open wallet dump file

I have tried changing the permissions on the file that I made for this exercise but it still wont work.

  1. [mark@centos8 ~]$ bitcoin-cli -regtest dumpprivkey “bcrt1qp67g0q2shtx3ufaclqp2z7w0mmk89a8ptxyvg4”
    cT5vb2dXNS6rKLgtwxepWhrb3K5942WDh5NyP2pELzwZKhMpNQus