I am having trouble interpreting transaction from web3.py w3.eth.get_transaction
Take this as example, it's a Swap transaction for example: Swapping USDT for USDC, then USDC for SINGLE
https://cronos.org/explorer/tx/0xaba4f0d9fb2606cab22328ea98297526e5ac4f98358e7fcceb098b755d8290ad/token-transfers
If I call web3.py w3.eth.get_transaction:
trx = w3.eth.getTransaction('0xaba4f0d9fb2606cab22328ea98297526e5ac4f98358e7fcceb098b755d8290ad')
The result is a bunch of gibberish in Bytes:
How can I decode the Bytes back into:
a. Type of transaction: Swap? Burn? Mint?
b. Sender and Recepient address
c. Amount in (In USDT), Amount out (In SINGLE)?
d. Status = Still pending? Or Success?
As partial solution, for "Status", we can check as follows:
from web3.exceptions import TransactionNotFound
trx_hash = '0xaba4f0d9fb2606cab22328ea98297526e5ac4f98358e7fcceb098b755d8290ad'
trx = w3.eth.getTransaction(trx_hash) # This only means you sent the transaction. It does not mean it succeeded.
status : int = -1
while True:
'''
https://web3py.readthedocs.io/en/stable/web3.eth.html#methods
Returns the transaction receipt specified by transaction_hash. If the transaction has not yet been mined throws web3.exceptions.TransactionNotFound.
If status in response equals 1 the transaction was successful. If it is equals 0 the transaction was reverted by EVM.
'''
try:
trx_receipt = w3.eth.getTransactionReceipt(trx_hash)
status = trx_receipt['status']
if status == 0 or status == 1:
break
except TransactionNotFound:
# Transaction not found!
pass
Format of trx_receipt as follows, notably it contains: status and gasUsed
But I still need wait to find things like transaction type, amount_in, amount_out, time it took for tran, sender/receiver wallet address …etc
https://discord.com/channels/435685690936786944/950963287141519420/970513522905739314
Best Answer
Problem solved, you'd need to parse event logs for event type "Transfer" (For the example given), not "Swap":