2

I'm trying to post a transaction with a message on a local ethereum blockchain using the data field. I don't know how to retrieve the message.

code:

import web3
w3 = web3.Web3(web3.HTTPProvider("http://127.0.0.1:7545"))
alice = w3.eth.accounts[0]
text = b'Hello'
print(text)
tx = {
    'from': alice,
    'to': alice,
    'data': text,
}
tx_hash = w3.eth.sendTransaction(tx)
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
my_tx = w3.eth.getTransaction(tx_hash)
print(my_tx.input)

output:

b'Hello'

0x48656c6c6f

I want to retrieve the original message 'Hello'.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Jack
  • 41
  • 1
  • 5

1 Answers1

1

You need to know the transaction hash where the message was posted.

Then you can call web3.eth.getTransaction(hash) and you can read data back in input field.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435