Crate pushtx

source ·
Expand description

§Bitcoin Transaction Broadcast Library

This is a library that broadcasts Bitcoin transactions directly into the P2P network by connecting to a set of random Bitcoin nodes. This differs from other broadcast tools in that it does not not interact with any centralized services, such as block explorers.

If Tor is running on the same system, connectivity to the P2P network is established through a newly created circuit. Having Tor Browser running in the background is sufficient. Tor daemon also works.

§Fine-tuning

The broadcast process can be fine-tuned using the Opts struct. Please refer to its documentation for details.

§Example

 // this is our hex-encoded transaction that we want to parse and broadcast
 let tx = "6afcc7949dd500000....".parse().unwrap();

 // we start the broadcast process and acquire a receiver to the info events
 let receiver = pushtx::broadcast(vec![tx], pushtx::Opts::default());

 // start reading info events until `Done` is received
 loop {
     match receiver.recv().unwrap() {
         pushtx::Info::Done(Ok(report)) => {
             println!("we successfully broadcast to {} peers", report.broadcasts);
             break;
         }
         pushtx::Info::Done(Err(err)) => {
             println!("we failed to broadcast to any peers, reason = {err}");
             break;
         }
         _ => {}
     }
 }

Structs§

  • Various options
  • An informational report on a successful broadcast process.
  • A Bitcoin transaction to be broadcast into the network.

Enums§

  • Possible error variants while broadcasting.
  • Defines how the initial pool of peers that we broadcast to is found.
  • Informational messages about the broadcast process.
  • The network to connect to.
  • Why an input could not be interpereted as a valid transaction.
  • Determines how to use Tor. The default is BestEffort.

Functions§

  • Connects to the p2p network and broadcasts a series of transactions. This runs fully in the background. Network and other parameters can be set through the opts argument.