I would like to create a python script that listens to the bitcoin network and monitors some addresses, stored in a mysql db. As soon as a transaction is broadcast with one of these addresses as an output, the script should run a function.

I do not need to store the whole blockchain, nor do I want to. The private keys are also not on the same machine, for security. There is no wallet on this machine, just a list of addresses in a DB.

For the moment I have implemented this with the webhooks from blockchain.info and also tested with blocktrail. It works but it does not work fast enough te achieve my goals, these solutions are just too slow to be practical. I need to be notified instantly.

I've looked at several options but none seem to fit as a good starting point. (BitcoinJ seems the closest but it is in Java) I cannot believe there is no such thing in existence, I just couldn't find one.

So, can you steer me in the right direction?

3 Answers 3


If you just listen to transactions on the network without having a validating node of your own you will have absolutely no way of knowing if they are legitimate or not. You must have a fully validating node locally, otherwise transactions can be cost-lessly fabricated to spend any amount of money anywhere. There is no recourse if you get this wrong, this is primarily why nobody has implemented any sort of validation in Python, there's various bits of the p2p protocol on Github, but it does exactly zero consensus validation on the data it receives.

The current master of Bitcoin Core (and the up coming 0.12 release at the end of the year) both contain a ZMQ interface which gives you a real time supply of validated transactions. A full node (pruned) can be run in as little as 2GB of space, and isn't very resource intensive for somebody running a business. There's example code for that available on github as zmq_sub.py which should get you started, just be aware that ZMQ has no guarantee of deliverability, some messages may be silently dropped if there are connectivity issues.

It's important to keep in mind that an unconfirmed transaction has no guarantee of being confirmed, and may be invalidated at any point in time. Accepting zero confirmations is extremely risky, though updating a user interface with a list of unconfirmed transactions is perfectly reasonable behaviour.

  • I haven't looked at the problem this way. It is very true what you are saying. I need validated transactions and I need more than zero confirmations, yes. BUT, what I'm trying to achieve is that a customer can pay me instore at our POS. I can't tell my customer hey wait a couple of minutes 'till I get x confirmations. He's used to instant verification of his debit/creditcard. I think I will need to implement levels of amount versus confirmations, like under $10 value = 0 conf, $100=1, ..., and $10.000+ = 6 conf.
    – DDecoene
    Commented Oct 22, 2015 at 14:54
  • You can't safely do this with Bitcoin, it is not designed for it. Pretending otherwise can leave you an unlimited amount of money out of pocket, companies have lost hundreds of thousands of dollars to very unsophisticated attacks against zero confirmation transactions. Possibly with payment channels in the future instant transactions with Bitcoin might be an option, but not today.
    – Claris
    Commented Oct 22, 2015 at 15:11
  • OT Danger: It is my desire to help make crypto's mainstream. I'm a founder of Ieper bitcoincity www.ieperbitcoinstad.be and involved in a similar project in Kortrijk, both in Belgium. To do this, we cannot use an altcoin, that could address these problems. All people know right now is Bitcoin. They have heard about it somewhere. We inform people with our initiatives. To get the ball rolling I wanted to offer storekeepers a platform for accepting BTC and get EUR deposited on their account, like bitpay and bitkassa, just local, Belgian, trusted. Aim is to help transition. How to they do it then?
    – DDecoene
    Commented Oct 22, 2015 at 19:14
  • The longer term goal of my platform is that storekeepers will say 'hey, I don't need to convert to Eur no more, I can pay my suppliers with BTC'. This could then create an ecosystem that is sustainable. I compare BTC to internet in '93. People wondered what that http or @ meant and such. Now we are the pioneers in the financial revolution. Revolutions are risky ;-) I've never shied away from (calculated) risks. I'm not planning on going bankrupt but completely safe is an illusion in business anyhow. Thank you for your welcome input sir I really appreciate it.
    – DDecoene
    Commented Oct 22, 2015 at 19:20
  • 1
    Nobility doesn't solve technical issues though
    – Claris
    Commented Oct 23, 2015 at 3:22

In the end I went with The websocket API from Blockchain in combination with the python websocket client from Hiroki Ohtani. This mechanism is really instantaneous and seems stable and usable. However, I still have concerns around having to put my eggs in one basket. So, I double check and also use Blocktrail's webhooks api.

This system still does not give me 100% foolproof security but I can live with this setup, until a better system comes along, or I can make something better.

Thank you all for helping out, and I hope this answer may serve as an idea/basis for your own Bitcoin projects!


If you have a raw copy of the transaction, you could re-publish it over and over again until it gets confirmed. Even with very low transaction fees it should get confirmed in the end (but it might take long)

  • But how do you find out whether it's confirmed? And, on a related note, if it isn't confirmed, how do you know whether it's valid?
    – Nick ODell
    Commented Feb 8, 2016 at 1:16

Your Answer

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

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