Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in Blockchain by (47.6k points)
edited by

I am in the process of creating a raw transaction using pybitcointools, however when I tried to push the transaction into the network using pushtx(tx)

I got the ff. error:

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/usr/local/lib/python2.7/site-packages/bitcoin-1.1.42-py2.7.egg/bitcoin/bci.py", line 311, in pushtx

return f(*args)

File "/usr/local/lib/python2.7/site-packages/bitcoin-1.1.42-py2.7.egg/bitcoin/bci.py", line 261, in bci_pushtx

  if not re.match('^[0-9a-fA-F]*$', tx):

File "/usr/local/lib/python2.7/re.py", line 141, in match

return _compile(pattern, flags).match(string)

TypeError: expected string or buffer

Here's the code:

from bitcoin.main import *

from bitcoin.transactions import *

from bitcoin.bci import *

>>> addr

'1CXW5bqMNQZ3sftXCtiRf3HGTPJmpd2xvq' #I just edited the address for security purpose

>>> unspent(addr)

[{'output': '23e81960ba8bb95c33c2336c84c126e378e4d1123921f881da9287c25f624161:1', 'value': 300000}] 

>>> source = '32GkPB9XjMAELR4Q2Hr31Jdz2tntY18zCe'

>>> unspent(source)

[{'output': '8602122a7044b8795b5829b6b48fb1960a124f42ab1c003e769bbaad31cb2afd:0', 'value': 677200}, {'output': 'bd992789fd8cff1a2e515ce2c3473f510df933e1f44b3da6a8737630b82d0786:0', 'value': 5000000}]

>>> ins = unspent(addr) + unspent(target)

>>> amount = 300000 + 5000000 + 677200

>>> amount -= 10000

>>> outs = [{'address': addr, 'value': value}]

>>> tx = mktx(ins, outs)

>>> tx = sign(tx, 0, priv)

>>> tx = deserialize(tx)

>>> tx['ins'][1]['script'] = '00483045022100dfcfafcea73d83e1c54d444a19fb30d17317f922c19e2ff92dcda65ad09cba24022001e7a805c5672c49b222c5f2f1e67bb01f87215fb69df184e7c16f66c1f87c290347304402204a657ab8358a2edb8fd5ed8a45f846989a43655d2e8f80566b385b8f5a70dab402207362f870ce40f942437d43b6b99343419b14fb18fa69bee801d696a39b3410b8034c695221023927b5cd7facefa7b85d02f73d1e1632b3aaf8dd15d4f9f359e37e39f05611962103d2c0e82979b8aba4591fe39cffbf255b3b9c67b3d24f94de79c5013420c67b802103ec010970aae2e3d75eef0b44eaa31d7a0d13392513cd0614ff1c136b3b1020df53ae'

>>> tx['ins'][2]['script'] = '00483045022100dfcfafcea73d83e1c54d444a19fb30d17317f922c19e2ff92dcda65ad09cba24022001e7a805c5672c49b222c5f2f1e67bb01f87215fb69df184e7c16f66c1f87c290347304402204a657ab8358a2edb8fd5ed8a45f846989a43655d2e8f80566b385b8f5a70dab402207362f870ce40f942437d43b6b99343419b14fb18fa69bee801d696a39b3410b8034c695221023927b5cd7facefa7b85d02f73d1e1632b3aaf8dd15d4f9f359e37e39f05611962103d2c0e82979b8aba4591fe39cffbf255b3b9c67b3d24f94de79c5013420c67b802103ec010970aae2e3d75eef0b44eaa31d7a0d13392513cd0614ff1c136b3b1020df53ae'

>>> serialize(tx)

'01000000036141525fc24792da81f8213912d1e478e326c18...'

>>> pushtx(tx)

1 Answer

+1 vote
by (106k points)
edited by

In your code, you need to pass tx to pushtx() in serialized form.

The line re.match('^[0-9a-fA-F]*$', tx)in your code accepts a hex string, exactly what serialize() returns.

This field is going to boom in future learn more about it through Blockchain Course by Intelipaat.

Related questions

0 votes
1 answer
asked Dec 23, 2020 in Blockchain by dev_sk2311 (45k points)
0 votes
1 answer
asked Dec 23, 2020 in Blockchain by dev_sk2311 (45k points)
0 votes
1 answer
asked Dec 23, 2020 in Blockchain by dev_sk2311 (45k points)
0 votes
1 answer
asked Dec 23, 2020 in Blockchain by dev_sk2311 (45k points)

Browse Categories

...