您如何使用bscscan访问历史交易和买卖订单?

2024-04-25 17:05:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在使用带有钱包地址的python bscscan文档来访问给定合同地址的令牌传输。查看documentation

代码:

from bscscan import BscScan async def get_contents(): async with BscScan(bsc_address) as client: print( await client.get_bep20_token_transfer_events_by_address( address="0x0000000000000000000000000000000000001004", startblock=0, endblock=999999999, sort="asc" ) ) asyncio.run(get_contents())

运行这段代码时,出现以下错误:

RuntimeError Traceback (most recent call last) in () 10 ) 11 ) ---> 12 asyncio.run(get_contents())

/usr/lib/python3.7/asyncio/runners.py in run(main, debug) 32 if events._get_running_loop() is not None: 33 raise RuntimeError( ---> 34 "asyncio.run() cannot be called from a running event loop") 35 36 if not coroutines.iscoroutine(main):

RuntimeError: asyncio.run() cannot be called from a running event loop

其他StackOverflow帖子建议安装nest_asyncio,使用if/else条件,if语句包含main(),else语句包含asyncio.run()。我两种方法都试过了,但还是有同样的错误

我不确定为什么我会收到这个错误。如果我能得到一些关于如何前进的澄清,那就太好了。另外,如果还有其他二进制智能链python的例子,我将非常感谢提供更多的资源


Tags: run代码fromloopasynciogetifmain