Bitcoin RPC getbalance of address I sent coins to on regtest

3

1

Here is my terminal session:

$ echo $address
mvt7M16caMH1xoJyfWU5orjArfq97jhZ7k
$ bitcoin-cli -regtest getbalance
5899.99990000
$ bitcoin-cli -regtest sendtoaddress $address 10.0
6ed7452f8f11fe25904867b57e127a6b65cb180c2013e667e3d399c4179ff1f0
$ bitcoin-cli -regtest setgenerate true 1 
$ bitcoin-cli -regtest getbalance $address
0.00000000

Shouldn't the balance of this address be 10 now? I thought that by generating a block, I will have that transaction included, which will show up on the addresses balance?

Chris Stewart

Posted 2014-10-26T18:03:02.350

Reputation: 865

Is bitcoind in regtest mode? Is the address in your wallet?Nick ODell 2014-10-26T18:10:28.167

I ran bitcoin-cli -regtest getnewaddress, and I also ran bitcoind -regtest -daemon, I think those are the two things you are looking for. If I needed to do anything outside of that, then no.Chris Stewart 2014-10-26T18:16:02.713

Try getreceivedbyaddress instead.Nick ODell 2014-10-26T18:19:25.170

That worked! Now why is that? Did I mistype something some where? Am I misunderstanding a procedure?Chris Stewart 2014-10-26T18:21:27.587

1

getbalance returns the balance of an account, not an address. https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list I didn't notice it at first.

Nick ODell 2014-10-26T18:23:03.367

Answers

4

getbalance returns the balance of an account, not an address. https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

If there's no account by the name of mvt7M16caMH1xoJyfWU5orjArfq97jhZ7k, it will return 0.

Try using getreceivedbyaddress instead.

Nick ODell

Posted 2014-10-26T18:03:02.350

Reputation: 26 536

4

Use it like this:

account=123abc
bitcoin-cli -regtest setaccount $address $account
bitcoin-cli -regtest getbalance $account
10.0

Md Shahadat Hossain

Posted 2014-10-26T18:03:02.350

Reputation: 197

If this is a shell, shouldn't that be account="123abc" ?Nick ODell 2015-08-13T06:04:04.103

i have edited for shell.now it'll worksMd Shahadat Hossain 2015-08-13T06:13:20.343