-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc.py
More file actions
executable file
·28 lines (22 loc) · 781 Bytes
/
rpc.py
File metadata and controls
executable file
·28 lines (22 loc) · 781 Bytes
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
#!/usr/bin/env python3
import sys
import json
import urllib.request
argc = len(sys.argv) - 1
rpc_method = "eth_blockNumber"
rpc_params = []
rpc_endpoint = "http://localhost:8545"
if argc > 0: rpc_method = sys.argv[1].replace(".", "_")
if argc > 1: rpc_params = json.loads(sys.argv[2])
if argc > 2: rpc_endpoint = sys.argv[3]
rpc_call = {"jsonrpc": "2.0", "method": rpc_method, "params": rpc_params, "id": 1}
try:
req = urllib.request.Request(rpc_endpoint,
data=json.dumps(rpc_call).encode("utf-8"),
headers={"content-type": "application/json"})
with urllib.request.urlopen(req) as f:
res = f.read()
res_json = json.loads(res.decode())
print(json.dumps(res_json["result"], indent=2))
except Exception as e:
print(e)