How can I get only to and from addresses from a transaction Hash using Web3. I am unable to get details of to and from using web3.eth.getTransaction() method. Please help!!
You can use the hash to get the transaction receipt. The transaction receipt will include the to and from addresses among other things. There are similar methods for inspecting the pending transaction before it is mined.
Hope it helps.
If you use web3.py, you need some python logic but you can make it work!
Assuming that you already have a tx hash, use the
eth.getTransaction method to retrieve the tx details and place them in a variable.
Then we convert the 'AttributeDict' object received to dictionary that python can read and extract the data.
tx_hash = "0x31ffad3241a97b6f235141d88bdc257e562a4c506a77da85010fde7519cd3296" details = web3.eth.getTransaction(tx_hash) # convert the 'AttributeDict' object to a dictionary parsedDict = dict(details) # create a list of info you want to retrieve from the hash info = ['from','to'] # loop to extrapolate the information for key, val in parsedDict.items(): for word in info: if word == key: print(key +':', val)
it will print this:
from: 0xe398aD530c47C16151DaE087F19A2e87C689E1d0 to: 0x0D0707963952f2fBA59dD06f2b425ace40b492Fe