Skip to main content

Listen to the bitcoin p2p transaction data

bitcoin-p2p can listen (no verification) to the p2p traffic of a bitcoin node and display the transactions like:

import socket, asyncio
import bdkpython as bdk
from bitcoin_p2p import tools, p2p
# see https://github.com/andreasgriffin/bitcoin-p2p

global_dict = {}

def callback_min_feerate(feerate):
    global_dict['feerate'] = feerate
    

def callback_recv_tx(tx_bytes):
    transaction = tools.transaction_from_bytes(tx_bytes)
    print(tools.transaction_table(transaction))
    
    

await p2p.listen(p2p.get_bitcoin_peer(), callback_recv_tx=callback_recv_tx, callback_min_feerate=callback_min_feerate )

with the output:

Received sendheaders command
Received sendcmpct
Received sendcmpct
Received ping
Received getheaders
Received feefilter, minimum feerate is 4477
Inventory count 18
+---------------------------------------------------------------------------------------------------------------------+
|                    Transaction: b3b7bcec03759c53580be4722227239f83197ce966af73139f6348f4d19b2e7d                    |
+--------------------------------------------------------------------+------------------------------------+-----------+
|                               Inputs                               |           Output Address           |   Amount  |
+--------------------------------------------------------------------+------------------------------------+-----------+
| d90af911da1d24b03b01047a9f57af5df354cff1f6394ea01200b8577712766d:0 | 33mX6JQUgXTun9m6DkmXMBugxHboYrUdbp | 105511580 |
+--------------------------------------------------------------------+------------------------------------+-----------+
+----------------------------------------------------------------------------------------------------------------------------------------------+
|                                Transaction: c4b75ce9c4c3fcf43054d7fbe502585a4be30b80dac31f8bfa4845aeab06a967                                 |
+--------------------------------------------------------------------+----------------------------------------------------------------+--------+
|                               Inputs                               |                         Output Address                         | Amount |
+--------------------------------------------------------------------+----------------------------------------------------------------+--------+
| c13f038c2b30b057c73d8dc694d2a6b742538e8b31e387478e30c715e6e97993:1 |               16G1xYBbiNG78LSuZdMqp6tux5xvVp9Wxh               |  546   |
| 0ae8edcd1299f7672e02e4c02c02d00a78367731913d1cc7a66118a3b1b7be55:1 | bc1parapxed82turc2hj99wgdxf0hz96s240200dnw0zx30f8t9vmgaql98ha0 | 94681  |
+--------------------------------------------------------------------+----------------------------------------------------------------+--------+
+----------------------------------------------------------------------------------------------------------------------+
|                    Transaction: 05455dcec23f81c2273eb003390b4427d1e3660709c45c6b90347525fc2ad5bc                     |
+--------------------------------------------------------------------+------------------------------------+------------+
|                               Inputs                               |           Output Address           |   Amount   |
+--------------------------------------------------------------------+------------------------------------+------------+
| d768d96b5aba03582a9e0c71a6859cc629cfb7dce40e53012b797f50ae45d063:1 | 3614Z6uv6tc738p76XP6uYVkkPcueVFCcY |  40000000  |
|                                                                    | 12vVbKJbTYYYvDZw3B8V6HRsjhesQCc121 | 1049819426 |
+--------------------------------------------------------------------+------------------------------------+------------+

Install package

From pypi

pip install bitcoin_p2p

From git

python setup.py sdist bdist_wheel
pip install dist/bitcoin_p2p-0.1-py3-none-any.whl   

Metadata

Release files for bitcoin-p2p 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bitcoin-p2p 0.3.4
File Size Uploaded Provenance Actions
bitcoin_p2p-0.3.4.tar.gz 21.8 kB Without provenance Details for bitcoin_p2p-0.3.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bitcoin-p2p 0.3.4
File Interpreter ABI Platform Actions
bitcoin_p2p-0.3.4-py3-none-any.whl Python 3 none any Details for bitcoin_p2p-0.3.4-py3-none-any.whl

Total release size: 42.7 kB

Release files / bitcoin_p2p-0.3.4.tar.gz

Download URL bitcoin_p2p-0.3.4.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
30b07a8983e5dfd6b8a9ac3c023e9ea6b35fbdeef5df7a6c1d867297d80cc3ef
BLAKE2b-256 checksum
How to use checksums
5d2952dc11f2b26930c359b3baa29dda2657ef8229d6d353d3e95ba44fa58006
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / bitcoin_p2p-0.3.4-py3-none-any.whl

Download URL bitcoin_p2p-0.3.4-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d3fce149414d266d66b5ae2c50264f3ae4e2a8b8b383b24749776c47d2c3a57
BLAKE2b-256 checksum
How to use checksums
83655e31b19ab066817aa29a3d1846e6f5d34b587bd8dcc8c5e70904fadc6f6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Security for bitcoin-p2p 0.3.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page