7

Hi I am running Python web3.py(Not web3.js) to run this:

 txn = ctrtInstance.functions.setzString(zString).buildTransaction()
 print('\ntxn: '+ str(txn))
 txn['nonce'] = 3643
 txn['chainId'] = 3
 print('\ntxn: '+ str(txn))

#So the txn looks this: {'value': 0, 'gas': 33504, 'gasPrice': 1000000000, 'chainId': 3, 'to': '0x5227D720d8eFDcB259c6c79C74f3Cfe04DC4D4fa', 'data': '0xb32e420700000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000007476f204d616e2100000000000000000000000000000000000000000000000000', 'nonce': 3643}

 signed = w3.eth.account.signTransaction(txn, privateKey)
 txn_hash = w3.eth.sendRawTransaction(signed.rawTransaction)

Then txn_hash looks very strange: b"\x83\xd4\t'\x9e\xec\xb7\xc0\xf5\xdd\xf9\xb9\x0fD\xdc\x81\xfb\x8d\x0e\xf7\xb5\xbc2e~\x81R\x8c]Ek|"

What is it? How to decode this Transaction hash?

Why does it look different from other transaction hash I've seen online?

How can I decode it so I can enter it into EtherScan to check such transaction? Thank you

Reference: http://web3py.readthedocs.io/en/latest/web3.eth.html#web3.eth.Eth.sendRawTransaction

1
  • Have you seen the example here? Seems like you might not be passing in the right value into the function. May 21, 2018 at 7:29

2 Answers 2

5

Use hex().

txnHash = w3.eth.sendRawTransaction(signed.rawTransaction)
print('txnHash: '+ str(txnHash))

txnHashHex = txnHash.hex()
print('txnHash.hex(): '+ txnHashHex)

Output in terminal:

txnHash: b'\x8f\xd8\x89\xfdt\x1f\xeb4\x88\x15\xeb\xb2-\xd8D\xf6\xdb%~\xdb\x0c\xf1\xa9n\x17R\x19\xf6#\xe6\x81\xf5'
binascii.hexlify(txnHash)= b'8fd889fd741feb348815ebb22dd844f6db257edb0cf1a96e175219f623e681f5'
txnHash.hex(): 0x8fd889fd741feb348815ebb22dd844f6db257edb0cf1a96e175219f623e681f5

You can then take txnHash.hex() to EtherScan to find this transaction status :)

1

What you see is a ASCII binary presentation of the bytes.

You can convert raw bytes to hex in Python:

 import binascii
 print binascii.hexlify(b"\x83\xd4\t'\x9e\xec\xb7\xc0\xf5\xdd\xf9\xb9\x0fD\xdc\x81\xfb\x8d\x0e\xf7\xb5\xbc2e~\x81R\x8c]Ek|")

 83d409279eecb7c0f5ddf9b90f44dc81fb8d0ef7b5bc32657e81528c5d456b7c
3
  • Hey. thank you. So why Ropsten EtherScan could not find such transaction? Thanks
    – Russo
    May 21, 2018 at 8:49
  • 1
    I suggest you open an another question with the details what is your transaction hash, how are you connected to Ropsten network and how do you look it up on Ropsten as the question you ask in the comment is a different question. May 21, 2018 at 10:23
  • 1
    Thank you Mikko. txnHash.hex() is actually more convenient :)
    – Russo
    May 23, 2018 at 6:47

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.