<p>In case you have not seen it, there is a good (IMHO) article which describes how to generate a transaction "manually" using "raw" python (no bitcoin libs or RPC): <a href="http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html">
"Bitcoins the hard way: Using the raw Bitcoin protocol"</a></p>

CC BY-SA 3.0
2014-09-17T12:47:06.353Z
2014-09-17T12:47:06.353Z
jliendo
<p><a href="https://en.wikipedia.org/wiki/Vitalik_Buterin" rel="nofollow noreferrer">Vitalik Buterin</a> has recently shared <a href="https://github.com/vbuterin/pybitcointools" rel="nofollow noreferrer">Pybitcointools</a>, a nice and simple-to-use Python library for handcrafting Bitcoin transactions. <a href="https://github.com/vbuterin/pybitcointools#example-usage-best-way-to-learn--" rel="nofollow noreferrer">The example</a> shows the basic workflow, which is pretty much what you have described in your example (just broken down to few more steps).</p>

<p>If you need more help, <a href="http://whatdoesthequantsay.com/2014/05/04/bitcoin-transactions-technically-part-2" rel="nofollow noreferrer">this nice article</a> explains bitcoin transactions technically and shows examples using the <strong>Pybitcointools</strong> library.</p>

CC BY-SA 3.0
2014-09-17T11:01:22.853Z
2017-01-23T15:45:41.703Z
2017-01-23T15:45:41.703Z
knaperek
<p>I think that <a href="https://github.com/richardkiss/pycoin" rel="nofollow">PyCoin</a> would serve your needs.</p>

<p><a href="https://github.com/richardkiss/pycoin/blob/master/tests/tx_utils_test.py" rel="nofollow">This test case shows how to construct a transaction.</a></p>

<p><a href="https://github.com/richardkiss/pycoin/blob/master/tests/key_translation_test.py" rel="nofollow">This test case shows how to use Wallet Import Format with PyCoin.</a></p>

<p>I'd also like to note that this is not a very good idea. Suppose that your input is actually 20 BTC instead of 10. What will happen is that Bitcoin will interpret the extra 10 BTC as a fee to be collected by the miner.</p>

CC BY-SA 3.0
2014-09-17T06:58:05.013Z
Note that in addition to the destination address and the private key, the other piece of data you need is the utxo (id and output number from a previous transaction) which is to be spent. Unless you happen to know what is, you'll need a Bitcoin client (or access to a copy of the block chain) to find an appropriate utxo given the private key.
Nate Eldredge
CC BY-SA 3.0
2014-09-17T06:32:24.727Z
2014-09-17T06:32:24.727Z
Nick ODell
<p>Lets say I have a bitcoin address that has 10 BTC sent to it. I also have the private key for this address</p>

<p>Using Python (2 or 3) is there a way to create a signed transaction (which I believe is a long string of hex digits) that can then be sent to an external service (bockchain.info or whatever) for network propogation.</p>

<p>It seems all the python libraries for making transactions require a connection to the bitcoind rpc interface. In my application, there will be no locally ran bitcoind.</p>

<p>I'm thinking the code I'm looking for is like this:</p>

<pre><code>address = '1ALis8zeW1XduXf98ZjoL4EKLen5mVA1q4'
private = '5KiUZd5as1TKsiwnt1KiPgiECtXiuF9BS1MxrAgedNrXcScm4d5'

from some_btc_library import make_transaction

tx_hex = make_transaction(
    inputs=[[address, private]],
    to='123rn4tNGhf1ZehQHLohYn8WRQYhjeGSCw',
    amount=3,
    miner_fee=0.0001
)

send_to_exteral_service(tx_hex)
print "transaction complete"
</code></pre>

<raw-transaction><python>
Is it possible to create a transaction in pure python without needing to run bitcoin locally?
priestc
# Is it possible to create a transaction in pure python without needing to run bitcoin locally?

(Asked by: username_0 on 2014-09-17)

Lets say I have a bitcoin address that has 10 BTC sent to it. I also have the private key for this address
Using Python (2 or 3) is there a way to create a signed transaction (which I believe is a long string of hex digits) that can then be sent to an external service (bockchain.info or whatever) for network propogation.
It seems all the python libraries for making transactions require a connection to the bitcoind rpc interface. In my application, there will be no locally ran bitcoind.
I'm thinking the code I'm looking for is like this:
address = '1ALis8zeW1XduXf98ZjoL4EKLen5mVA1q4'
private = '5KiUZd5as1TKsiwnt1KiPgiECtXiuF9BS1MxrAgedNrXcScm4d5'

from some_btc_library import make_transaction

tx_hex = make_transaction(
    inputs=[[address, private]],
    to='123rn4tNGhf1ZehQHLohYn8WRQYhjeGSCw',
    amount=3,
    miner_fee=0.0001
)

send_to_exteral_service(tx_hex)
print "transaction complete"

**Tags:** raw-transaction, python


---

## 3 answers

### Answer by username_1 on 2014-09-17. Score: 15

In case you have not seen it, there is a good (IMHO) article which describes how to generate a transaction "manually" using "raw" python (no bitcoin libs or RPC): ["Bitcoins the hard way: Using the raw Bitcoin protocol"](http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html)


---

### Answer by username_2 on 2014-09-17. Score: 9

[Vitalik Buterin](https://en.wikipedia.org/wiki/Vitalik_Buterin) has recently shared [Pybitcointools](https://github.com/vbuterin/pybitcointools), a nice and simple-to-use Python library for handcrafting Bitcoin transactions. [The example](https://github.com/vbuterin/pybitcointools#example-usage-best-way-to-learn--) shows the basic workflow, which is pretty much what you have described in your example (just broken down to few more steps).

If you need more help, [this nice article](http://whatdoesthequantsay.com/2014/05/04/bitcoin-transactions-technically-part-2) explains bitcoin transactions technically and shows examples using the **Pybitcointools** library.


---

### Answer by username_3 on 2014-09-17. Score: 2

I think that [PyCoin](https://github.com/richardkiss/pycoin) would serve your needs.

[This test case shows how to construct a transaction.](https://github.com/richardkiss/pycoin/blob/master/tests/tx_utils_test.py)

[This test case shows how to use Wallet Import Format with PyCoin.](https://github.com/richardkiss/pycoin/blob/master/tests/key_translation_test.py)

I'd also like to note that this is not a very good idea. Suppose that your input is actually 20 BTC instead of 10. What will happen is that Bitcoin will interpret the extra 10 BTC as a fee to be collected by the miner.

> **Comments:**
> **username_4**: Note that in addition to the destination address and the private key, the other piece of data you need is the utxo (id and output number from a previous transaction) which is to be spent. Unless you happen to know what is, you'll need a Bitcoin client (or access to a copy of the block chain) to find an appropriate utxo given the private key.  

---

