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)
<ipython-input-42-48390f7d05da> in <module>
----> 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?

  • You could refer to righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html
    – Ugam Kamat
    Commented Apr 4, 2019 at 11:56
  • @UgamKamat I tried it out. Please see my edit 1 Commented Apr 5, 2019 at 11:58
  • 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.
    – Ugam Kamat
    Commented Apr 5, 2019 at 12:33


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.