<p>Code sample from 04/2014 is out of date with current python-bitcoinlib. Slight modification here:</p>

<pre><code>from bitcoin.core import COIN, b2lx
import bitcoin.wallet
import bitcoin.rpc

rpc = bitcoin.rpc.Proxy()
addr = bitcoin.wallet.CBitcoinAddress('1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T')

txid = rpc.sendtoaddress(addr, 0.001 * COIN)
print(b2lx(txid))
</code></pre>

<p>Tested on v0.3.0+</p>

CC BY-SA 3.0
2016-05-05T23:01:32.000Z
from version 0.5.1 `CBitcoinAddressError: Version 0 not a recognized Bitcoin Address`. Can you help me to fix it?
Moreno
CC BY-SA 3.0
2015-03-07T07:17:28.587Z
2015-03-07T07:17:28.587Z
Scott Bigelow
<p>I just added sendtoaddress to bitcoin.rpc.Proxy:</p>

<pre><code>from bitcoin.core import COIN, b2lx
import bitcoin.wallet
import bitcoin.rpc
try:
    # This moved between versions
    from bitcoin.base58 import CBitcoinAddress
except:
    from bitcoin.wallet import CBitcoinAddress

rpc = bitcoin.rpc.Proxy()
addr = CBitcoinAddress('1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T')

txid = rpc.sendtoaddress(addr, 0.001 * COIN)
print(b2lx(txid))
</code></pre>

<p>Note quite as simple as bitcoinrpc, but that's the trade-off for having proper types and so forth.</p>

CC BY-SA 3.0
2014-04-19T07:00:56.060Z
Could you expand your answer to relate to the question?
John T
CC BY-SA 3.0
2014-04-22T12:46:58.253Z
Thank you for your good work and answer! I have another question. Maybe you have an answer to that as well?: http://bitcoin.stackexchange.com/questions/24802/how-to-getreceivedbyaddress-with-the-python-bitcoinlib
kramer65
CC BY-SA 3.0
2014-09-17T05:08:33.890Z
where is `CBitcoinAddress` being imported from?
priestc
CC BY-SA 3.0
2014-04-17T06:57:48.353Z
2015-03-07T08:12:10.277Z
2015-03-07T08:12:10.277Z
Peter Todd
<p>I've been using the bitcoin-python library for making payments from within Python. This worked pretty simple:</p>

<pre><code>&gt;&gt;&gt; import bitcoinrpc
&gt;&gt;&gt; conn = bitcoinrpc.connect_to_local()
&gt;&gt;&gt; conn.sendtoaddress('bitcoin_address_here', 0.5)
</code></pre>

<p>The <a href="https://github.com/laanwj/bitcoin-python" rel="nofollow">Readme of that library</a> now says that it is not maintained anymore and refers to the <a href="https://github.com/petertodd/python-bitcoinlib" rel="nofollow">python-bitcoinlib</a> as a successor. So now I'm trying to wrap my head around that lib, but it seems to be a bit more difficult than bitcoin-python used to be. I now understand I can connect to the running bitcoind using the following code:</p>

