forked from flare-foundation/developer-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_query_flare.py
36 lines (31 loc) · 1.05 KB
/
make_query_flare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import asyncio
import json
import aiohttp
from web3 import AsyncHTTPProvider, AsyncWeb3
from web3.middleware import ExtraDataToPOAMiddleware
async def main() -> str:
registry_addr = "0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019"
w3 = AsyncWeb3(
AsyncHTTPProvider("https://flare-api.flare.network/ext/C/rpc"),
middleware=[ExtraDataToPOAMiddleware],
)
params = {
"module": "contract",
"action": "getabi",
"address": registry_addr,
}
async with (
aiohttp.ClientSession() as session,
session.get(
"https://flare-explorer.flare.network/api", params=params
) as response,
):
res = await response.json()
abi = json.loads(res["result"])
registry = w3.eth.contract(address=w3.to_checksum_address(registry_addr), abi=abi)
res = await registry.functions.getContractAddressByName("WNat").call()
print(f"WNat address: {res}")
# WNat address: 0x1D80c49BbBCd1C0911346656B529DF9E5c2F783d
return res
if __name__ == "__main__":
asyncio.run(main())