I have a transaction in which I know the hash of. It was a swap to sell a token using Uniswap. I am trying to find the amount the wallet received in ETH within the transaction object. To my knowledge, this information can likely be found by extracting the function calls with its parameters inside the ‘input’ field of the transaction object returned by web3 py library.
Can anyone help guide me on how I can correctly decode this to get the information I am looking for?
Heres some of the general transaction data I am printing:
-----------------------------------------------------------------------------------------
Transaction 4:
Type: execute
From: 0x9ae6c4196E8ca4aEE7bFCA0E2A767019e1fDbe26
To: 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD
Block Number: 19715682
Hash: 0x2691a1feec999b296b6b5a4e16f531b525afe59554246d23bfe8ccfd580cd495
Value: 0 ETH ($0.0)
Gas Spent: 0.0019 ETH ($6.6)
Total Spent: 0.0019 ETH ($6.6)
-----------------------------------------------------------------------------------------
Here is related code to help me extract the input field of the transaction object (I manually got the abi through etherscan, I can confirm the function getContractABI is working):
for i in range(0, len(transactions)):
if getTransactionType(transactions[i]) == "execute":
input_data = transactions[i]['input']
print("Input Data:", input_data)
abi = getContractABI('0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD')
# Ensure input data is long enough to extract the function signature
if len(input_data) < 10:
print("Error: Input data is too short to extract function signature.")
exit(1)
# Extract the function signature from the input data
function_signature = input_data[:10]
print("Function Signature:", function_signature.hex())
function_signature_bytes = function_signature.hex()
print("Function Signatures in ABI:")
for item in abi:
if 'name' in item and 'type' in item and item['type'] == 'function':
signature = item.get('signature', 'N/A')
print(item['name'], item['type'], signature)
Here is the information printed from the code above:
Input Data: b"5x93VLx00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00`x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00xa0x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00f'9xe3x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x04nx08x06x0cx00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x04x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x80x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x02x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x03 x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x03xa0x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x01`x00x00x00x00x00x00x00x00x00x00x00x00xa6xebxa1xed'xb1xa4xbax00xb0 x81x92dxa7x013xb6xe1'x00x00x00x00x00x00x00x00x00x00x00x00xffxffxffxffxffxffxffxffxffxffxffxffxffxffxffxffxffxffxffxffx00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00fNxc4x8dx00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00?xc9x1a:xfdp9\xd4x96xc6Gxd5xa6xccx9dK+x7fxadx00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00f'>x95x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00xe0x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00Ax94xa3>x89rHtxccxc3yxf1xb9l[xddxf5Axc5Nxe5xd3kxa9xddx96xb5xe7Zx987: ^7xebxa8fx1bxbbx03x9cGxd2Gxd6xe06zxddxdfWx1a,xdbx13xb9x81Rxd7l Nx8cxbax1bx00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x01x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x02x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x003+xce,6x116xafx00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00nxc7xbfx17<x0ex05xa0x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00xa0x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x01x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x02x00x00x00x00x00x00x00x00x00x00x00x00xa6xebxa1xed'xb1xa4xbax00xb0 x81x92dxa7x013xb6xe1'x00x00x00x00x00x00x00x00x00x00x00x00xc0*xaa9xb2#xfex8dnx0e\O'xeaxd9x08<ulxc2x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00`x00x00x00x00x00x00x00x00x00x00x00x00xc0*xaa9xb2#xfex8dnx0e\O'xeaxd9x08<ulxc2x00x00x00x00x00x00x00x00x00x00x00x007xa8xf2x95a&x02xf2wM3x1eV+xe9xe6x1bx83xa3'x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x19x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00@x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x01x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00nxc0xd8xda`bwx88"
Function Signature: 0x3593564c000000000000
Function Signatures in ABI:
collectRewards function N/A
execute function N/A
execute function N/A
onERC1155BatchReceived function N/A
onERC1155Received function N/A
onERC721Received function N/A
supportsInterface function N/A
uniswapV3SwapCallback function N/A