Web3Config#

tradeexecutor.ethereum.web3config.Web3Config class.

class Web3Config[source]#

Bases: object

Advanced Web3 connection manager.

Supports multiple blockchain connections.

__init__(connections=<factory>, gas_price_method=None, default_chain_id=None)#
Parameters
Return type

None

Methods

__init__([connections, gas_price_method, ...])

check_default_chain_id()

Check that we are connected to the correct chain.

close()

Close all connections.

create_web3(url[, gas_price_method])

Create a new Web3.py connection.

get_connection(chain_id)

Get a connection to a specific network.

get_default()

Getst the default connection.

has_any_connection()

set_default_chain(chain_id)

Set the default chain our strategy runs on.

setup_from_environment(gas_price_method, ...)

Setup connections based on given RPC URLs.

Attributes

default_chain_id

Chain id for single chain strategies

gas_price_method

How do we price our txs

connections

Mapping of different connections for different chains

connections: Dict[ChainId, Web3]#

Mapping of different connections for different chains

gas_price_method: Optional[GasPriceMethod] = None#

How do we price our txs

default_chain_id: Optional[ChainId] = None#

Chain id for single chain strategies

static create_web3(url, gas_price_method=None)[source]#

Create a new Web3.py connection.

Parameters
  • url (str) – JSON-RPC node URL

  • gas_price_method (Optional[GasPriceMethod]) – How do we estimate gas for a transaction If not given autodetect the method.

Return type

Web3

close()[source]#

Close all connections.

set_default_chain(chain_id)[source]#

Set the default chain our strategy runs on.

Most strategies are single chain strategies. Set the chain id we expect these strategies to run on.

Parameters

chain_id (ChainId) –

get_connection(chain_id)[source]#

Get a connection to a specific network.

Parameters

chain_id (ChainId) –

Return type

Optional[Web3]

get_default()[source]#

Getst the default connection.

Assumes exactly 1 node connection available.

Return type

Web3

check_default_chain_id()[source]#

Check that we are connected to the correct chain.

The JSON-RPC node chain id should be the same as in the strategy module.

classmethod setup_from_environment(gas_price_method, **kwargs)[source]#

Setup connections based on given RPC URLs.

Read JSON_RPC_BINANCE, JSON_RPC_POLYGON, etc. environment variables.

Parameters
  • kwargs – {json_rpc_xxx: rpc URL} dict, as parsed by Typer.

  • gas_price_method (Optional[GasPriceMethod]) –

Return type

Web3Config

__init__(connections=<factory>, gas_price_method=None, default_chain_id=None)#
Parameters
Return type

None