API References

Controllers

Base Controller

class ethereum_gasprice.controller.base.BaseGaspriceController(*, return_unit=<EthereumUnit.WEI: 'wei'>, providers=(), settings=None)[source]

Bases: abc.ABC

Parameters
  • return_unit (Literal[<EthereumUnit.WEI: ‘wei’>, <EthereumUnit.GWEI: ‘gwei’>]) – ethereum unit, which

  • providers (Sequence[Type[BaseGaspriceProvider]]) – tuple of providers classes, which will be initialized and used in given order

  • settings (Optional[Dict[str, Optional[str]]]) – Secrets for providers

abstract get_gasprice_by_strategy(strategy='fast')[source]

Get gasprice with chosen strategy from first available provider.

Parameters

strategy (Union[GaspriceStrategy, str]) – strategy class or identifier (str)

Return type

Optional[int]

abstract get_gasprice_from_all_sources()[source]

Get all gasprices from all available providers.

It is useful when you don’t trust single provider and what to verify gasprice with other providers. It is a good pratice to calculate an average gasprice for every strategy and take the average gasprice value.

Return type

Dict[str, Dict[str, int]]

abstract get_gasprices()[source]

Get all gasprice strategies values from first available provider.

Return type

Optional[Dict[GaspriceStrategy, Optional[int]]]

Sync Controller

class ethereum_gasprice.controller.sync_wrapper.GaspriceController(*, return_unit=<EthereumUnit.WEI: 'wei'>, providers=(<class 'ethereum_gasprice.providers.etherscan_provider.EtherscanProvider'>, <class 'ethereum_gasprice.providers.ethgasstation_provider.EthGasStationProvider'>, <class 'ethereum_gasprice.providers.etherchain_provider.EtherchainProvider'>), settings=None)[source]

Bases: ethereum_gasprice.controller.base.BaseGaspriceController

Entrypoint for fetching gasprice.

Parameters
  • return_unit (Literal[<EthereumUnit.WEI: ‘wei’>, <EthereumUnit.GWEI: ‘gwei’>]) – type of return value

  • providers (Sequence[Type[BaseGaspriceProvider]]) – gasprice provider class

  • settings (Optional[Dict[str, Optional[str]]]) – controller settings

get_gasprice_by_strategy(strategy='fast')[source]

Get gasprice with chosen strategy from first available provider.

Parameters

strategy (Union[GaspriceStrategy, str]) – strategy class or identifier (str)

Return type

Optional[int]

get_gasprice_from_all_sources()[source]

Get all gasprices from all available providers.

It is useful when you don’t trust single provider and what to verify gasprice with other providers. It is a good pratice to calculate an average gasprice for every strategy and take the average gasprice value.

Return type

Dict[str, Dict[str, int]]

get_gasprices()[source]

Get all gasprice strategies values from first available provider.

Return type

Optional[Dict[GaspriceStrategy, Optional[int]]]

Async Controller

class ethereum_gasprice.controller.async_wrapper.AsyncGaspriceController(*, return_unit=<EthereumUnit.WEI: 'wei'>, providers=(<class 'ethereum_gasprice.providers.etherscan_provider.AsyncEtherscanProvider'>, <class 'ethereum_gasprice.providers.ethgasstation_provider.AsyncEthGasStationProvider'>, <class 'ethereum_gasprice.providers.etherchain_provider.AsyncEtherchainProvider'>), settings=None)[source]

Bases: ethereum_gasprice.controller.sync_wrapper.GaspriceController

Entrypoint for fetching gasprice.

Parameters
  • return_unit (Literal[<EthereumUnit.WEI: ‘wei’>, <EthereumUnit.GWEI: ‘gwei’>]) – type of return value

  • providers (Sequence[Type[BaseGaspriceProvider]]) – gasprice provider class

  • settings (Optional[Dict[str, Optional[str]]]) – controller settings

async get_gasprice_by_strategy(strategy='fast')[source]

Get gasprice with chosen strategy from first available provider.

Parameters

strategy (Union[GaspriceStrategy, str]) – strategy class or identifier (str)

Return type

Optional[int]

async get_gasprice_from_all_sources()[source]

Get all gasprices from all available providers.

Uses asyncio.gather to speed up requests

