30 web3.py 异步

async def hello(i): w3 = Web3( Web3.AsyncHTTPProvider(endpoint_uri), modules={'eth': (AsyncEth,), 'net': (AsyncNet,)} ) a= await w3.eth.get_balance(i) print(a)

if name == "main": for i in di: asyncio.run(hello(i)) 出错显示bject function can't be used in 'await' expression 请问web3.py的异步应该怎么写

请先 登录 后评论

最佳答案 2022-09-09 00:17

这样写。就少了,初始化时候的,middlewares=[]

import asyncio

import web3
from web3 import Web3
from web3.eth import AsyncEth
url = "http://127.0.0.1:8080"
async def GetNumber(w3):
    n = await w3.eth.get_block_number()
    print(n)
if __name__ == '__main__':
    w3 = Web3(web3.AsyncHTTPProvider(url),
              modules={'eth': (AsyncEth,)},
              middlewares=[]
              )
    asyncio.run(GetNumber(w3))
请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 0 收藏,2819 浏览
  • v 提出于 2022-09-07 01:53