<p>BIP004 states that a derivation path's 4th digit will be 1 if it is a change address like this:</p>

<p>m / purpose' / coin_type' / account' / change / address_index</p>

<p><a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#change" rel="nofollow noreferrer">https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#change</a></p>

<p>The idea is that once money is spent from a given address, the left over is moved in to a new address which is used as the change address. Wallet software should not leave the left over funds in an address in the old address, they should be moved to the new address. I guess that some wallets follow this, and some don't. But wallets that do not follow this would be breaking the BIP.</p>

<p>So, my question is, from looking at a given address on the blockchain is there a programmatic way to tell where the funds have been moved to?</p>

<p>If you have the public key and the derivation path for the address, you can derive the change address, but if I don't have these things, is there a way to figure it out? Or, at least to take a good guess as to what it might be based on where the funds are moved to?</p>

<p><strong>Use Case (View-Only Wallet):</strong></p>

<ul>
<li>User adds a loose address to their wallet (without public key)</li>
<li>App scans blockchain for address</li>
<li>App realizes balance has changed and transaction occurred</li>
<li>Funds have moved to another address, but app can't figure this out without prompting user, or displaying an incorrect balance.</li>
</ul>

CC BY-SA 3.0
2018-03-05T10:24:50.483Z
The change address is always an additional output in the transaction. I am not aware that there is a way to discriminate between outputs what may be a legitimate change address but, there may be?
Willtech
CC BY-SA 3.0
2018-03-06T21:50:01.157Z
Yep. That's what I mean. The change address will be there, but the question is how to discriminate between the two.
Christian Findlay
<address><api><blockexplorer>
Programmatically Get Change Address From Blockchain
Christian Findlay
# Programmatically Get Change Address From Blockchain

(Asked by: username_0 on 2018-03-05)

BIP004 states that a derivation path's 4th digit will be 1 if it is a change address like this:

m / purpose' / coin\_type' / account' / change / address\_index

<https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#change>

The idea is that once money is spent from a given address, the left over is moved in to a new address which is used as the change address. Wallet software should not leave the left over funds in an address in the old address, they should be moved to the new address. I guess that some wallets follow this, and some don't. But wallets that do not follow this would be breaking the BIP.

So, my question is, from looking at a given address on the blockchain is there a programmatic way to tell where the funds have been moved to?

If you have the public key and the derivation path for the address, you can derive the change address, but if I don't have these things, is there a way to figure it out? Or, at least to take a good guess as to what it might be based on where the funds are moved to?

**Use Case (View-Only Wallet):**

* User adds a loose address to their wallet (without public key)
* App scans blockchain for address
* App realizes balance has changed and transaction occurred
* Funds have moved to another address, but app can't figure this out without prompting user, or displaying an incorrect balance.

**Tags:** address, api, blockexplorer

> **Comments:**
> **username_1**: The change address is always an additional output in the transaction. I am not aware that there is a way to discriminate between outputs what may be a legitimate change address but, there may be?  
> **username_0**: Yep. That's what I mean. The change address will be there, but the question is how to discriminate between the two.  

---

## 0 answers

