pybitcointools pushtx TypeError expected string or buffer

0 votes

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)
Sep 6, 2018 in Blockchain by slayer
• 29,370 points
1,296 views

1 answer to this question.

0 votes
From the looks of it, you need to pass tx to pushtx() in serialized form.

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

This is all the more likely considering that mktx() and sign() produce the result in serialized form.
answered Sep 6, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

How to solve “Error: Expected a Resource or Concept”?

There are few errors in code. I ...READ MORE

answered Jul 31, 2018 in Blockchain by slayer
• 29,370 points
1,234 views
0 votes
1 answer

TypeError: argument must be a string node.js while encoding to hex string.

The error is in protobuf.Transaction.create headerSignature needs to be a string, ...READ MORE

answered Nov 6, 2018 in Blockchain by Omkar
• 69,220 points
3,311 views
+15 votes
5 answers
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,428 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
0 votes
1 answer

What encoding or data type can be used to get alphanumeric string in elixir?

Integers in Elixir are arbitrary precision integers, ...READ MORE

answered Aug 31, 2018 in Blockchain by digger
• 26,740 points
800 views
0 votes
1 answer

how can i convert stub.GetTxTimestamp() to type string?

You can not directly convert the timestamp ...READ MORE

answered Jul 5, 2018 in Blockchain by digger
• 26,740 points
1,503 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP