├── .gitignore ├── LICENSE ├── README.md ├── docs ├── Makefile ├── conf.py ├── index.rst ├── locales │ └── zh_CN │ │ └── LC_MESSAGES │ │ └── index.po ├── make.bat └── readthedocs.yml ├── etherscan ├── __init__.py ├── errors.py └── etherscan.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # For dev test 2 | *test.py 3 | 4 | # PyCharm stuff: 5 | .idea 6 | 7 | # Byte-compiled / optimized / DLL files 8 | __pycache__/ 9 | *.py[cod] 10 | *$py.class 11 | 12 | # C extensions 13 | *.so 14 | 15 | # Distribution / packaging 16 | .Python 17 | build/ 18 | develop-eggs/ 19 | dist/ 20 | downloads/ 21 | eggs/ 22 | .eggs/ 23 | lib/ 24 | lib64/ 25 | parts/ 26 | sdist/ 27 | var/ 28 | wheels/ 29 | *.egg-info/ 30 | .installed.cfg 31 | *.egg 32 | MANIFEST 33 | 34 | # PyInstaller 35 | # Usually these files are written by a python script from a template 36 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 37 | *.manifest 38 | *.spec 39 | 40 | # Installer logs 41 | pip-log.txt 42 | pip-delete-this-directory.txt 43 | 44 | # Unit test / coverage reports 45 | htmlcov/ 46 | .tox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *.cover 53 | .hypothesis/ 54 | .pytest_cache/ 55 | 56 | # Translations 57 | *.mo 58 | *.pot 59 | 60 | # Django stuff: 61 | *.log 62 | local_settings.py 63 | db.sqlite3 64 | 65 | # Flask stuff: 66 | instance/ 67 | .webassets-cache 68 | 69 | # Scrapy stuff: 70 | .scrapy 71 | 72 | # Sphinx documentation 73 | docs/_build/ 74 | 75 | # PyBuilder 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # pyenv 82 | .python-version 83 | 84 | # celery beat schedule file 85 | celerybeat-schedule 86 | 87 | # SageMath parsed files 88 | *.sage.py 89 | 90 | # Environments 91 | .env 92 | .venv 93 | env/ 94 | venv/ 95 | ENV/ 96 | env.bak/ 97 | venv.bak/ 98 | 99 | # Spyder project settings 100 | .spyderproject 101 | .spyproject 102 | 103 | # Rope project settings 104 | .ropeproject 105 | 106 | # mkdocs documentation 107 | /site 108 | 109 | # mypy 110 | .mypy_cache/ 111 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 NeoS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Etherscan.io API wrapper 2 | 3 | [![PyPi Version](http://img.shields.io/pypi/v/etherscan.svg)](https://pypi.python.org/pypi/etherscan/) 4 | 5 | An Etherscan.io API wrapper, for Python. 6 | 7 | With a default cache supported by [requests-cache](https://github.com/reclosedev/requests-cache) 8 | 9 | ## Installation 10 | ``` 11 | pip3 install etherscan 12 | ``` 13 | 14 | ## Usage 15 | ```python 16 | import etherscan 17 | 18 | es = etherscan.Client( 19 | api_key='YOUR_API_KEY', 20 | cache_expire_after=5, 21 | ) 22 | 23 | eth_price = es.get_eth_price() 24 | 25 | eth_supply = es.get_eth_supply() 26 | 27 | eth_balance = es.get_eth_balance('0x39eB410144784010b84B076087B073889411F878') 28 | 29 | eth_balances = es.get_eth_balances([ 30 | '0x39eB410144784010b84B076087B073889411F878', 31 | '0x39eB410144784010b84B076087B073889411F879', 32 | ]) 33 | 34 | gas_price = es.get_gas_price() 35 | 36 | block = es.get_block_by_number(block_number=12345) 37 | 38 | transactions = es.get_transactions_by_address('0x39eB410144784010b84B076087B073889411F878') 39 | 40 | token_transations = es.get_token_transactions( 41 | contract_address='0xEF68e7C694F40c8202821eDF525dE3782458639f', 42 | address='0xEF68e7C694F40c8202821eDF525dE3782458639f', 43 | ) 44 | ``` 45 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SOURCEDIR = . 8 | BUILDDIR = _build 9 | 10 | # Put it first so that "make" without argument is like "make help". 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | .PHONY: help Makefile 15 | 16 | # Catch-all target: route all unknown targets to Sphinx using the new 17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 18 | %: Makefile 19 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Configuration file for the Sphinx documentation builder. 4 | # 5 | # This file does only contain a selection of the most common options. For a 6 | # full list see the documentation: 7 | # http://www.sphinx-doc.org/en/master/config 8 | 9 | # -- Path setup -------------------------------------------------------------- 10 | 11 | # If extensions (or modules to document with autodoc) are in another directory, 12 | # add these directories to sys.path here. If the directory is relative to the 13 | # documentation root, use os.path.abspath to make it absolute, like shown here. 14 | # 15 | # import os 16 | # import sys 17 | # sys.path.insert(0, os.path.abspath('.')) 18 | # from recommonmark.parser import CommonMarkParser 19 | # 20 | # source_parsers = { 21 | # '.md': CommonMarkParser, 22 | # } 23 | 24 | # -- Project information ----------------------------------------------------- 25 | 26 | project = 'etherscan' 27 | copyright = '2018, neoctobers' 28 | author = 'neoctobers' 29 | 30 | # The short X.Y version 31 | version = '' 32 | # The full version, including alpha/beta/rc tags 33 | release = '0.2.3' 34 | 35 | 36 | # -- General configuration --------------------------------------------------- 37 | 38 | # If your documentation needs a minimal Sphinx version, state it here. 39 | # 40 | # needs_sphinx = '1.0' 41 | 42 | # Add any Sphinx extension module names here, as strings. They can be 43 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 44 | # ones. 45 | extensions = [ 46 | ] 47 | 48 | # Add any paths that contain templates here, relative to this directory. 49 | templates_path = ['_templates'] 50 | 51 | # The suffix(es) of source filenames. 52 | # You can specify multiple suffix as a list of string: 53 | # 54 | # source_suffix = ['.rst', '.md'] 55 | source_suffix = '.rst' 56 | 57 | # The master toctree document. 58 | master_doc = 'index' 59 | 60 | # The language for content autogenerated by Sphinx. Refer to documentation 61 | # for a list of supported languages. 62 | # 63 | # This is also used if you do content translation via gettext catalogs. 64 | # Usually you set "language" from the command line for these cases. 65 | language = None 66 | 67 | # List of patterns, relative to source directory, that match files and 68 | # directories to ignore when looking for source files. 69 | # This pattern also affects html_static_path and html_extra_path. 70 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 71 | 72 | # The name of the Pygments (syntax highlighting) style to use. 73 | pygments_style = None 74 | 75 | 76 | # -- Options for HTML output ------------------------------------------------- 77 | 78 | # The theme to use for HTML and HTML Help pages. See the documentation for 79 | # a list of builtin themes. 80 | # 81 | # html_theme = 'alabaster' 82 | html_theme = 'sphinx_rtd_theme' 83 | 84 | # Theme options are theme-specific and customize the look and feel of a theme 85 | # further. For a list of options available for each theme, see the 86 | # documentation. 87 | # 88 | # html_theme_options = {} 89 | 90 | # Add any paths that contain custom static files (such as style sheets) here, 91 | # relative to this directory. They are copied after the builtin static files, 92 | # so a file named "default.css" will overwrite the builtin "default.css". 93 | html_static_path = ['_static'] 94 | 95 | # Custom sidebar templates, must be a dictionary that maps document names 96 | # to template names. 97 | # 98 | # The default sidebars (for documents that don't match any pattern) are 99 | # defined by theme itself. Builtin themes are using these templates by 100 | # default: ``['localtoc.html', 'relations.html', 'sourcelink.html', 101 | # 'searchbox.html']``. 102 | # 103 | # html_sidebars = {} 104 | 105 | 106 | # -- Options for HTMLHelp output --------------------------------------------- 107 | 108 | # Output file base name for HTML help builder. 109 | htmlhelp_basename = 'etherscandoc' 110 | 111 | 112 | # -- Options for LaTeX output ------------------------------------------------ 113 | 114 | latex_elements = { 115 | # The paper size ('letterpaper' or 'a4paper'). 116 | # 117 | # 'papersize': 'letterpaper', 118 | 119 | # The font size ('10pt', '11pt' or '12pt'). 120 | # 121 | # 'pointsize': '10pt', 122 | 123 | # Additional stuff for the LaTeX preamble. 124 | # 125 | # 'preamble': '', 126 | 127 | # Latex figure (float) alignment 128 | # 129 | # 'figure_align': 'htbp', 130 | } 131 | 132 | # Grouping the document tree into LaTeX files. List of tuples 133 | # (source start file, target name, title, 134 | # author, documentclass [howto, manual, or own class]). 135 | latex_documents = [ 136 | (master_doc, 'etherscan.tex', 'etherscan Documentation', 137 | 'neoctobers', 'manual'), 138 | ] 139 | 140 | 141 | # -- Options for manual page output ------------------------------------------ 142 | 143 | # One entry per manual page. List of tuples 144 | # (source start file, name, description, authors, manual section). 145 | man_pages = [ 146 | (master_doc, 'etherscan', 'etherscan Documentation', 147 | [author], 1) 148 | ] 149 | 150 | 151 | # -- Options for Texinfo output ---------------------------------------------- 152 | 153 | # Grouping the document tree into Texinfo files. List of tuples 154 | # (source start file, target name, title, author, 155 | # dir menu entry, description, category) 156 | texinfo_documents = [ 157 | (master_doc, 'etherscan', 'etherscan Documentation', 158 | author, 'etherscan', 'One line description of project.', 159 | 'Miscellaneous'), 160 | ] 161 | 162 | 163 | # -- Options for Epub output ------------------------------------------------- 164 | 165 | # Bibliographic Dublin Core info. 166 | epub_title = project 167 | 168 | # The unique identifier of the text. This can be a ISBN number 169 | # or the project homepage. 170 | # 171 | # epub_identifier = '' 172 | 173 | # A unique identification for the text. 174 | # 175 | # epub_uid = '' 176 | 177 | # A list of files that should not be packed into the epub file. 178 | epub_exclude_files = ['search.html'] 179 | 180 | locale_dirs = ['locales/'] #path is example but recommended. 181 | gettext_compact = False #optional. 182 | 183 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | 2 | Welcome to etherscan.io API python wapper! 3 | ========================================== 4 | 5 | This is an index page. 6 | -------------------------------------------------------------------------------- /docs/locales/zh_CN/LC_MESSAGES/index.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) 2018, neoctobers 3 | # This file is distributed under the same license as the etherscan package. 4 | # FIRST AUTHOR , 2018. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: etherscan \n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2018-12-05 21:53+0800\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=utf-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "Generated-By: Babel 2.6.0\n" 19 | 20 | #: ../../index.rst:3 21 | msgid "Welcome to etherscan.io API python wapper!" 22 | msgstr "中文标题" 23 | 24 | #: ../../index.rst:5 25 | msgid "This is an index page." 26 | msgstr "中文正文" 27 | 28 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/readthedocs.yml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yml 2 | 3 | build: 4 | image: latest 5 | 6 | python: 7 | version: 3.6 8 | setup_py_install: true 9 | -------------------------------------------------------------------------------- /etherscan/__init__.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | from .etherscan import * 3 | 4 | name = 'etherscan' 5 | -------------------------------------------------------------------------------- /etherscan/errors.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | 3 | 4 | class EtherscanIoException(Exception): 5 | pass 6 | -------------------------------------------------------------------------------- /etherscan/etherscan.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import os 3 | import tempfile 4 | import requests_cache 5 | from .errors import EtherscanIoException 6 | 7 | 8 | class Client(): 9 | 10 | def __init__(self, 11 | api_key: str, 12 | network=None, 13 | cache_backend='sqlite', 14 | cache_expire_after=5, 15 | ): 16 | 17 | # API URL 18 | self._api_url = 'https://api.etherscan.io/api' 19 | 20 | # API Key 21 | self._api_key = api_key 22 | 23 | # Network 24 | if network: 25 | if network not in ['ropsten', 'kovan', 'rinkeby']: 26 | raise Exception('network could only be None(mainnet) /ropsten/kovan/rinkeby') 27 | 28 | self._api_url = 'https://api-{network}.etherscan.io/api'.format( 29 | network=network 30 | ) 31 | 32 | # params 33 | self._params = { 34 | 'apikey': self._api_key, 35 | } 36 | 37 | # session & cache 38 | self._session = None 39 | self._cache_name = os.path.join(tempfile.gettempdir(), 'etherscan_cache') 40 | self._cache_backend = cache_backend 41 | self._cache_expire_after = cache_expire_after 42 | 43 | @property 44 | def session(self): 45 | if not self._session: 46 | self._session = requests_cache.core.CachedSession( 47 | cache_name=self._cache_name, 48 | backend=self._cache_backend, 49 | expire_after=self._cache_expire_after, 50 | ) 51 | 52 | self._session.headers.update( 53 | { 54 | 'User-agent': 'etherscan - python wrapper ' 55 | 'around etherscan.io (github.com/neoctobers/etherscan)' 56 | } 57 | ) 58 | 59 | return self._session 60 | 61 | def __req(self): 62 | r = self.session.post(url=self._api_url, data=self._params).json() 63 | 64 | if '0' == r['status']: 65 | print('--- Etherscan.io Message ---', r['message']) 66 | 67 | return r['result'] 68 | 69 | def __proxy_req(self): 70 | self._params['module'] = 'proxy' 71 | 72 | # get, json 73 | r = self.session.get(url=self._api_url, data=self._params).json() 74 | 75 | # todo: handle exceptions 76 | 77 | return r['result'] 78 | 79 | @staticmethod 80 | def __bool(x: str): 81 | """Convert str to bool""" 82 | if x.lower() in ['0', 'false', 'none', 'null', 'n/a', '']: 83 | return False 84 | return True 85 | 86 | @staticmethod 87 | def __int(x: str): 88 | """Convert str to int or None""" 89 | if x == '': 90 | return None 91 | return int(x) 92 | 93 | @staticmethod 94 | def __str(x: str): 95 | """Return str or None""" 96 | if x == '': 97 | return None 98 | return x 99 | 100 | def get_eth_price(self): 101 | """Get ETH price.""" 102 | self._params['module'] = 'stats' 103 | self._params['action'] = 'ethprice' 104 | 105 | r = self.__req() 106 | 107 | return { 108 | 'ethbtc': float(r['ethbtc']), 109 | 'ethbtc_timestamp': int(r['ethbtc_timestamp']), 110 | 'ethusd': float(r['ethusd']), 111 | 'ethusd_timestamp': int(r['ethbtc_timestamp']), 112 | } 113 | 114 | def get_eth_supply(self): 115 | self._params['module'] = 'stats' 116 | self._params['action'] = 'ethsupply' 117 | 118 | return int(self.__req()) 119 | 120 | def get_eth_balance(self, address: str): 121 | """Get ETH balance by address.""" 122 | self._params['module'] = 'account' 123 | self._params['action'] = 'balance' 124 | self._params['address'] = address 125 | 126 | return int(self.__req()) 127 | 128 | def get_eth_balances(self, addresses: list): 129 | """Get ETH balances by addresses list.""" 130 | self._params['module'] = 'account' 131 | self._params['action'] = 'balancemulti' 132 | self._params['address'] = ','.join(addresses) 133 | 134 | balances = {} 135 | for row in self.__req(): 136 | balances[row['account']] = int(row['balance']) 137 | 138 | return balances 139 | 140 | def __transaction(self, source: dict): 141 | """Repack the __transaction dict""" 142 | return { 143 | 'timestamp': self.__int(source['timeStamp']), 144 | 'block_number': self.__int(source['blockNumber']), 145 | 146 | 'from': self.__str(source['from']), 147 | 'to': self.__str(source['to']), 148 | 'input': self.__str(source['input']), 149 | 'hash': self.__str(source['hash']), 150 | 'value': self.__int(source['value']), 151 | 152 | 'gas': self.__int(source['gas']), 153 | 'gas_price': self.__int(source['gasPrice']), 154 | 'gas_used': self.__int(source['gasUsed']), 155 | 'nonce': self.__int(source['nonce']), 156 | 'confirmations': self.__int(source['confirmations']), 157 | 158 | 'is_error': self.__bool(source['isError']), 159 | 'tx_receipt_status': self.__bool(source['txreceipt_status']), 160 | 161 | 'transaction_index': self.__int(source['transactionIndex']), 162 | 'cumulative_gas_used': self.__int(source['cumulativeGasUsed']), 163 | 164 | 'block_hash': self.__str(source['blockHash']), 165 | } 166 | 167 | def get_transactions_by_address(self, 168 | address: str, 169 | type: str = 'normal', 170 | start_block: int = 0, 171 | end_block: int = 999999999, 172 | page: int = 1, 173 | limit: int = 1000, 174 | sort: str = 'asc', 175 | ): 176 | """Get transactions by address.""" 177 | self._params['module'] = 'account' 178 | 179 | if type == 'normal': 180 | self._params['action'] = 'txlist' 181 | elif type == 'internal': 182 | self._params['action'] = 'txlistinternal' 183 | else: 184 | raise Exception('param `type` must be "normal" or "internal"') 185 | 186 | self._params['address'] = address 187 | self._params['startblock'] = start_block 188 | self._params['endblock'] = end_block 189 | self._params['page'] = page 190 | self._params['offset'] = limit 191 | self._params['sort'] = sort 192 | 193 | rs = self.__req() 194 | 195 | transactions = [] 196 | for t in rs: 197 | transactions.append(self.__transaction(t)) 198 | 199 | return transactions 200 | 201 | def __token_transaction(self, source: dict): 202 | """Repack the token __transaction dict""" 203 | return { 204 | 'timestamp': self.__int(source['timeStamp']), 205 | 'block_number': self.__int(source['blockNumber']), 206 | 207 | 'from': self.__str(source['from']), 208 | 'to': self.__str(source['to']), 209 | 'input': self.__str(source['input']), 210 | 'hash': self.__str(source['hash']), 211 | 'value': self.__int(source['value']), 212 | 213 | 'gas': self.__int(source['gas']), 214 | 'gas_price': self.__int(source['gasPrice']), 215 | 'gas_used': self.__int(source['gasUsed']), 216 | 'nonce': self.__int(source['nonce']), 217 | 'confirmations': self.__int(source['confirmations']), 218 | 219 | 'contract_address': self.__str(source['contractAddress']), 220 | 'token_decimal': self.__int(source['tokenDecimal']), 221 | 'token_name': self.__str(source['tokenName']), 222 | 'token_symbol': self.__str(source['tokenSymbol']), 223 | 224 | 'transaction_index': self.__int(source['transactionIndex']), 225 | 'cumulative_gas_used': self.__int(source['cumulativeGasUsed']), 226 | 'block_hash': self.__str(source['blockHash']), 227 | } 228 | 229 | def get_token_transactions(self, 230 | contract_address: str = None, 231 | address: str = None, 232 | start_block: int = 0, 233 | end_block: int = 999999999, 234 | page: int = 1, 235 | limit: int = 1000, 236 | sort: str = 'asc', 237 | ): 238 | """Get ERC20 token transactions by contract address.""" 239 | if contract_address is None and address is None: 240 | raise EtherscanIoException('Param `contract_address` and `address` cannot be None at the same time.') 241 | 242 | self._params['module'] = 'account' 243 | self._params['action'] = 'tokentx' 244 | 245 | if contract_address: 246 | self._params['contractaddress'] = contract_address 247 | 248 | if address: 249 | self._params['address'] = address 250 | 251 | self._params['startblock'] = start_block 252 | self._params['endblock'] = end_block 253 | self._params['page'] = page 254 | self._params['offset'] = limit 255 | self._params['sort'] = sort 256 | 257 | rs = self.__req() 258 | 259 | token_transactions = [] 260 | for t in rs: 261 | token_transactions.append(self.__token_transaction(t)) 262 | 263 | return token_transactions 264 | 265 | def get_gas_price(self): 266 | """Get gas price.""" 267 | self._params['action'] = 'eth_gasPrice' 268 | 269 | return int(self.__proxy_req(), 16) 270 | 271 | def get_block_number(self): 272 | """Get latest block number.""" 273 | self._params['action'] = 'eth_blockNumber' 274 | 275 | return int(self.__proxy_req(), 16) 276 | 277 | def get_block_by_number(self, block_number): 278 | """Get block by number.""" 279 | self._params['action'] = 'eth_getBlockByNumber' 280 | self._params['tag'] = hex(block_number) 281 | self._params['boolean'] = True 282 | 283 | return self.__proxy_req() 284 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import setuptools 3 | 4 | with open("README.md", "r") as fh: 5 | long_description = fh.read() 6 | 7 | setuptools.setup( 8 | name="etherscan", 9 | version="0.2.3", 10 | author="@neoctobers", 11 | author_email="neoctobers@gmail.com", 12 | description="Etherscan.io API wrapper", 13 | long_description=long_description, 14 | long_description_content_type="text/markdown", 15 | url="https://github.com/neoctobers/etherscan", 16 | packages=setuptools.find_packages(), 17 | classifiers=[ 18 | "Programming Language :: Python :: 3", 19 | "License :: OSI Approved :: MIT License", 20 | "Operating System :: OS Independent", 21 | ], 22 | install_requires=[ 23 | 'requests_cache', 24 | ], 25 | ) 26 | --------------------------------------------------------------------------------