bitcoin-cli: how to create a wallet and utxo address

user3489820 picture user3489820 · Feb 14, 2018 · Viewed 7.3k times · Source

I am a relative newbie in bitcoin and blockchain and hope you can help me with some of the questions. So I launched a "regtest" network and generated 101 blocks using

bitcoin-cli -regtest generate 101

Now, if I launch 'bitcoin-cli -regtest getaddressesbyaccount ""', I get the public address of my default account:

[
  "mwpKJNJ4UZL7yFyj53RSVcwauGAK84UvV2"
]

And of course, I should not have any other accounts as for now. When I launch 'bitcoin-cli -regtest listunspent':

[
  {
    "txid": "694030f8638318c8c54054515ec716159edc494b14234885deb48f294b75a2fe",
    "vout": 0,
    "address": "n1queZpweTHjrMLvwSmcfrrJSQjsrYG3nG",
    "scriptPubKey": "21038cadb266ed1ae6c474f5c1b74fc5f6790eacde843a673a16cfc924a100f2a679ac",
    "amount": 50.00000000,
    "confirmations": 101,
    "spendable": true,
    "solvable": true,
    "safe": true
  }
]

First question: I understand that the only transaction listed by "listunspent" is UTXO, meaning this is a transaction what I received to my address "n1queZpweTHjrMLvwSmcfrrJSQjsrYG3nG" with 50 BTC as amount. Where this address comes from? By what bitcoin-cli command I can see/find it in my wallet?

Second question: How can I create a new wallet with some balances and switch between them ( using bitcoin-cli )? Basically, I would like to be able to test my app using bitcoin-cli - I need to be able to create wallets, switch between them and send btc between the addresses.

Answer

skang404 picture skang404 · Feb 15, 2018

Coinbase coins can't be transferred until 100 blocks after they were created.

(Why did you generate "101" blocks specifically?)

So, the amount in your wallet you see is from the first block you mined. You can verify that by bitcoin-cli -regtest getblock "<hash of first block>" which you had got in return to the generate 101 command you ran earlier (an array of 101 block hashes).

Try the following

  • generate one more block bitcoin-cli -regtest generate 1
  • now listunspent and you should see 2 utxos instead of 1.

Depending on what you want to test, maybe simply creating a new address and sending money to it is enough for you?

[Edit]

  1. Shut down core properly.
  2. Rename your wallet.dat file
  3. When you restart, a new wallet(wallet.dat) will be created. You can use them by supplying -wallet arg to bitcoin-qt

For example, if you are on linux:

Create 4 wallets by starting bitcoin core, stopping bitcoin core and then renaming the wallet.dat in your ~/.bitcoin folder (then repeating the process). For example, run this process 4 times to generate :

  • mywallet.dat
  • wifeswallet.dat
  • kidswallet.dat
  • businesswallet.dat

Then, in linux, in your .bashrc :

alias mywallet="bitcoin-qt -wallet=~/.bitcoin/mywallet.dat"
alias wifeswallet="bitcoin-qt -wallet=~/.bitcoin/wifeswallet.dat"
alias kidswallet="bitcoin-qt -wallet=~/.bitcoin/kidswallet.dat"
alias businesswallet="bitcoin-qt -wallet=~/.bitcoin/businesswallet.dat"