Create raw transaction in python

0

I have a private key (raw + WIF) and I want to send all funds from that address - fee to another address.

Is there a raw python function that can do that for me ? I will broadcast the tx manually.

I tried to look into electrum source code but I find it to complicated for this task please help.

sektor

Posted 2016-03-19T20:48:28.033

Reputation: 143

Answers

3

pycoin is probably your best bet. You need the utxo first, which you'll need to look up somewhere (blockchain.info is fine). Once you have the utxos, they'd need to be TxIns like this:

tx_in = TxIn("<utxo hash in binary here>", <utxo position, usually between 0 and 5>)
script = standard_tx_out_script(address)
tx_out = TxOut(<btc amount to send - fee>, script)
tx = Tx(1, [tx_in], [tx_out])
lookup = <this part you have to figure out>
tx.sign(lookup)
print tx.as_hex()

You can take the results and paste to something like blockchain.info's send transaction page.

NOTE: It's very easy to screw this up and have a too-high tx fee or lose your coins altogether. I would NOT recommend it. Install Armory and import the key or do the same using Mycelium. It's a lot safer to do it that way.

Jimmy Song

Posted 2016-03-19T20:48:28.033

Reputation: 7 067