1

我正在尝试使用数据字段在本地以太坊区块链上发布带有消息的交易。我不知道如何检索消息。

代码:

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)

输出:

b'你好'

0x48656c6c6f

我想检索原始消息“你好”。

4

1 回答 1

1

您需要知道发布消息的事务哈希。

然后你可以打电话,你可以在现场web3.eth.getTransaction(hash)读回数据。input

于 2020-07-14T07:34:45.570 回答