install_api_call_counter_middleware

Documentation for eth_defi.chain.install_api_call_counter_middleware function.

install_api_call_counter_middleware(web3)[source]

Install API call counter middleware.

Measure total and per-API EVM call counts for your application.

  • Every time a Web3 API is called increase its count.

  • Attach web3.api_counter object to the connection

Example:

from eth_defi.chain import install_api_call_counter_middleware

web3 = Web3(tester)

counter = install_api_call_counter_middleware(web3)

# Make an API call
_ = web3.eth.chain_id

assert counter["total"] == 1
assert counter["eth_chainId"] == 1

# Make another API call
_ = web3.eth.block_number

assert counter["total"] == 2
assert counter["eth_blockNumber"] == 1
Returns

Counter object with columns per RPC endpoint and “total”

Parameters

web3 (web3.main.Web3) –

Return type

collections.Counter