Skip to content

Instantly share code, notes, and snippets.

@luzihang123
Last active July 20, 2019 09:11
Show Gist options
  • Save luzihang123/a08f432790d543efcc254082f9e3ddb0 to your computer and use it in GitHub Desktop.
Save luzihang123/a08f432790d543efcc254082f9e3ddb0 to your computer and use it in GitHub Desktop.
异步从链上获取ETH余额 address ETH balance
import grequests
import urllib
address_list = [
"0xc94770007dda54cF92009BFF0dE90c06F603a09f",
'0x054c64741dbafdc19784505494029823d89c3b13',
'0x0b4bdc478791897274652dc15ef5c135cae61e60',
'0x4af328c52921706dcb739f25786210499169afe6',
'0x49bd2da75b1f7af1e4dfd6b1125fecde59dbec58',
'0x829bd824b016326a401d083b33d092293333a830',
'0x55296f69f40ea6d20e478533c15a6b08b654e758',
'0x190289e0f72dfd611121da7dd9f3e6c92b8f71e4',
'0x0bc61dded5f6710c637cf8288eb6058766ce1921',
'0xd01db73e047855efb414e6202098c4be4cd2423b',
'0xd37532d304214d588aeeac4c365e8f1d72e2304a',
]
request_list = []
for address in address_list:
params_str = '["{}","latest"]'.format(address)
params_encode = urllib.parse.quote(params_str)
print(params_encode)
rs = grequests.get(url="https://api.infura.io/v1/jsonrpc/mainnet/eth_getBalance?params={}".format(params_encode))
print(rs)
request_list.append(rs)
try:
ret = grequests.map(request_list, size=20)
success_count = 0
failed_count = 0
print(ret)
for r in ret:
if r.status_code == 200:
success_count += 1
print(r.json())
balance = int(r.json()["result"], 16)
print("{} Wei".format(balance))
print("{} Ether".format(balance * 10 ** -18))
else:
failed_count += 1
print(r.text)
except Exception as e:
print("*** Exception:{}, holder_list:{}".format(e, address_list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment