Crates.io | bitcoin-send-tx-p2p |
lib.rs | bitcoin-send-tx-p2p |
version | 0.2.0 |
source | src |
created_at | 2022-08-15 19:42:49.3304 |
updated_at | 2023-11-13 01:17:49.678477 |
description | Send a bitcoin tx through the peer-to-peer protocol via clearnet or tor |
homepage | https://github.com/andrewtoth/bitcoin-send-tx-p2p/ |
repository | https://github.com/andrewtoth/bitcoin-send-tx-p2p/ |
max_upload_size | |
id | 646138 |
size | 40,612 |
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.
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"
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
}