嗨,我正在运行Pythonweb3.py(不是web3.js)来运行这个:
txn = ctrtInstance.functions.setzString(zString).buildTransaction()
print('\ntxn: '+ str(txn))
txn['nonce'] = 3643
txn['chainId'] = 3
print('\ntxn: '+ str(txn))#因此txn看起来如下:{'value':0,'gas':33504,‘汽油价格’:1000000000,'chainId':3,'to':‘0x5227D720d8eFDcB259c79C74f3Cfe04DC4D4fa,'data':'0xb32e420700000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000007476f204d616e2100000000000000000000000000000000000000000000000000','nonce':3643}
signed = w3.eth.account.signTransaction(txn, privateKey)
txn_hash = w3.eth.sendRawTransaction(signed.rawTransaction)然后txn_hash看起来很奇怪:txn_hash
那是什么?如何解码此事务哈希?
为什么它看起来与我在网上看到的其他事务散列不同?
如何对其进行解码,以便将其输入EtherScan以检查此类事务?谢谢
参考资料:http://web3py.readthedocs.io/en/latest/web3.eth.html#web3.eth.Eth.sendRawTransaction
发布于 2018-05-23 06:46:13
使用hex()。
txnHash = w3.eth.sendRawTransaction(signed.rawTransaction)
print('txnHash: '+ str(txnHash))
txnHashHex = txnHash.hex()
print('txnHash.hex(): '+ txnHashHex)终端输出:
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然后,您可以将txnHash.hex()转到EtherScan以找到以下事务状态:)
发布于 2018-05-21 08:15:31
您看到的是字节的ASCII二进制表示。
您可以在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|")
83d409279eecb7c0f5ddf9b90f44dc81fb8d0ef7b5bc32657e81528c5d456b7chttps://ethereum.stackexchange.com/questions/49019
复制相似问题