<pre><code>&gt;&gt;&gt; import bitcoin.rpc as rpc
&gt;&gt;&gt; proxy = rpc.Proxy()
&gt;&gt;&gt; proxy.getinfo()
{u'connections': 36, u'errors': u'', u'blocks': 295646, u'paytxfee': 0, u'keypoololdest': 1394108331, u'walletversion': 60000, u'difficulty': Decimal('6119726
089.12814713'), u'testnet': False, u'version': 90100, u'proxy': u'', u'protocolversion': 70002, u'timeoffset': -1, u'balance': 1856000, u'keypoolsize': 101}
</code></pre>

<p>So far so good. The problem is now that I have no idea how I can do a simple payment. I see there is a function called <code>proxy.sendrawtransaction(self, tx)</code>, which apparently takes a raw transaction as an argument. I have no idea how to create a raw transaction though, plus I would expect that there is some kind of <code>send_to_address(address, amount)</code> available, but I can't find it around the library.</p>

<p>So does anybody know how I can send a simple transaction to an address with the <a href="https://github.com/petertodd/python-bitcoinlib" rel="nofollow">python-bitcoinlib</a>? All tips are welcome!</p>

<transactions><library><python-bitcoinlib>
How to make a simple payment with the python-bitcoinlib?
kramer65
# How to make a simple payment with the python-bitcoinlib?

(Asked by: username_0 on 2014-04-13)

I've been using the bitcoin-python library for making payments from within Python. This worked pretty simple:

```
>>> import bitcoinrpc
>>> conn = bitcoinrpc.connect_to_local()
>>> conn.sendtoaddress('bitcoin_address_here', 0.5)

```

The [Readme of that library](https://github.com/laanwj/bitcoin-python) now says that it is not maintained anymore and refers to the [python-bitcoinlib](https://github.com/username_3/python-bitcoinlib) as a successor. So now I'm trying to wrap my head around that lib, but it seems to be a bit more difficult than bitcoin-python used to be. I now understand I can connect to the running bitcoind using the following code:

```
>>> import bitcoin.rpc as rpc
>>> proxy = rpc.Proxy()
>>> proxy.getinfo()
{u'connections': 36, u'errors': u'', u'blocks': 295646, u'paytxfee': 0, u'keypoololdest': 1394108331, u'walletversion': 60000, u'difficulty': Decimal('6119726
089.12814713'), u'testnet': False, u'version': 90100, u'proxy': u'', u'protocolversion': 70002, u'timeoffset': -1, u'balance': 1856000, u'keypoolsize': 101}

```

So far so good. The problem is now that I have no idea how I can do a simple payment. I see there is a function called `proxy.sendrawtransaction(self, tx)`, which apparently takes a raw transaction as an argument. I have no idea how to create a raw transaction though, plus I would expect that there is some kind of `send_to_address(address, amount)` available, but I can't find it around the library.

So does anybody know how I can send a simple transaction to an address with the [python-bitcoinlib](https://github.com/username_3/python-bitcoinlib)? All tips are welcome!

**Tags:** transactions, library, python-bitcoinlib


---

## 2 answers

### Answer by username_3 on 2014-04-17. Score: 8 | Accepted answer

I just added sendtoaddress to bitcoin.rpc.Proxy:

```
from bitcoin.core import COIN, b2lx
import bitcoin.wallet
import bitcoin.rpc
try:
    # This moved between versions
    from bitcoin.base58 import CBitcoinAddress
except:
    from bitcoin.wallet import CBitcoinAddress

rpc = bitcoin.rpc.Proxy()
addr = CBitcoinAddress('1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T')

txid = rpc.sendtoaddress(addr, 0.001 * COIN)
print(b2lx(txid))

```

Note quite as simple as bitcoinrpc, but that's the trade-off for having proper types and so forth.

> **Comments:**
> **username_4**: Could you expand your answer to relate to the question?  
> **username_0**: Thank you for your good work and answer! I have another question. Maybe you have an answer to that as well?: http://bitcoin.stackexchange.com/questions/24802/how-to-getreceivedbyaddress-with-the-python-bitcoinlib  
> **username_5**: where is `CBitcoinAddress` being imported from?  

---

### Answer by username_1 on 2015-03-07. Score: 3

Code sample from 04/2014 is out of date with current python-bitcoinlib. Slight modification here:

```
from bitcoin.core import COIN, b2lx
import bitcoin.wallet
import bitcoin.rpc

rpc = bitcoin.rpc.Proxy()
addr = bitcoin.wallet.CBitcoinAddress('1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T')

txid = rpc.sendtoaddress(addr, 0.001 * COIN)
print(b2lx(txid))

```

Tested on v0.3.0+

> **Comments:**
> **username_2**: from version 0.5.1 `CBitcoinAddressError: Version 0 not a recognized Bitcoin Address`. Can you help me to fix it?  

---

