How to get confirmations for incoming transactions? I'm currently working on accepting Bitcoins on my website. To do this I create a new address for every sale. I know I can get the amount of bitcoins that were paid into this address by using ./btcoind getreceivedbyaddress &lt;the-address&gt; 0 or conn.getreceivedbyaddress(localAddress, 0) when using the python binding for bitcoin. So far so good.

I now also want to get and display the amount of confirmations to the customer. So I made this:

highestConfirmCount = None
for i in count():
    received = btcConn.getreceivedbyaddress(localAddress, i)
    if received &gt;= amountExpected:
        highestConfirmCount = i
    else:
        break
print highestConfirmCount


This works fine, but it's pretty slow for incoming payments which have been a while ago. Also, I would presume there would be a better and more efficient built in function for this, but I can't find anything like it.

Does anybody know what the best way is for getting confirmations for incoming payments to a specific address?
Calling bitcoin-cli listunspent 0 9999999 "[\"someLocalAddress\",\"someOtherLocalAddress\"]" will provide you with the exact number of confirmations for every transaction to these addresses so you will not need to perform all these iterations. 

Replacing 9999999 with what you consider in your application to be a confirmed transaction will only return the unconfirmed transactions, which is more effective if you already keep track of the confirmed transactions in your database.