简体   繁体   English

如何使用 Web3py 获取特定合约的 ERC20 代币交易

[英]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.我正在使用 web3py,我想获取特定合约的交易历史。 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.我预计将获得与此合约相关的 ERC20 代币交易,如在此处找到,但遗憾的是它没有显示任何内容。 How to go about this?如何 go 关于这个?

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)我所做的是我创建了一个合约实例: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.然后 trasnfer_filter = contract.events.Transfer.filter(你有可选参数,例如:fromBlock:...,toBlock,argument_filters:{“to”:users_address(此过滤器仅用于传输到该地址)})所以你可以玩周围。

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

found in the event log object section.在事件日志 object 部分中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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