<p>If you want to identify incoming payments, the recommended way is creating a new receive address for every request. When the confirmations of a transaction to a given address get high enough, you can consider the payment confirmed.</p>

<p>Using the 'sender address' does not give you reliable information - it can only identify (one of the) addresses that were previously in control of the coins. There is no guarantee that these correspond to the sender of the payment (it may be a webwallet with shared coins, for example).</p>

<p>Not reusing addresses also has other benefits, like making bitcoins as a whole less easily traceable.</p>

CC BY-SA 3.0
2012-10-19T12:05:18.100Z
Hi Pieter! For what I've seen, the first input is always the sender address. Am I right? My app needs to send back a certain amount of bitcoins as well -as a confirmation-.
flaab
CC BY-SA 3.0
2012-10-19T12:45:40.637Z
Bitcoin does not have sender addresses. A transaction consumes coins, and creates new coins from them - possibly assigned to new addresses. You can see the incoming transaction, check which previous outputs it consumes, check which addresses those were previously assigned to, and use the first of those as a 'sender', but that only tells you an address that controlled the coins, not who sent them (which is a problem when the sender uses a shared webwallet, for example). This is bad practice as it also encourages address reuse. If you need to send coins back, ask for a refund address.
Pieter Wuille
CC BY-SA 3.0
2012-10-19T12:53:07.430Z
Hi Pieter, thanks a lot for your answer. I might just do that. As a technical sidenote, how does the website "Satoshi Dice" do that? It sends back the coins to the right address by checking the first input, right?
flaab
CC BY-SA 3.0
2012-10-19T12:54:24.277Z
Yes, unfortunately. This results in a lot of unnecessary traffic, address reuse (which decreases privacy in the system for everyone), and doesn't work for people using shared wallets.
Pieter Wuille
CC BY-SA 3.0
2012-10-19T13:02:59.853Z
Hi Pieter! I understand. I am concerned about creating a new address for each payment, because I haven't found a way to "delete" receiving addresses, which would create junk in my bitcoin wallet. I prefer having just one receiving address, checked constantly. I should then check the wallet for new transactions using listunspent function. Right?
flaab
CC BY-SA 3.0
2013-10-16T06:22:58.113Z
hi flaab, what method did you end up using?
Anthony Chua
CC BY-SA 3.0
2012-10-18T21:54:14.347Z
2012-10-18T21:54:14.347Z
Pieter Wuille
<p>Raw transactions provides the information about the Inputs ("sender addresses", as you refer to them). </p>

<ul>
<li><a href="http://en.bitcoin.it/wiki/Raw_Transactions" rel="nofollow">http://en.bitcoin.it/wiki/Raw_Transactions</a></li>
</ul>

<p>In that is ListUnspent which will give you all the Transaction Ids, output addresses ("receiving address") and amounts.  From that you can compare against your list to tell which are new.</p>

CC BY-SA 3.0
2012-10-18T21:30:10.800Z
Hi Stephen, thanks for answering. Sorry but I don't quite understand the concept of unspent transactions. What is an unspent transaction? ;-)
flaab
CC BY-SA 3.0
2012-10-18T18:19:28.310Z
2012-10-18T18:19:28.310Z
Stephen Gornick
<p>Good afternoon,</p>

<p>I am struggling a bit to receive Bitcoin payments at my online store. So far, I have installed bitcoind in my system and created a set of receiving addresses, and now I face the problem of checking for new payments.</p>

<p>I am using the following resources: </p>

<ul>
<li><a href="https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list" rel="noreferrer">https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list</a></li>
<li><a href="http://code.gogulski.com/bitcoin-php/class_bitcoin_client.html" rel="noreferrer">http://code.gogulski.com/bitcoin-php/class_bitcoin_client.html</a></li>
</ul>

<p>I would like to make a cron job that searches for new payments and stores each one of them into a relational database, each transaction identified by:</p>

