Calculate Any Address Balance Using Bitcoinn RPC getrawtransaction

1

I'm trying to use getrawtransaction to get transaction details (for any address) from my local blockchain. What I have is an address in readable format, "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa" but the input to getrawtransaction is a hexadecimal string. I found the following solution that does not change the string at all.

let address='1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa';
address=address.toString('hex')
console.log(address);
client.getRawTransaction(address, function(error, o) { console.log(o); });

Any ideas?

Corbin

Posted 2018-03-08T21:46:09.547

Reputation: 115

Answers

1

Bitcoin Core does not support querying an address balance.

What you can do is import the address as watch-only into your wallet (using the importaddress RPC), and completing a rescan of the blockchain. When you're finished, the wallet will treat that address as one of its own, and track payments to it, and include it in its balance. Of course, you won't be able to spend it without private key.

Pieter Wuille

Posted 2018-03-08T21:46:09.547

Reputation: 54 032

The feature seems pretty basic to me, but I'm sure the core devs have good reason for it. Thank you for the suggestion I will try this out.Corbin 2018-03-09T00:29:43.430

For normal operation an address index is not necessary, plus it is expensive to maintain, and there exists other software that is more appropriate for it.Pieter Wuille 2018-03-09T00:42:36.240

Pieter thank you. May I ask what other software that is?Corbin 2018-03-10T18:40:11.517