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:
- 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
. - Set up
PyZMQ
- Allow ZeroMQ.
- Hearken to the
hashtx
ZMQ notificationshashtx
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. - For every
hashtx
notification you obtain, test if the transaction is seen for the primary time, then namebitcoin-cli getrawtransaction <txid>
. Within the response, learn theworth
andhandle
fields for every component of thevout
vector. Optionally learnn
to get the output’s index. Observe that some outputs don’t have addresses, e.g. P2PK and nulldata (OP_RETURN) outputs. - 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.