简体   繁体   中英

How to get ERC20 Token Transaction of a specific contract using Web3py

I'm using web3py and I want to get the transaction history of a specific contract. Here's my code sample

eventSignatureHash = web3.keccak(text='Transfer(address,uint256)').hex()


filter = web3.eth.filter({
    'address': '0x828402Ee788375340A3e36e2Af46CBA11ec2C25e',
    'topics': [eventSignatureHash]
})

I'm expected to get ERC20 Token Transactions related to this contract as found here but it does not display anything unfortunately. How to go about this?

Finally, is there a way to watch these transactions in real time?

What i did is that i created a contract instance: contract = web3.eth.contract(address = contract_address)

then trasnfer_filter = contract.events.Transfer.filter(u have optional parameters such as: fromBlock:...,toBlock, argument_filters:{"to": users_address(this filters for transfers only to that address)}) so you can play around it.

https://web3py.readthedocs.io/en/latest/contracts.html#web3.contract.ContractEvents

found in the event log object section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM