Why the amount of listunspent and getbalance is not the same when each data is called by API?

0

0

When I called listunspent, it returned the following array. From the array, I thought the balance "mknGW629wzSkfWvgXF23d8eTrqibnhTcrf" is 0.1097. However, when I called getbalance of mknGW629wzSkfWvgXF23d8eTrqibnhTcrf, it returned 0.000000.

Why sum of amounts of listunspnet is not equal with balance of address?

$./bitcoin-cli listunspent

{
    "txid": "a82bf11b72d6ef2f5eaa62190914a4c80b8749e075015fda513b899f54d29e06",
    "vout": 0,
    "address": "mknGW629wzSkfWvgXF23d8eTrqibnhTcrf",
    "account": "",
    "scriptPubKey": "76a91439be11328b909d0327ef53ae923a9b4dd47420f788ac",
    "amount": 0.00000600,
    "confirmations": 367,
    "spendable": true
  },
  {
    "txid": "b8f8d20946ca52283fbf192c7ebfb817deba260c54911938d59bb64bbb8cb8a7",
    "vout": 0,
    "address": "mknGW629wzSkfWvgXF23d8eTrqibnhTcrf",
    "account": "",
    "scriptPubKey": "76a91439be11328b909d0327ef53ae923a9b4dd47420f788ac",
    "amount": 0.00000600,
    "confirmations": 366,
    "spendable": true
  },
  {
    "txid": "b8f8d20946ca52283fbf192c7ebfb817deba260c54911938d59bb64bbb8cb8a7",
    "vout": 2,
    "address": "mknGW629wzSkfWvgXF23d8eTrqibnhTcrf",
    "account": "",
    "scriptPubKey": "76a91439be11328b909d0327ef53ae923a9b4dd47420f788ac",
    "amount": 0.10968200,
    "confirmations": 366,
    "spendable": true
  },
  {
    "txid": "b66513ae7aab964e5374d97be206b94e529055523a35d2249ad2917745c921f8",
    "vout": 0,
    "address": "mknGW629wzSkfWvgXF23d8eTrqibnhTcrf",
    "account": "",
    "scriptPubKey": "76a91439be11328b909d0327ef53ae923a9b4dd47420f788ac",
    "amount": 0.00000600,
    "confirmations": 370,
    "spendable": true
  }
]

$ ./bitcoin-cli getbalance mknGW629wzSkfWvgXF23d8eTrqibnhTcrf
0.00000000

lalala

Posted 2015-11-28T10:52:03.340

Reputation: 251

Answers

4

Because Bitcoin Core does not support "balance of address".

The wallet has a single balance, and addresses are treated as separate input gates into that balance, so you can distinguish what is being paid for (by allowing you to give a different address to each payer).

The argument to getbalance is an account name. Accounts are just bean counters: they don't correspond to actual coins in the network. You can change their balance using the move RPC command, which does not even create a transaction. They're a purely local abstraction. You can associate an address with an account so that receives on that address credit the account, and you can use the sendfrom RPC to deduct the sent funds from a given account (but the actual transaction outputs used are still drawn from a pool shared by the whole wallet).

Accounts are a confusing feature however, and they're hard to use in a correct way. That's why they're also scheduled for deprecation in Bitcoin Core.

Perhaps you're looking for the getreceivedbyaddress RPC?

Pieter Wuille

Posted 2015-11-28T10:52:03.340

Reputation: 54 032

Exactly. What I want is getreceiveaddress RPC. Thanks a lot, Pieter:) $ ./bitcoin-cli getreceivedbyaddress mknGW629wzSkfWvgXF23d8eTrqibnhTcrf 0.43938200lalala 2015-11-29T01:37:06.420