- Notifications
You must be signed in to change notification settings - Fork0
Library for fetching actual ethereum blockchain gasprice.
License
Elastoo-Team/ethereum-gasprice-py
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Library for fetching actual ethereum blockchain gasprice from different sources:Etherscan Gas Tracker,Eth Gas Station,Etherchain Gasprice Oracle,Web3 RPC Method.
Read more about gas and fee fromthis article
poetry add ethereum-gasprice
or
pip3 install ethereum-gasprice
fromethereum_gaspriceimportGaspriceController,GaspriceStrategy,EthereumUnitfromethereum_gasprice.providersimportEtherscanProviderETHERSCAN_API_KEY="..."# Pass api key to GaspriceController to initialize providercontroller=GaspriceController(settings={EtherscanProvider.title:ETHERSCAN_API_KEY},)# Get gasprice by one of these strategies:gasprice=controller.get_gasprice_by_strategy(GaspriceStrategy.FAST)print(gasprice)# output: 69
Read base API references and other part documentationonethereum-gasprice.readthedocs.io
Main entrypoint to fetching gasprice from providers. Has sync and async implementations.
It is recommended to initialize controller withwith ... as controller:
method
fromethereum_gaspriceimportGaspriceController,AsyncGaspriceController
Parameters:
return_unit
- return gasprice in given ethereum unit. It is recommended to useEthereumUnit
classfromethereum_gasprice.consts
to choose unitproviders
- tuple of providers what will be used in fetching gasprice. Order of providers is important
- gasprice will be fetch in given priority. Providers must be a subclass of
BaseGaspriceProvider
settings
- dict containing secrets for providers. Key is provider title slug, value is a secret for provider.
fromethereum_gasprice.constsimportEthereumUnitfromethereum_gasprice.providersimport (EtherscanProvider,EthGasStationProvider,AsyncEtherscanProvider,AsyncEthGasStationProvider)settings= {EtherscanProvider.title:"API_KEY",EthGasStationProvider.title:"API_KEY"}sync_providers= (EtherscanProvider,EthGasStationProvider)async_providers= (AsyncEtherscanProvider,AsyncEthGasStationProvider)withGaspriceStrategy(return_unit=EthereumUnit.GWEI,providers=sync_providers,settings=settings)ascontroller:# Do somethingpassasyncwithAsyncGaspriceController(return_unit=EthereumUnit.WEI,providers=async_providers,settings=settings)asasync_controller:# Do somethingpass
Methods:
.get_gasprice_by_strategy()
- get gasprices from first available provider and return only one gasprice strategy.
available strategies: slow (GaspriceStrategy.SLOW
), regular (GaspriceStrategy.REGULAR
),fast (GaspriceStrategy.FAST
), fastest (GaspriceStrategy.FASTEST
).
Some providers does not have info for some strategies. For example, Etherscan does not provide gasprice for slowstrategy.
In any case method will return dict with these for strategies. If fail case strategy (when all provides is unavailable)dict withNone
values will be returned.
fromethereum_gasprice.constsimportGaspriceStrategygasprice=controller.get_gasprice_by_strategy(GaspriceStrategy.FAST)# type: int, example: 69
.get_gasprices()
- gets gasprices for all strategies from first available provider. Returns a dict.
gasprices=awaitasync_controller.get_gasprices()# type: dictprint(gasprices)# {'slow': None, 'regular': 17, 'fast': 19, 'fastest': 20}
.get_gasprice_from_all_sources()
- get gasprices for all strategies from all available provider.
It can be useful to calculate an average gasprice value from all providers to get the most objective gasprice value.
gasprices=controller.get_gasprice_from_all_sources()# type: dictprint(gasprices)# {# 'etherscan': {'slow': None, 'regular': 17, 'fast': 19, 'fastest': 29},# 'ethgasstation': {'slow': 16, 'regular': 17, 'fast': 19, 'fastest': 20}# }
Provider wrapper
fromethereum_gasprice.providersimportEtherscanProvider,AsyncEtherscanProvider
Parameters:
secret
- any secret or api key which will be used in request.client
- sync or asynchttpx Client instance. For asyncproviderhttpx AsyncClient should be used.
Methods:
.request()
- make request to api, returns status and response data..get_gasprice()
- get gasprices from provider, returns gasprices in GWEI.
fromhttpximportClientprovider=EtherscanProvider(secret="API-KEY",client=Client())print(provider.get_gasprice())# {'slow': None, 'regular': 17, 'fast': 19, 'fastest': 20}
- Initital release
- Async implementation of controller, providers
- Write documentation
- Write unit tests with pytest
- Integrate tests, docs and auto publishing to pypi in github pipeline
see CHANGELOG.md file
Ethereum gasprice is licensed under the terms of the MIT License (see the file LICENSE).
About
Library for fetching actual ethereum blockchain gasprice.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.