It is useful when you don’t trust single provider and what to verify gasprice with other providers. It is a good pratice to calculate an average gasprice for every strategy and take the average gasprice value.

Return type

Dict[str, Dict[str, int]]

async get_gasprices()[source]

Get all gasprice strategies values from first available provider.

Return type

Optional[Dict[GaspriceStrategy, Optional[int]]]

Providers

Base Provider

class ethereum_gasprice.providers.base.BaseAPIGaspriceProvider(secret=None, *args, **kwargs)[source]

Bases: ethereum_gasprice.providers.base.BaseGaspriceProvider, abc.ABC

class ethereum_gasprice.providers.base.BaseAsyncAPIGaspriceProvider(*, secret=None, client=None, **kwargs)[source]

Bases: ethereum_gasprice.providers.base.BaseAPIGaspriceProvider, abc.ABC

async get_gasprice()[source]

Get gasprice from provider and prepare data.

Return type

Tuple[bool, Dict[GaspriceStrategy, Optional[int]]]

class ethereum_gasprice.providers.base.BaseGaspriceProvider(secret=None, *args, **kwargs)[source]

Bases: abc.ABC

class ethereum_gasprice.providers.base.BaseSyncAPIGaspriceProvider(*, secret=None, client=None, **kwargs)[source]

Bases: ethereum_gasprice.providers.base.BaseAPIGaspriceProvider, abc.ABC

get_gasprice()[source]

Get gasprice from provider and prepare data.

Return type

Tuple[bool, Dict[GaspriceStrategy, Dict[str, int]]]

Etherchain Provider

class ethereum_gasprice.providers.etherchain_provider.AsyncEtherchainProvider(*, secret=None, client=None, **kwargs)[source]

Bases: ethereum_gasprice.providers.base.BaseAsyncAPIGaspriceProvider, ethereum_gasprice.providers.etherchain_provider.EtherchainProvider

async request()[source]

Make request to API.

Return type

Tuple[bool, dict]

class ethereum_gasprice.providers.etherchain_provider.EtherchainProvider(*, secret=None, client=None, **kwargs)[source]

Bases: ethereum_gasprice.providers.base.BaseSyncAPIGaspriceProvider

Provider for Etherscan Gas Tracker (https://etherscan.io/gasTracker)

request()[source]

Make request to API.

Return type

Tuple[bool, dict]

Etherscan Provider

class ethereum_gasprice.providers.etherscan_provider.AsyncEtherscanProvider(*, secret=None, client=None, **kwargs)[source]

Bases: ethereum_gasprice.providers.base.BaseAsyncAPIGaspriceProvider, ethereum_gasprice.providers.etherscan_provider.EtherscanProvider

async request()[source]

Make request to API.

Return type

Tuple[bool, dict]

class ethereum_gasprice.providers.etherscan_provider.EtherscanProvider(*, secret=None, client=None, **kwargs)[source]

Bases: ethereum_gasprice.providers.base.BaseSyncAPIGaspriceProvider

Provider for Etherscan Gas Tracker (https://etherscan.io/gasTracker)

request()[source]

Make request to API.

Return type

Tuple[bool, dict]

EthGasStation Provider

class ethereum_gasprice.providers.ethgasstation_provider.AsyncEthGasStationProvider(*, secret=None, client=None, **kwargs)[source]

Bases: ethereum_gasprice.providers.base.BaseAsyncAPIGaspriceProvider, ethereum_gasprice.providers.ethgasstation_provider.EthGasStationProvider

async request()[source]

Make request to API.

Return type

Tuple[bool, dict]

class ethereum_gasprice.providers.ethgasstation_provider.EthGasStationProvider(*, secret=None, client=None, **kwargs)[source]

Bases: ethereum_gasprice.providers.base.BaseSyncAPIGaspriceProvider

Provider for Eth Gas Station (https://ethgasstation.info/)

request()[source]

Make request to API.

Return type

Tuple[bool, dict]

Web3 Provider

class ethereum_gasprice.providers.web3_provider.Web3Provider(secret=None, *args, **kwargs)[source]

Bases: ethereum_gasprice.providers.base.BaseGaspriceProvider

Provider for Web3 RPC.

get_gasprice()[source]

Get gasprice from provider and prepare data.

Return type

Tuple[bool, Dict[GaspriceStrategy, Optional[int]]]