Overview

The purpose of this page is to give you a sense of everything ETHHelper can do and to serve as a quick reference guide. You’ll find a summary of each feature with links to learn more.

Configuration

In order to use interfaces of ETHHelper, you need to provide a hostname and port of your Geth Web Services(include HTTP and WebSocket) and make sure net/txpool/eth namespaces are opened.

Third-party node services are available, but not all namespaces are guaranteed to be available. Nor does it ensure that the parsing of the information is legal.

Geth HTTP Connector

To use the HTTP interface of GethHTTPConnector, you need to provide the hostname and port of the HTTP service of your Geth node. If on the machine where Geth is deployed, this should default to http://localhost:8545.

Note

Please pay attention to marking http/https headers correctly, which is especially important when using third-party node services.

Geth HTTP Connector Example

>>> from ethhelper import GethHttpConnector
>>> connector = GethHttpConnector("http://localhost:8545/")
>>> await connector.test_connection()
True

Note

All interfaces in this repo rely on the asynchronous environment, so the asyncio environment is required when using the REPL for interactive coding. This can be done by running python -m asyncio directly on the command line or shell (instead of python).

Geth New Block Subscriber

In order to use GethNewBlockSubscriber, you need to provide the hostname and port of the websocket service of your Geth node. If on the machine where Geth is deployed, you need to enable the Websocket service in the command lines of the startup of the Geth node(or some kind of config file). In this case, the hostname and port provided should default to ws://localhost:8546.

Note

Please pay attention to marking ws/wss headers correctly, which is especially important when using third-party node services.

Geth New Block Subscriber Example

You can see an example of this feature here.

HTTP API

GethHttpConnector of ETHHelper provides a series of HTTP APIs, including repackaging of eth/net namespaces interfaces of Web3.py (based on the data structure defined by using pydantic). It also supported for native txpool namespace of Geth node. On those basis, a series of convenient and fast asynchronous aggregation interfaces (named as custom space) is provided.

Note

GethHttpConnector does not use the same namespace naming method as Web3.py (ie, one submodule per namespace). On the contrary, for flat design and quick access, GethHttpConnector uses the first word of the function name to distinguish the namespace. The only exception is that the custom space ignores the first word directly.

Eth Namespace

Net Namespace

Txpool Namespace

Custom Namespace

WS API

ETHHelper implements an abstract class GethSubscriber to maintain a complete Geth Websocket connection life cycle. Starting from the function, a GethNewBlockSubscriber is exported to subscribe to new block messages on the basis of the Websocket connection.

GethNewBlockSubscriber