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.
- 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?
- Try to execute dumpwallet in order to store keys in a file.
- 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:
- 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:
- 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