parse bitcoin addresses from transactions acquired by means of the P2P protocol utilizing python

on

|

views

and

comments


I’m assuming that you’re truly simply involved in getting data on each transaction your node sees, reasonably than the precise p2p site visitors.

In that case, right here is how I’d strategy your drawback:

  1. Run a Bitcoin Core full node. If you happen to solely care about unconfirmed transactions, take into account making it a pruned node. If you wish to accumulate information on all transactions, make it a non-pruning node and allow the transaction index with txindex=1.
  2. Set up PyZMQ
  3. Allow ZeroMQ.
  4. Hearken to the hashtx ZMQ notifications
    hashtx notifies about all transactions, both when they’re added to mempool or when a brand new block arrives, so chances are you’ll get a number of notifications for a similar txid.
  5. For every hashtx notification you obtain, test if the transaction is seen for the primary time, then name bitcoin-cli getrawtransaction <txid>. Within the response, learn the worth and handle fields for every component of the vout vector. Optionally learn n to get the output’s index. Observe that some outputs don’t have addresses, e.g. P2PK and nulldata (OP_RETURN) outputs.
  6. Optionally: Retailer the ensuing outputs in a database utilizing their “outpoint” (txid:n) as the important thing.

Observe that some txs you see in your mempool could get changed by a later transaction. If you wish to be sure to solely maintain transactions that find yourself being a part of the most effective chain, chances are you’ll wish to monitor transactions in blocks reasonably than transactions within the mempool, and you should definitely deal with blockchain reorganizations.

If that’s too gradual to your functions, you may get a complete block explorer of your personal by operating an occasion of mempool.area or Esplora. Alternatively, you may most likely pay for an API key to get this (public!) information from plenty of completely different block explorers.

Observe that you just may must easy out some corners on this strategy if you would like use it, I’ve not examined this. There may additionally be simpler extra environment friendly methods, I by no means tried to unravel this drawback myself.

Share this
Tags

Must-read

‘Lidar is lame’: why Elon Musk’s imaginative and prescient for a self-driving Tesla taxi faltered | Tesla

After years of promising traders that thousands and thousands of Tesla robotaxis would quickly fill the streets, Elon Musk debuted his driverless automobile...

Common Motors names new CEO of troubled self-driving subsidiary Cruise | GM

Common Motors on Tuesday named a veteran know-how government with roots within the online game business to steer its troubled robotaxi service Cruise...

Meet Mercy and Anita – the African employees driving the AI revolution, for simply over a greenback an hour | Synthetic intelligence (AI)

Mercy craned ahead, took a deep breath and loaded one other process on her pc. One after one other, disturbing photographs and movies...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here