'Retrieving swapped token addresses from etherscan using web3js
I am trying to retrieve the token addresses of tokens swapped (and amount of tokens swapped) in a single transaction.
I am using the "web3.eth.get_transaction(hash)" and it seems that this info is lacking.
Please find below my code:
import config
from web3 import Web3
w3 = Web3(Web3.HTTPProvider(config.INFURA_URL))
transaction = w3.eth.get_transaction("0x875c5c1ffea8d91571960349e5347d6cb4503ff13fc14cf03851a1c1a723b646")
print(transaction)
And this is what I get from the terminal:
AttributeDict({
'accessList': [],
'blockHash': HexBytes('0xb5cb4520640a46716ccd68cc2e79f31b1593b7c3022cfcae05fae1780210e366'),
'blockNumber': 14724801,
'chainId': '0x1',
'from': '0x35f12e6eB5180e0BD260De25D2D94DF37D9eA0f7',
'gas': 260247,
'gasPrice': 69659922397,
'hash': HexBytes('0x875c5c1ffea8d91571960349e5347d6cb4503ff13fc14cf03851a1c1a723b646'),
'input': '0x5ae401dc0000000000000000000000000000000000000000000000000000000062755ee4000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e442712a670000000000000000000000000000000000000000000000000000c8abfc6d8a000000000000000000000000000000000000000000000000001bc237a5adc220e0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000035f12e6eb5180e0bd260de25d2d94df37d9ea0f70000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a010e37405eb57437a381daae88e5c3913d0796c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000412210e8a00000000000000000000000000000000000000000000000000000000',
'maxFeePerGas': 89683038482,
'maxPriorityFeePerGas': 1500000000,
'nonce': 6,
'r': HexBytes('0xddab3462565d12062537f16358e6d1592e8c264310bfac3230af713344036561'),
's': HexBytes('0x632682b1d42adc59312a0051ad8385795bbb0c9710c73b83fc75f557154b0700'),
'to': '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
'transactionIndex': 195,
'type': '0x2',
'v': 1,
'value': 2000222369230233824})
From the output, I think that I am missing token addresses (and value of SATS swapped in this case). How can I extract the tokens swapped and the amount swapped in a transaction? (highlighted in the screenshot).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

