Parse Event Logs

解析合约调用事件

Parse Transfer Event



from tronpy import Tron
from tronpy.keys import keccak256
from pprint import pprint
client = Tron()


txn_id = 'e010654f48b5f94a4ea0305273bac3310b273979e1df61c8fd2334c52686ba6e'
txn_info = client.get_transaction_info(txn_id)


pprint(txn_info)

target_event = 'Transfer(address,address,uint256)'
event_hash = keccak256(target_event.encode()).hex()

for log in txn_info.get('log', []):
    if log['topics'][0] == event_hash:
        print('Transfer!')

        from_addr = client.to_base58check_address('41' + log['topics'][1][-40:])
        print('From', from_addr)
        to_addr = client.to_base58check_address('41' + log['topics'][2][-40:])
        print('To', to_addr)

        amount = int(log['data'], 16)
        print('Amount', amount)
    else:
        print('unknown event:', log['topics'][0])

最后更新于