<blockquote>
<p>I already have bitcoind running with a 4GB pruned database, and I'm hoping that will be enough.</p>
</blockquote>
<p>It is! By running bitcoin-core, you can pull this data in an easy, trustless way.</p>
<p>I would recommend creating and displaying a new address to your patrons each time a new donation is received (so as to avoid address reuse, which is detrimental to your privacy, and perhaps more importantly your patron's privacy), but otherwise you should be able to accomplish your goal without much issue. You could perhaps look at something like <a href="https://docs.btcpayserver.org/" rel="nofollow noreferrer">btcpayserver</a> to help automate the payment flow on your website.</p>
<p>Here is a general workflow:</p>
<ol>
<li>Generate a private key that will be used to receive funds, using your wallet of choice (ideally, this would be done in an offline environment)</li>
<li>Import the address(es) that are derived from the keys you generated in step one, into bitcoin-core. You can use <code>bitcoin-cli importaddress</code> to accomplish this step. Note that if the address is brand new and you know for certain it has never received funds before, then you can set <code>rescan</code> to <code>false</code>, to save a fair bit of computational time.</li>
<li>Use the command <code>bitcoin-cli listunspent</code> to return a list of UTXOs that are locked to addresses that the wallet is watching. You can optionally filter the returned info by address, see <code>bitcoin-cli help listunspent</code> for more info.</li>
<li>(Alternatively, you can use <code>bitcoin-cli getreceivedbyaddress</code>, which may be easier if you're re-using a single receiving address)</li>
<li>From there, you'll just need to parse the JSON data returned, and sum up the relevant address balance(s), to be displayed on your webpage.</li>
</ol>

CC BY-SA 4.0
2021-04-18T03:11:33.680Z
I think I understand you better. But this still leaves me with a quandry. Let me suppose that I have received 600mBTC, but in six increments of 100mBTC each. So I have six UTXOs, that's great. But if they are in six wallets, then how do I send say 450mBTC to someone? Near as I can tell, I'd have to send all 100mBTC from wallets 1-4, then the balance from wallet 5. And each of those would generate a transaction fee.Unless there's a way to make various addresses aliases for the same wallet? I don't care if I use 200,000 addresses as long as I don't have to take the funds from multiple wallets.
Dan Egli
CC BY-SA 4.0
2021-04-18T03:15:34.553Z
As to btcpayserver, I looked at it. I kind of like the idea, but I can't seem to figure out how I could download the software or anything. They talk about hosting on various servers, but almost all of them seem to be hosting services. We already have the VPS. It's been running other things for months now. So obviously we don't want to move the entire setup to a new server. So, how do I obtain the software for download to our server, and how do I actually install that software? That's what I can't seem to figure out.
Dan Egli
CC BY-SA 4.0
2021-04-18T20:04:30.083Z
@DanEgli comments are not intended for discussions, if you have further questions you should use the search function/create new posts. But in brief: a *wallet* will contain many, many *addresses* (keypairs). Receiving to a new address (which is from the same wallet) each and every payment is the standard and highly recommended workflow, your wallet software will manage all of the keys and transaction creation in the background. Installing btcpayserver isn’t too difficult, but it does require some technical skills. See https://docs.btcpayserver.org/Deployment/
chytrik
CC BY-SA 4.0
2021-04-16T02:56:00.563Z
I often wonder about multiple addresses. The issue I see with using multiple addresses is the extra transaction fees each time the funds need  to be used. If I get a donation of 50mBTC from user 1, and 60mBTC from user 2,each sending to a different wallet, then I somehow need to consolidate all the funds before they can be used. That would seem to lean towards using a single address. Now if there's a free way of doing that I'm all ears. But that is a concern.
Dan Egli
CC BY-SA 4.0
2021-04-16T03:00:56.377Z
@DanEgli you misunderstand how bitcoin fees work. Each received transaction create a UTXO, the cost of spending each UTXO as input in another transaction does not depend whatsoever on whether the coins are locked to the same address, or different addresses. There is absolutely no difference in terms of fees.
chytrik
CC BY-SA 4.0
2021-04-16T04:55:01.927Z
Maybe I am misunderstanding. If so please correct me. But my impression was this: USER A sends 40mBTC to Address 123abc. User 2 send another 40mBTC to address def456. Now, I have 80mBTC but it's split in to two chunks. To consolidate into one spendable lump, I need to maybe send the funds in wallet 2 to wallet 1. But that's an extra transaction, thus incuring extra transaction fees.
Dan Egli
CC BY-SA 4.0
2021-04-17T04:16:10.330Z
@DanEgli you are assuming that bitcoin uses an 'account' model to keep track of coins, but that is incorrect, it uses a 'UTXO' model. Even if you use the same address, multiple payments will still create multiple UTXOs, which will incur the exact same fees as you would spending multiple UTXOs that are locked to different addresses. Needlessly consolidating funds is never a great idea though, just spend the UTXOs when you need to, no need to consolidate first. See this question for more info: https://bitcoin.stackexchange.com/questions/49853/utxo-model-vs-account-balance-model
chytrik
CC BY-SA 4.0
2021-04-15T00:46:08.973Z
2021-04-15T00:46:08.973Z
chytrik
<p>Do you want the balance shown to be specific to the user viewing the page, or the total balance contributed from all users?</p>
<p>The former requires more work, the latter is trivially simple.</p>
<p>You can use something like the blockstream API, called via cURL in PHP</p>
<p><a href="https://blockstream.info/api/address/AddressHere" rel="nofollow noreferrer">https://blockstream.info/api/address/AddressHere</a></p>
<p>&quot;chain_stats&quot; contains information for confirmed transactions that you can use to calculate the balance of the address</p>

CC BY-SA 4.0
2021-04-16T02:47:43.427Z
Not per user. Just overall. If the wallet has, say 0.5 BTC, then that's what it shows, regardless of who looks. But as soon as 0.1 BTC was transferred out, then people should see 0.4 BTC in the wallet. The actual list of transactions can be manually created easily.
Dan Egli
CC BY-SA 4.0
2021-04-14T22:42:21.777Z
2021-04-14T22:42:21.777Z
hydrabeast
<p>I am working on a project where people can contribute to the project in Bitcoin or Ethereum. For each I need a way to be able to display an active balance in each currency's wallet. Something along the lines of this:</p>
<p>You have elected to contribute in BTC to the project. Thank you. Your contributions are most welcome. Please send your BTC to 123abc456def. This wallet currently contains X Bitcoins, while Y have been contributed in total, and the contributed funds have been used for the purposes listed below.</p>
<p>And each time the person accesses the page, X and Y will reflect that wallet at that moment. I'd really prefer not to run a full copy of the blockchain for this. I already have bitcoind running with a 4GB pruned database, and I'm hoping that will be enough.</p>
<p>I need to do all this in PHP. Is there a good PHP toolkit/library/whatever that I can use to call the info?</p>
<p>Thanks!</p>

<wallet><php><website-integration>
Actively display wallet funds on web page - how?
Dan Egli
# Actively display wallet funds on web page - how?

(Asked by: username_0 on 2021-04-14)

I am working on a project where people can contribute to the project in Bitcoin or Ethereum. For each I need a way to be able to display an active balance in each currency's wallet. Something along the lines of this:

You have elected to contribute in BTC to the project. Thank you. Your contributions are most welcome. Please send your BTC to 123abc456def. This wallet currently contains X Bitcoins, while Y have been contributed in total, and the contributed funds have been used for the purposes listed below.

And each time the person accesses the page, X and Y will reflect that wallet at that moment. I'd really prefer not to run a full copy of the blockchain for this. I already have bitcoind running with a 4GB pruned database, and I'm hoping that will be enough.

I need to do all this in PHP. Is there a good PHP toolkit/library/whatever that I can use to call the info?

Thanks!

**Tags:** wallet, php, website-integration


---

## 2 answers

### Answer by username_1 on 2021-04-15. Score: 4

> I already have bitcoind running with a 4GB pruned database, and I'm hoping that will be enough.

It is! By running bitcoin-core, you can pull this data in an easy, trustless way.

I would recommend creating and displaying a new address to your patrons each time a new donation is received (so as to avoid address reuse, which is detrimental to your privacy, and perhaps more importantly your patron's privacy), but otherwise you should be able to accomplish your goal without much issue. You could perhaps look at something like [btcpayserver](https://docs.btcpayserver.org/) to help automate the payment flow on your website.

Here is a general workflow:

1. Generate a private key that will be used to receive funds, using your wallet of choice (ideally, this would be done in an offline environment)
2. Import the address(es) that are derived from the keys you generated in step one, into bitcoin-core. You can use `bitcoin-cli importaddress` to accomplish this step. Note that if the address is brand new and you know for certain it has never received funds before, then you can set `rescan` to `false`, to save a fair bit of computational time.
3. Use the command `bitcoin-cli listunspent` to return a list of UTXOs that are locked to addresses that the wallet is watching. You can optionally filter the returned info by address, see `bitcoin-cli help listunspent` for more info.
4. (Alternatively, you can use `bitcoin-cli getreceivedbyaddress`, which may be easier if you're re-using a single receiving address)
5. From there, you'll just need to parse the JSON data returned, and sum up the relevant address balance(s), to be displayed on your webpage.

> **Comments:**
> **username_0**: I often wonder about multiple addresses. The issue I see with using multiple addresses is the extra transaction fees each time the funds need  to be used. If I get a donation of 50mBTC from user 1, and 60mBTC from user 2,each sending to a different wallet, then I somehow need to consolidate all the funds before they can be used. That would seem to lean towards using a single address. Now if there's a free way of doing that I'm all ears. But that is a concern.  
> **username_1**: @username_0 you misunderstand how bitcoin fees work. Each received transaction create a UTXO, the cost of spending each UTXO as input in another transaction does not depend whatsoever on whether the coins are locked to the same address, or different addresses. There is absolutely no difference in terms of fees.  
> **username_0**: Maybe I am misunderstanding. If so please correct me. But my impression was this: USER A sends 40mBTC to Address 123abc. User 2 send another 40mBTC to address def456. Now, I have 80mBTC but it's split in to two chunks. To consolidate into one spendable lump, I need to maybe send the funds in wallet 2 to wallet 1. But that's an extra transaction, thus incuring extra transaction fees.  
> **username_1**: @username_0 you are assuming that bitcoin uses an 'account' model to keep track of coins, but that is incorrect, it uses a 'UTXO' model. Even if you use the same address, multiple payments will still create multiple UTXOs, which will incur the exact same fees as you would spending multiple UTXOs that are locked to different addresses. Needlessly consolidating funds is never a great idea though, just spend the UTXOs when you need to, no need to consolidate first. See this question for more info: https://bitcoin.stackexchange.com/questions/49853/utxo-model-vs-account-balance-model  
> **username_0**: I think I understand you better. But this still leaves me with a quandry. Let me suppose that I have received 600mBTC, but in six increments of 100mBTC each. So I have six UTXOs, that's great. But if they are in six wallets, then how do I send say 450mBTC to someone? Near as I can tell, I'd have to send all 100mBTC from wallets 1-4, then the balance from wallet 5. And each of those would generate a transaction fee.Unless there's a way to make various addresses aliases for the same wallet? I don't care if I use 200,000 addresses as long as I don't have to take the funds from multiple wallets.  
> **username_0**: As to btcpayserver, I looked at it. I kind of like the idea, but I can't seem to figure out how I could download the software or anything. They talk about hosting on various servers, but almost all of them seem to be hosting services. We already have the VPS. It's been running other things for months now. So obviously we don't want to move the entire setup to a new server. So, how do I obtain the software for download to our server, and how do I actually install that software? That's what I can't seem to figure out.  
> **username_1**: @username_0 comments are not intended for discussions, if you have further questions you should use the search function/create new posts. But in brief: a *wallet* will contain many, many *addresses* (keypairs). Receiving to a new address (which is from the same wallet) each and every payment is the standard and highly recommended workflow, your wallet software will manage all of the keys and transaction creation in the background. Installing btcpayserver isn’t too difficult, but it does require some technical skills. See https://docs.btcpayserver.org/Deployment/  

---

### Answer by username_2 on 2021-04-14. Score: 0

Do you want the balance shown to be specific to the user viewing the page, or the total balance contributed from all users?

The former requires more work, the latter is trivially simple.

You can use something like the blockstream API, called via cURL in PHP

<https://blockstream.info/api/address/AddressHere>

"chain\_stats" contains information for confirmed transactions that you can use to calculate the balance of the address

> **Comments:**
> **username_0**: Not per user. Just overall. If the wallet has, say 0.5 BTC, then that's what it shows, regardless of who looks. But as soon as 0.1 BTC was transferred out, then people should see 0.4 BTC in the wallet. The actual list of transactions can be manually created easily.  

---

