简体   繁体   中英

How do I get the total Wallet Balance in Blockcypher API?

I'm able to get address balances using their address balance endpoint:

https://www.blockcypher.com/dev/bitcoin/?shell#address-balance-endpoint .

But the API does not present any method to return Wallet Balances (since a Wallet consists of multiple addresses).

Since multiple addresses constitute a Wallet, I tried using a loop on the addresses and adding up the total to get the Wallet balance, but the issue with that approach is that it is too resource intensive and uses up the Blockcypher API limits quickly, especially when the addresses become really large (as I'm generating new address for each transaction on my application).

I've tried storing address information (including balance) on my db and using a webhook to listen on incoming transactions and update the address balance accordingly, but the approach is really messy and it doesn't even update the correct balance! This is how I retrieve the balance from the webhook total field:

$profile->hash = $data['hash'];     
$profile->address = $data['addresses'][0];     
$profile->amount = $data['total'];     
$profile->fees = $data['fees'];     
$profile->size = $data['size'];     
$profile->vsize = $data['vsize'];

Problem with this one is that the incoming tx s are never the same and there's nothing unique to use to separate them.

Please I would like someone experienced to kindly point me in the right direction, cos I've been pulling my hair out for days and there's not enough information about blockcypher on the.net. I just want to know what is the best way or best practice to retrieve Wallet Balances (not address) on Blockcypher API.

Thanks.

I tried using a loop on the addresses and adding up the total to get the Wallet balance. I got the desired result but the issue with that approach is that it is too resource intensive and uses up the Blockcypher API limits quickly, especially when the addresses become really large (as I'm generating new address for each transaction on my application).

I've tried storing address information (including balance) on my db and using a webhook to listen on incoming transactions and update the address balance accordingly, was expecting to get the transaction's amount in $data['total'] but it doesn't get the correct amount. Gets random values and each tx that comes from tx-confirmation presents something entirely new.

With blockcypher API you can concatenate addresses using ; , like this: https://api.blockcypher.com/v1/btc/main/addrs/1DEP8i3QJCsomS4BSMY2RpU1upv62aGvhD;1JcX75oraJEmzXXHpDjRctw3BX6qDmFM8e

More info: https://www.blockcypher.com/dev/bitcoin/#batching

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM