- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathetherscanAPI.py
More file actions
Latest commit
36 lines (29 loc) · 1.68 KB
/
Copy pathetherscanAPI.py
File metadata and controls
36 lines (29 loc) · 1.68 KB
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
"""
Created on Wed Apr 10 17:21:42 2019
@author: Maher Alharby
"""
importrequests
classetherscan:
def__init__(self, apikey, network):
self.network=network
self.apikey=apikey
ifnetwork=='mainnet':
self.apipath='https://api.etherscan.io/api?'
else:
self.apipath='https://api'+'-'+network+'.etherscan.io/api?'
#### define all functions that we need to use from Etherscan APIs ####
defgetTransactions(self, address, fromblock, toblock,p,c):
payload= {'module':'account', 'action':'txlist', 'address':address, 'startblock':fromblock, 'endblock':toblock, 'page':p, 'offset':c, 'sort':'asc', 'apykey':self.apikey}
returnrequests.get(self.apipath, params=payload).json()['result']
defgetBlockNumber(self):
payload= {'module':'proxy', 'action':'eth_BlockNumber', 'apykey':self.apikey}
returnrequests.get(self.apipath, params=payload).json()['result']
defgetBlockByNumber(self, number):
payload= {'module':'proxy', 'action':'eth_getBlockByNumber', 'tag':hex(number), 'boolean':'true', 'apykey':self.apikey}
returnrequests.get(self.apipath, params=payload).json()['result']
defgetTransactionReceipt(self, txhash):
payload= {'module':'proxy', 'action':'eth_getTransactionReceipt', 'txhash':txhash, 'apykey':self.apikey}
returnrequests.get(self.apipath, params=payload).json()['result']
defgetCode(self, address):
payload= {'module':'proxy', 'action':'eth_getCode', 'address':address, 'tag':'latest', 'apykey':self.apikey}
returnrequests.get(self.apipath, params=payload).json()['result']