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!("{} transactions broadcast successfully", report.success.len());
break;
}
pushtx::Info::Done(Err(err)) => {
println!("we failed to broadcast to any peers, reason = {err}");
break;
}
_ => {}
}
}
Structs§
- Opts
- Various options
- Report
- An informational report on a broadcast outcome.
- Transaction
- A Bitcoin transaction to be broadcast into the network.
- Txid
Enums§
- Error
- Possible error variants while broadcasting.
- Find
Peer Strategy - Defines how the initial pool of peers that we broadcast to is found.
- Info
- Informational messages about the broadcast process.
- Network
- The network to connect to.
- Parse
TxError - Why an input could not be interpereted as a valid transaction.
- TorMode
- Determines how to use Tor. The default is
BestEffort
.
Functions§
- broadcast
- 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.