- 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 for description. There are different descriptions for differnt versions of the program. - Try to execute dumpwallet in order to store keys in a file.
-The keys are dumped into a file. Windows requirers administrator rights to create the file in the same location, but with a path to a Public folder it works easy. - Try to execute dumpprivkey on an address you generated with getnewaddress.
-Each comand responds with the key or address on the following ine.
- 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?
- getnewaddress: I founded and understood
- getbalance: “If [account] is specified, returns the balance in the account.” - I need help with this.
- Try to execute dumpwallet in order to store keys in a file.
PS D:\Bitcoin\daemon> ./bitcoin-cli -regtest dumpwallet D:\Bitcoin\daemon\filename - Try to execute dumpprivkey on an address you generated with getnewaddress.
PS D:\Bitcoin\daemon> ./bitcoin-cli -regtest dumpprivkey bcrt1q7eyu7n9ee43hwwgnpnz4ccr7akewgedzvhrun2
c************************************************************************b
Hey, that command did change try using
getreceivedbyaddress
to get the address balance.
- yes, getnewaddress and getbalance work as described.
- ./bitcoin-cli -regtest dumpwallet test
- ./bitcoin-cli -regtest dumpprivkey 2MztSYDZHAyEyK899Xatu6xwHpMUsFYnRTJ
-
getnewaddress - generates another address (unused address with its corrisponding private key etc)
getbalance adds up all the unspent balances on all the addresse in the wallet. -
dump wallet puts all the private keys to a file for each address.
-
dumpprivkey dumps the private key for a given address.
- 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?
makes sense via the help function
PS E:\Program Files\Bitcoin\daemon> .\bitcoin-cli -regtest help dumpwallet
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” : “str” (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/
-
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
Not sure how this works yet. Is this only possible from within the own wallet CLI?
Yes the wallet must hold the private keys for this to work. You can try with a random address from an explorer and see what happens
- Commands used and their meanings;
a) getnewaddress - Returns new address for receiving payments. If (account) is specified, payments received with the address will be credited to (account).
b) getbalance - If (account) is not specified, returns the server’s total balance available. If (account) is specified, returns the balance in the account.
Both seem to be decent descriptions.
- Execute dumpwallet “address”
./bitcoin-cli -regtest dumpwallet “public key address”
- Execute dumpprivkey “address”
./bitcoin-cli -regtest dumpprivkey “public key address”
dumpwallet
accepts the filename where to dump the keys to, not the address
The cli has a help command you can always use to check how a specific command works:
bitcoin-cli help dumpwallet
Hi @Alko89,
Do you know how to change the Wallet to which the regtest is providing the mining reward?
Let me explain the situation. I created a “virgin” regtest and in this regtest I have three wallets: the default (which doesn’t seem to have a name) , Wallet_1, and Wallet_2.
I loaded Wallet_1 and mined the first 101 blocks with Wallet_1 like this:
./Bitcoin-cli -regtest -rpcwallet=Wallet_1 generatetoaddress 101 “x-address from Wallet_1”
I tried mining new blocks with the other wallets by loading, and unloading between the three wallets with commands like:
./Bitcoin-cli -regtest -rpcwallet=Wallet_2 generatetoaddress 1 “x-address from Wallet_2”
But the reward always goes to the first wallet I used to mine, in my case Wallet_1.
So I guess, perhaps I am not understanding how to change the wallet to which the mining reward goes to in the -regtest.
Please advise.
Actually I think I finally got it. I just learned that freshly minted Bitcoins require 100 confirmations to be able to be spent, at least in the -regtest.; not sure how this works in the real mainnet.
This means that the increasing amount I was seeing in Wallet_1 is just the older blocks that are now available to be spent.
But the newly mined block which only have a few confirmations are not yet available for Wallet_2.
I was able to figure out this by running:
./Bitcoin-cli -regtest -rpcwallet=Wallet_2 getwalletinfo
The results show a “immature_balance” which is the rewards that do not have enough confirmations to be spent.
Yes, mining rewards can only be spend after 100 confirmations, this is the same on mainnet
-
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 could find them, but this description makes me wonder:
If [account] is not specified, returns the server’s total available balance.
When we executed the getbalance command, did we get the balance of the server? or the balance of the account? is this the same as the balance of the wallet?
and when we executed the getnewaddress command, did we got a new address for the wallet? or the server? or the account? are all of these terms equivalent? Because I would understand that I could only create one wallet per server and I could get several addresses for the wallet, depending on which wallet type it is (based on my limited knowledge of bitcoin) - Try to execute dumpwallet in order to store keys in a file.
I could execute it with the command: ./bitcoin-cli -regtest dumpwallet “test.txt” … But I dont know what are these things … seems to be an HD wallet … I just read an article on HD wallets and by doing so I learned a lot mother f¨ckers!!!
- Try to execute dumpprivkey on an address you generated with getnewaddress.
succesfully done!!! I´m feeling great doing this course in parallel with the privacy coins course, I would recomend doing these 2 after taking the bitcoin fundamentals course, and even before rishing into the Ethereum programming courses
Its the balance of the default wallet on the server Bitcoin core stores the keys in a wallet.dat file and if you don’t specify an address you will get the entire balance of that wallet.
You can also have multiple wallets by using the --rpcwallet=<wallet>
parameter in bitcoin-cli
.
You will get a new address for the wallet but in case you’re using bitcoind
as a wallet you will get it in the wallet on that server.
To find the location of the wallet in question you can check these directories for each OS:
https://en.bitcoin.it/wiki/Data_directory
%APPDATA%\Bitcoin
on Windows
Dumpwallet will export your private keys to a file. Mind that bitcoind
does not use HD wallets so you must save all the keys you ever used.
Thanks so much another time!!
So which wallets does bitcoind uses?
It has its own wallet.
Sorry , I meant which TYPE of wallet?
Basically just a keystore that holds private keys. Its not specific because HD wallets were developed later.
Sorry to insist, but what is a “keystore” … did you mean key storage? is that just a file that contanins the private keys?
Basically yes. If you use the default wallet it will be stored under the name wallet.dat
in the Bitcoin data folder.