1

Currently my implementations of abi decode gets only token amount and not the From, To, address and token amount is without decimal point

value = decode(['uint256'],log['data'])

ouptput

Token transfer details:
Value: (2657829493000000000000,)
1
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Apr 7, 2023 at 13:35

1 Answer 1

0

Your question isn't quite clear, but I'm assuming that log['data'] is several bytes values concatenated, and that Value is an amount in wei. In that case you could use eth_abi and web3.py as below:

from web3 import Web3
from eth_abi import encode, decode

accountA = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'
accountB = '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB'
wei_amt = 2657829493000000000000

w3 = Web3()

encoded = encode(['address', 'address', 'uint256'], [accountA, accountB, wei_amt])

print(encoded)

decoded = decode(['address', 'address', 'uint256'], encoded)

print(decoded)

address_from, address_to, token_amt_in_wei = decoded

amount_in_eth = w3.from_wei(token_amt_in_wei, "ether")

print(f"{address_from=}")
print(f"{address_to=}")
print(f"{amount_in_eth=}")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.