<p>I have a raw bitcoin transaction created using <a href="https://bitcoincore.org/en/doc/0.17.0/rpc/rawtransactions/combinerawtransaction/" rel="nofollow noreferrer">createrawtransaction</a></p>
<pre><code>unsigned_tx = &quot;02000000014bcb8bcbf347d2f91a11703afa644a3ba43cd25a1e8cf538732d65aeb54401070000000000cffgffff0137670000000000001970a91436c27d3f6dd809c25cfbf7d2670ab701a5717b0488ac00000000&quot;
</code></pre>
<p>The raw transaction was created using multiple inputs and a single output.</p>
<p>Now I am trying to find a way to sign that transaction offline using Python3 and not connecting to a node.</p>
<p>I have been searching through the web with no luck.</p>
<p><strong>Edit 1:</strong>
After following the steps in <a href="http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html" rel="nofollow noreferrer">http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html</a>, I get stuck with this exception:</p>
<pre><code>In [41]: private_key = &quot;3699556636270870316293620289962549511891625341283681895576015487131205320420&quot;

In [42]: ecdsa.SigningKey.from_string(bytes.fromhex(privat_key), curve=ecdsa.SECP256k1)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
&lt;ipython-input-42-48390f7d05da&gt; in &lt;module&gt;
----&gt; 1 ecdsa.SigningKey.from_string(bytes.fromhex(private_key), curve=ecdsa.SECP256k1)

~/workspace/virtualenvs/blah-folder/lib/python3.6/site-packages/ecdsa/keys.py in from_string(klass, string, curve, hashfunc)
    147     @classmethod
    148     def from_string(klass, string, curve=NIST192p, hashfunc=sha1):
--&gt; 149         assert len(string) == curve.baselen, (len(string), curve.baselen)
    150         secexp = string_to_number(string)
    151         return klass.from_secret_exponent(secexp, curve, hashfunc)

AssertionError: (38, 32)
</code></pre>
<p>Any ideas where I am going wrong?</p>

CC BY-SA 4.0
2019-04-04T11:56:48.420Z
You could refer to http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html
Ugam Kamat
CC BY-SA 4.0
2019-04-05T11:58:13.057Z
@UgamKamat I tried it out. Please see my edit 1
Bongani Sibanda
CC BY-SA 4.0
2019-04-05T12:33:27.590Z
You have declared private key as a string and you are using it as hex. In that format, your private key is 38 bytes. The curve is asserting that it should be 32 bytes before it performs the operation and as a result you are getting the AssertionError.
Ugam Kamat
<bitcoin-core><raw-transaction><python><ecdsa><signrawtransaction>
How to sign bitcoin raw transactions with Python offline
Bongani Sibanda
# How to sign bitcoin raw transactions with Python offline

(Asked by: username_0 on 2019-04-04)

I have a raw bitcoin transaction created using createrawtransaction
unsigned_tx = "02000000014bcb8bcbf347d2f91a11703afa644a3ba43cd25a1e8cf538732d65aeb54401070000000000cffgffff0137670000000000001970a91436c27d3f6dd809c25cfbf7d2670ab701a5717b0488ac00000000"

The raw transaction was created using multiple inputs and a single output.
Now I am trying to find a way to sign that transaction offline using Python3 and not connecting to a node.
I have been searching through the web with no luck.
Edit 1:
After following the steps in http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html, I get stuck with this exception:
In [41]: private_key = "3699556636270870316293620289962549511891625341283681895576015487131205320420"

In [42]: ecdsa.SigningKey.from_string(bytes.fromhex(privat_key), curve=ecdsa.SECP256k1)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
 in 
----> 1 ecdsa.SigningKey.from_string(bytes.fromhex(private_key), curve=ecdsa.SECP256k1)

~/workspace/virtualenvs/blah-folder/lib/python3.6/site-packages/ecdsa/keys.py in from_string(klass, string, curve, hashfunc)
    147     @classmethod
    148     def from_string(klass, string, curve=NIST192p, hashfunc=sha1):
--> 149         assert len(string) == curve.baselen, (len(string), curve.baselen)
    150         secexp = string_to_number(string)
    151         return klass.from_secret_exponent(secexp, curve, hashfunc)

AssertionError: (38, 32)

Any ideas where I am going wrong?

**Tags:** bitcoin-core, raw-transaction, python, ecdsa, signrawtransaction

> **Comments:**
> **username_1**: You could refer to http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html  
> **username_0**: @UgamKamat I tried it out. Please see my edit 1  
> **username_1**: You have declared private key as a string and you are using it as hex. In that format, your private key is 38 bytes. The curve is asserting that it should be 32 bytes before it performs the operation and as a result you are getting the AssertionError.  

---

## 0 answers

