Skip to content

Commit f488fe1

Browse files
committed
Addition of Blocks module.
1 parent 6ad7187 commit f488fe1

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,51 @@
22

33
[![Build Status](https://secure.travis-ci.org/corpetty/py-etherscan-api.png?branch=master)](http://travis-ci.org/corpetty/py-etherscan-api) [![Join the chat at https://gitter.im/py-etherscan/Lobby](https://badges.gitter.im/py-etherscan/Lobby.svg)](https://gitter.im/py-etherscan/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
44

5-
65
EtherScan.io API python bindings
76

87
## Description
9-
This module is written as an effort to provide python bindings to the EtherScan.io API, which can be found at:
10-
https://etherscan.io/apis. If you are interacting with a contract on the Ropsten Testnet please use
11-
https://ropsten.etherscan.io/apis.
8+
9+
This module is written as an effort to provide python bindings to the EtherScan.io API, which can be found at:
10+
https://etherscan.io/apis. If you are interacting with a contract on the Ropsten Testnet please use
11+
https://ropsten.etherscan.io/apis.
1212
In order to use this, you must attain an Etherscan user account, and generate an API key.
1313

1414
In order to use the API, you must provide an API key at runtime, which can be found at the Etherscan.io API website.
1515
If you'd like to use the provided examples without altering them, then the JSON file `api_key.json` must be stored in
16-
the base directory. Its format is as follows:
16+
the base directory. Its format is as follows:
1717

1818
{ "key" : "YourApiKeyToken" }
19-
19+
2020
with `YourApiKeyToken` is your provided API key token from EtherScan.io
2121

2222
## Installation
23+
2324
To install the package to your computer, simply run the following command in the base directory:
2425

2526
python3 -m pip install py-etherscan-api
26-
2727

2828
## Available bindings
29+
2930
Currently, only the following Etherscan.io API modules are available:
3031

3132
- accounts
3233
- contracts
3334
- stats
3435
- tokens
3536
- proxies
37+
- blocks
3638

3739
The remaining available modules provided by Etherscan.io will be added eventually...
3840

3941
## Available Networks
42+
4043
Currently, this works for the following networks:
4144

4245
- Mainnet
4346
- Ropsten
4447

4548
## Examples
49+
4650
All possible calls have an associated example file in the examples folder to show how to call the binding
4751

4852
These of course will be fleshed out with more details and explanation in time
@@ -53,15 +57,15 @@ Jupyter notebooks area also included in each directory to show all examples
5357

5458
- Package and submit to PyPI
5559
- Add the following modules:
56-
- event logs
57-
- geth proxy
58-
- websockets
60+
- event logs
61+
- geth proxy
62+
- websockets
5963
- Add robust documentation
6064
- Add unit test suite
6165
- Add request throttling based on Etherscan's suggestions
6266

63-
6467
## Holla at ya' boy
68+
6569
BTC: 16Ny72US78VEjL5GUinSAavDwARb8dXWKG
6670

6771
ETH: 0x5E8047fc033499BD5d8C463ADb29f10f11165ed0

etherscan/blocks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from .client import Client
2+
from typing import Union
3+
4+
5+
class Blocks(Client):
6+
def __init__(self, api_key='YourApiKeyToken'):
7+
Client.__init__(self, address='', api_key=api_key)
8+
self.url_dict[self.MODULE] = 'block'
9+
10+
def get_block_reward(self, block_number: Union[str, int]):
11+
self.url_dict[self.ACTION] = 'getblockreward'
12+
self.url_dict[self.BLOCKNO] = block_number if type(
13+
block_number) is str else str(block_number)
14+
self.build_url()
15+
req = self.connect()
16+
return req['result']

examples/blocks/__init__.py

Whitespace-only changes.

examples/blocks/get_block_reward.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from etherscan.blocks import Blocks
2+
import json
3+
4+
with open('../../api_key.json', mode='r') as key_file:
5+
key = json.loads(key_file.read())['key']
6+
7+
api = Blocks(api_key=key)
8+
reward = api.get_block_reward(5747732)
9+
print(reward)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name='py_etherscan_api',
55
version='0.8.0',
66
packages=['examples', 'examples.stats', 'examples.tokens',
7-
'examples.accounts', 'etherscan'],
7+
'examples.accounts', 'examples.blocks', 'etherscan'],
88
url='https://github.com/corpetty/py-etherscan-api',
99
license='MIT',
1010
author='coreypetty',

0 commit comments

Comments
 (0)