provider.env

Documentation for eth_defi.provider.env Python module.

Get JSON-RPC URL from environment variables.

To support multiple blockchains, we use a naming convention for chains:

  • JSON_RPC_ETHEREUM for Ethereum Mainnet

  • JSON_RPC_ARBITRUM for Arbitrum

  • JSON_RPC_OPTIMISM for Optimism

  • JSON_RPC_ARBITRUM_SEPOLIA for Arbitrum Sepolia

  • JSON_RPC_BASE_SEPOLIA for Base Sepolia

All environment variables support multiple RPC providers per chain using a space-separated round robin mechanism. See MEV protection and multiple JSON-RPCs configuration for more details.

Example:

export JSON_RPC_BINANCE="https://bsc-dataseed.bnbchain.org https://bsc-dataseed.ninicoin.io https://bnb.rpc.subquery.network/public"

For the chain names and more information see eth_defi.chain.

Functions

get_json_rpc_env(chain)

Get the JSON-RPC URL environment variable based on the chain id.

read_json_rpc_url(chain)

Read JSON-RPC URL from environment variable based on the chain id.

get_json_rpc_env(chain)

Get the JSON-RPC URL environment variable based on the chain id.

  • Map chain id to a name and from there to environment variables.

Parameters

chain (int) –

Return type

str

read_json_rpc_url(chain)

Read JSON-RPC URL from environment variable based on the chain id.

Raises

ValueError – If the environment variable is not set for the given chain.

Parameters

chain (int) –

Return type

str