bitcoin-send-tx-p2p

Crates.iobitcoin-send-tx-p2p
lib.rsbitcoin-send-tx-p2p
version0.2.0
sourcesrc
created_at2022-08-15 19:42:49.3304
updated_at2023-11-13 01:17:49.678477
descriptionSend a bitcoin tx through the peer-to-peer protocol via clearnet or tor
homepagehttps://github.com/andrewtoth/bitcoin-send-tx-p2p/
repositoryhttps://github.com/andrewtoth/bitcoin-send-tx-p2p/
max_upload_size
id646138
size40,612
(andrewtoth)

documentation

https://docs.rs/bitcoin-send-tx-p2p/

README

Bitcoin Send Tx P2P

Library for sending bitcoin transactions to nodes using the bitcoin peer-to-peer protocol, given only a transaction and the IP or onion address of the node.

Under the hood it creates a connection to the node and performs the version handshake. Then it sends an inv message with the txid or wtxid and waits for a getdata message. After transmitting a tx message with the full transaction it disconnects. Note that if the receiving node already has the transaction it will not respond with a a getdata message, in which case the sending function will timeout and disconnect.

Installation

Run the following Cargo command in your project directory:

cargo add bitcoin-send-tx-p2p

Or add the following line to your Cargo.toml:

bitcoin-send-tx-p2p = "0.2.0"

Examples

use bitcoin::Transaction;

use bitcoin_send_tx_p2p::{send_tx_p2p_over_clearnet, send_tx_p2p_over_tor, Config, Error};

async fn send_tx(tx: Transaction) -> Result<(), Error> {
    let mut config = Config::default();
    config.block_height = 1000;
    send_tx_p2p_over_clearnet("127.0.0.1:8333".parse()?, tx, Some(config)).await
}

async fn send_tx_tor(tx: Transaction) -> Result<()> {
    send_tx_p2p_over_tor("cssusbltvosy7hhomxuhicmh5svw6e4z3eebgnyjcnslrloiy5m27pid.onion:8333", tx, None).await
}
Commit count: 11

cargo fmt