M
M
miki1312014-07-01 17:32:51
Node.js
miki131, 2014-07-01 17:32:51

How to find out the balance of a bitcoin address?

The server has a bitcoind client.
For each "client" an account is created and it has 4 addresses

var name = ['myaccount'];
var batch = [{method: 'getnewaddress', params: name}, {method: 'getnewaddress', params: name}, {method: 'getnewaddress', params: name}, {method: 'getnewaddress', params: name}];
client.cmd(batch, function(err, address, resHeaders) {
  if (err) return console.log(err);
  console.log('Address:', address);
});

Then I can find out the account balance
client.cmd('getbalance', 'myaccount', 4, function(err, balance, resHeaders) {
  if (err) return console.log(err);
  console.log('Balance:', balance);
})

How do I find out the balance of an individual address in my account.
Also, is there a "received transfer" event so that I can subscribe to it and find out when someone replenishes one of their addresses?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sprocker, 2014-07-02
@sprocker

As far as I know, you can call the getbalance function in bitcoind
On the example of Linux:
The appearance of the line in the terminal [email protected]:~ bitcoind getbalance $address
$address is one of the addresses of the created bitcoin account
About "received a transfer" - in my opinion, there is no such function, you can try to track transactions on the wallet address:
With the help listtransactionof every N minutes, receive the latest transactions, run them through the API of some bitcoin blockchain, take the date from the json decryption and compare it with the current one.
There are a lot of drawbacks to this option, but you can probably come up with a better scheme. This is just the first thing that came to mind
. Here is a list of bitcoind calls, you may find it useful:
code.gogulski.com/bitcoin-php/class_bitcoin_client.html

Y
Yuri Bogoslavets, 2019-09-12
@uranik

We canceled the address parameter in this function, now it returns the balance of the entire wallet :(
see https://bitcoincore.org/en/doc/0.18.0/rpc/wallet/g
... sum unspent for the desired address.This
is faster and more convenient than using listtransaction (sprocker) to parse the entire blockchain.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question