5

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:

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.

2 Answers 2

2

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.

6
  • 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
    Oct 19, 2012 at 12:05
  • 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. Oct 19, 2012 at 12:45
  • 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
    Oct 19, 2012 at 12:53
  • 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. Oct 19, 2012 at 12:54
  • 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
    Oct 19, 2012 at 13:02
1

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

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.

1
  • Hi Stephen, thanks for answering. Sorry but I don't quite understand the concept of unspent transactions. What is an unspent transaction? ;-)
    – flaab
    Oct 18, 2012 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.