123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import requests
- import json
- url_0 = "https://eth-mainnet.g.alchemy.com/v2/WLI0ohbUlvbsJVmoIvB1wTSwUA8qP5qS"
- url_1 = ("https://eth-mainnet.g.alchemy.com/v2/ck1dtOx8tHkjAH2PX2FwTGN2T2gDaGtV")
- url_2 = "https://eth-mainnet.g.alchemy.com/v2/pxF-cEkEE1JxzxgotGyww5ra5w1IvAkJ"
-
- url = "https://eth-mainnet.g.alchemy.com/v2/WLI0ohbUlvbsJVmoIvB1wTSwUA8qP5qS"
- eth_getBalance_payload = {
- "id": 1,
- "jsonrpc": "2.0",
- "params": ["0x0f6e93a1d47c92ebf83bcb995e9fb4238187f030", "latest"],
- "method": "eth_getBalance"
- }
- headers = {
- "accept": "application/json",
- "content-type": "application/json"
- }
- req_response = requests.post(url, json=eth_getBalance_payload, headers=headers)
- print(req_response.text)
- response = json.loads(
- req_response.text)
- print(response)
- dalao_balance = int(response["result"], 16)/10**18
- print(dalao_balance)
- # https://docs.alchemy.com/reference/eth-getbalance
- # https://docs.alchemy.com/reference/alchemy-gettokenbalances
- 如果是在合约外部判断,则可以使用web3.eth.getCode(),或者是对应的JSON-RPC方法eth_getcode。
- getCode()用来获取参数地址所对应合约的代码,如果参数是一个外部账号地址,则返回"0x";如果参数是合约,则返回对应的字节码,如下所示:
- web3.eth.getCode("0xa5Acc472597C1e1651270da9081Cc5a0b38258E3")
- "0x"
- web3.eth.getCode("0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8")
- "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"
- 这样我们就可以通过getCode()的内容判断是哪一种地址了。
|