0

I have an address on the testnet. I started out with 1.3 btc. I then sent 0.5 btc to another address. My balance is now 0.8. OK, that makes sense.

I expect now to have one UTXO which was the 0.8 in change from the previous transaction. But when I run listunspent, I see I have two UTXOs. The balance is correct, but it seems I have two outputs.

[
  {
    "txid": 
   "321dab633022a33c3a49b4aab4b13d3c431771ae9402746dbb6dcc21be5fd603",
    "vout": 1,
    "address": "2N4wJG7gs1mVXeMkX2MCuyekZUCSzrW7CjT",
    "redeemScript": "0014221f8d76c5b85e979055e54ac97a0cada38bc4e9",
    "scriptPubKey": "a914803d96c7e19e4a568764f9912fa54499f814cd8e87",
    "amount": 0.79999834,
    "confirmations": 119,
    "spendable": true,
    "solvable": true,
    "safe": true
  }
]

When I run gettxout with the txid and vout 0, the first transaction UTXO is 0.5.

{
  "bestblock": 
  "0000000000000043a1abc3cf9c778d3adeb417488019a507da871db9df74ffad",
  "confirmations": 119,
  "value": 0.50000000,
  "scriptPubKey": {
     "asm": "OP_HASH160 a43f8a90f292b6be0b487556ac357709a5e86480 OP_EQUAL",
     "hex": "a914a43f8a90f292b6be0b487556ac357709a5e8648087",
     "reqSigs": 1,
     "type": "scripthash",
     "addresses": [
       "2N8Dgvfmgs4fNCi7QatLZJR8ArvhPpMPW8P"
     ]
  },
  "coinbase": false
}

And when I run gettxout with vout 1, the second transaction UTXO is 0.799 (0.8) which is the balance.

{
  "bestblock": 
  "0000000000000043a1abc3cf9c778d3adeb417488019a507da871db9df74ffad",
  "confirmations": 119,
  "value": 0.79999834,
  "scriptPubKey": {
    "asm": "OP_HASH160 803d96c7e19e4a568764f9912fa54499f814cd8e OP_EQUAL",
    "hex": "a914803d96c7e19e4a568764f9912fa54499f814cd8e87",
    "reqSigs": 1,
    "type": "scripthash",
    "addresses": [
      "2N4wJG7gs1mVXeMkX2MCuyekZUCSzrW7CjT"
  ]
},
"coinbase": false

}

And according to this: How to check if an output has been spent?

If gettxout returns something, then the output is unspent.

Why do I have two unspent outputs with the first one in the same amount that I sent to another address?

  • Does your wallet control both addresses? 2N4wJG... and 2N8Dgv...? If so, it makes sense that both UTXOs would be listed with listunspent – chytrik Jul 19 '18 at 7:42
  • Ok, that's probably it. What I did as an exercise is I made two copies of wallet.dat: sending.dat and receiving.dat. I then had a test faucet send some btc to sending.dat. I then sent btc from sending.dat to receiving.dat. What you see in my original question were the two UTXOs for sending.dat. So I'm guessing that because I made copies of wallet.dat, all the resulting addresses I created actually belong to the same wallet? – Bastien Jul 19 '18 at 8:19
  • Yes, the addresses belong to the same wallet. It was the same file copied, and with Bitcoin Core's HD wallets, the same addresses and private keys will always be generated with those wallet files. – Andrew Chow Jul 19 '18 at 8:33
1

As per the comments on OP’s question

Since you made a copy of the wallet.dat file (which is an HD format), both addresses will be under the control of (both copies of) your wallet. Hence, both UTXOs will be listed when calling the listunspent command, as each wallet is able to spend both UTXOs.

If you used a new wallet to generate a new address, and send some funds to it, then the listunspent command should function as you originally expected, as your bitcoin core wallet would not control the address you spent coins too (it would only control the change address).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.