forked from algorand/py-algorand-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_custom_header.py
39 lines (30 loc) · 1.13 KB
/
example_custom_header.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
37
38
39
# Example of accesing a remote API with a custom token key.
#
# In this case, the API is expecting the key "X-API-Key" instead of the
# default "X-Algo-API-Token". This is done by using a dict with our custom
# key, instead of a string, as the token.
from algosdk import algod
algod_address = "https://......"
algod_token = ""
headers = {
"X-API-Key": "#######",
}
def main():
algod_client = algod.AlgodClient(algod_token, algod_address, headers)
try:
status = algod_client.status()
except Exception as e:
print("Failed to get algod status: {}".format(e))
if status:
print("algod last round: {}".format(status.get("lastRound")))
print("algod time since last round: {}".format(
status.get("timeSinceLastRound")))
print("algod catchup: {}".format(status.get("catchupTime")))
print("algod latest version: {}".format(
status.get("lastConsensusVersion")))
# Retrieve latest block information
last_round = algod_client.status().get("lastRound")
print("####################")
block = algod_client.block_info(last_round)
print(block)
main()