<ul>
<li>Transaction ID</li>
<li>Sender's address</li>
<li>Amount as a 64-bit integer</li>
</ul>

<p>Everything is pretty easy but I can't find an efficient way of extracting the new incoming transactions from my bitcoin daemon. For instance, I am able to extract the balance of each address, but I don't find a feasible way to obtain a collection of incoming transactions with all required data. This creates a further problem because I don't want to process transactions twice.</p>

<p>Which is the best way to do it using the API?</p>

<p>Thank you very much.</p>

<payment><api>
Bitcoin API - How can I identify new incoming payments?
flaab
# Bitcoin API - How can I identify new incoming payments?

(Asked by: username_0 on 2012-10-18)

Good afternoon,

I am struggling a bit to receive Bitcoin payments at my online store. So far, I have installed bitcoind in my system and created a set of receiving addresses, and now I face the problem of checking for new payments.

I am using the following resources:

* <https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list>
* <http://code.gogulski.com/bitcoin-php/class_bitcoin_client.html>

I would like to make a cron job that searches for new payments and stores each one of them into a relational database, each transaction identified by:

* Transaction ID
* Sender's address
* Amount as a 64-bit integer

Everything is pretty easy but I can't find an efficient way of extracting the new incoming transactions from my bitcoin daemon. For instance, I am able to extract the balance of each address, but I don't find a feasible way to obtain a collection of incoming transactions with all required data. This creates a further problem because I don't want to process transactions twice.

Which is the best way to do it using the API?

Thank you very much.

**Tags:** payment, api


---

## 2 answers

### Answer by username_1 on 2012-10-18. Score: 2 | Accepted answer

If you want to identify incoming payments, the recommended way is creating a new receive address for every request. When the confirmations of a transaction to a given address get high enough, you can consider the payment confirmed.

Using the 'sender address' does not give you reliable information - it can only identify (one of the) addresses that were previously in control of the coins. There is no guarantee that these correspond to the sender of the payment (it may be a webwallet with shared coins, for example).

Not reusing addresses also has other benefits, like making bitcoins as a whole less easily traceable.

> **Comments:**
> **username_0**: Hi username_1! For what I've seen, the first input is always the sender address. Am I right? My app needs to send back a certain amount of bitcoins as well -as a confirmation-.  
> **username_1**: Bitcoin does not have sender addresses. A transaction consumes coins, and creates new coins from them - possibly assigned to new addresses. You can see the incoming transaction, check which previous outputs it consumes, check which addresses those were previously assigned to, and use the first of those as a 'sender', but that only tells you an address that controlled the coins, not who sent them (which is a problem when the sender uses a shared webwallet, for example). This is bad practice as it also encourages address reuse. If you need to send coins back, ask for a refund address.  
> **username_0**: Hi username_1, thanks a lot for your answer. I might just do that. As a technical sidenote, how does the website "Satoshi Dice" do that? It sends back the coins to the right address by checking the first input, right?  
> **username_1**: Yes, unfortunately. This results in a lot of unnecessary traffic, address reuse (which decreases privacy in the system for everyone), and doesn't work for people using shared wallets.  
> **username_0**: Hi username_1! I understand. I am concerned about creating a new address for each payment, because I haven't found a way to "delete" receiving addresses, which would create junk in my bitcoin wallet. I prefer having just one receiving address, checked constantly. I should then check the wallet for new transactions using listunspent function. Right?  
> **username_2**: hi username_0, what method did you end up using?  

---

### Answer by username_3 on 2012-10-18. Score: 1

Raw transactions provides the information about the Inputs ("sender addresses", as you refer to them).

* <http://en.bitcoin.it/wiki/Raw_Transactions>

In that is ListUnspent which will give you all the Transaction Ids, output addresses ("receiving address") and amounts. From that you can compare against your list to tell which are new.

> **Comments:**
> **username_0**: Hi username_3, thanks for answering. Sorry but I don't quite understand the concept of unspent transactions. What is an unspent transaction? ;-)  

---

