-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaucet_polygon.py
53 lines (46 loc) · 1.44 KB
/
faucet_polygon.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
import argparse
import requests
import json
import sched, time
import os
from dotenv import load_dotenv
load_dotenv()
WALLET_ADDRESS = os.getenv('WALLET_ADDRESS')
url = "https://api.faucet.matic.network/transferTokens"
s = sched.scheduler(time.time, time.sleep)
def callFaucet():
payload = json.dumps({
"network": "mumbai",
"address": WALLET_ADDRESS,
"token": "maticToken"
})
headers = {
'Content-Type': 'application/json'
}
success = False
while not success:
try:
response = requests.request("POST", url, headers=headers, data=payload)
print("RESPONSE OF FAUCET CALL", response.text)
respJson = response.json()
print("respJson", respJson['error'])
if(respJson['error'] == 'Returned error: replacement transaction underpriced'):
success = False
else:
s.enter(50, 1, callFaucet)
success = True
except Exception as e:
success = False
s.enter(50, 1, callFaucet)
print('Error! re-trying...', e)
def __main__():
try:
print("STARTING FAUCET REQUEST")
callFaucet()
s.run()
except Exception as e:
print("exception catched", e)
pass
if __name__ == '__main__':
__main__()