3

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?

The Bassman
  • 2,241
  • 5
  • 26
  • 38

2 Answers2

0

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.

whitebat 199
  • 172
  • 2
  • 9
0

As is answered by other's answer, contract.events provides lots of useful methods. If nothing is returned, specifying from and to might help.

And besides, an ultimate solution is already provided here -> Advanced example: Fetching all token transfer events.

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

Actually, lots of nodes support subscribe RPCs. However, this feature is not yet supported by web3py(#1402). You can try SDK in other language or temporarily adopt this method here

Darwin
  • 26
  • 2