如何过滤以太坊地址
我尝试编写一个脚本来获取我的以太坊地址的交易。 这个脚本在监控合约地址时有效,但如果我想监控我自己的地址或非合约地址,它不会收到任何交易
def handle_event(event):
print(event)
print(Web3.toJSON(event))
def log_loop(event_filter, poll_interval):
while True:
for event in event_filter.get_new_entries():
handle_event(event)
time.sleep(poll_interval)
def main():
event_filter = web3.eth.filter({"address": trackAddress})
#get_block = web3.eth.get_block('latest')
#block_filter = web3.eth.filter('latest')
log_loop(event_filter, 2)
if __name__ == '__main__':
main()
I try to write a script to get transactions of my ethereum address as they happen.
This script here works when monitoring a contractAddress, but if i want to monitor my own address or non contract address, it dont get any transactions
def handle_event(event):
print(event)
print(Web3.toJSON(event))
def log_loop(event_filter, poll_interval):
while True:
for event in event_filter.get_new_entries():
handle_event(event)
time.sleep(poll_interval)
def main():
event_filter = web3.eth.filter({"address": trackAddress})
#get_block = web3.eth.get_block('latest')
#block_filter = web3.eth.filter('latest')
log_loop(event_filter, 2)
if __name__ == '__main__':
main()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,使用filter命令只能监控合约上发生的事件。此选项不适用于您的情况。
我将编写我更熟悉的 JavaScript 代码,但您可以将其改编为 python。我可能会这样做:
您可以将此函数插入到 setInterval 中,并大约每隔 ~15 秒调用它。为什么是15秒?平均而言,每 15 秒就会出现一个新区块。
另一种选择是使用 ethers.js 库。您可以直接订阅区块并请求交易信息一个新的块。但我不知道python是否存在这样的库。
您还可以执行以下操作:
在这种情况下,每次您的地址收到 ERC-20 代币时都会触发处理程序。
As far as I know, using the filter command, you can only monitor events that occur on the contract. This option will not work in your case.
I'll write the JavaScript code as I'm more familiar with it, but you can adapt it to python. I would probably do something like this:
You can insert this function into
setInterval
and call it approximately every ~15 seconds. Why 15 seconds? On average, a new block appears just every 15 seconds.Another option is using the ethers.js library. You can subscribe directly to blocks and request transaction information for a new block. But I don't know if such a library exists for python.
You can also do something like this with:
In this case, the handler will be triggered every time you receive ERC-20 tokens to your address.