agent0.ethpy.base
Base utilities for working with contracts via web3
Submodules
Attributes
Functions
|
Get the balance for an account deployed on the web3 provider. |
|
Set the eth balance of the the account using the web3 provider. |
|
Retrieve the transaction receipt asynchronously, retrying with exponential backoff. |
|
Initialize a Web3 instance using an HTTP provider and inject a geth Proof of Authority (poa) middleware. |
Package Contents
- agent0.ethpy.base.get_account_balance(web3: web3.Web3, account_address: str) int | None
Get the balance for an account deployed on the web3 provider.
- Parameters:
web3 (Web3) – The instantiated web3 provider.
account_address (str) – The address of the account to fund.
- Returns:
The balance of the account in wei, or None if the rpc call failed.
- Return type:
int | None
- agent0.ethpy.base.set_account_balance(web3: web3.Web3, account_address: str, amount_wei: int) web3.types.RPCResponse
Set the eth balance of the the account using the web3 provider.
- Parameters:
web3 (Web3) – The instantiated web3 provider.
account_address (str) – The address of the account to fund.
amount_wei (int) – Amount_wei to fund, in wei.
- Returns:
success can be checked by inspecting rpc_response.error
- Return type:
RPCResponse
- async agent0.ethpy.base.async_wait_for_transaction_receipt(contract_function: pypechain.core.PypechainContractFunction, transaction_hash: hexbytes.HexBytes, timeout: float | None = None, start_latency: float = 0.01, backoff_multiplier: float = 2, validate_transaction: bool = False) web3.types.TxReceipt
Retrieve the transaction receipt asynchronously, retrying with exponential backoff.
This function is copied from web3.eth.wait_for_transaction_receipt, but using exponential backoff and async await. This function also takes the place of sign_transact_and_wait, except it uses async await. This is due to agent0 using the sync version of web3py, but we wrap things in async calls.
- Parameters:
contract_function (PypechainContractFunction) – The contract function that was called.
transaction_hash (HexBytes) – The hash of the transaction.
timeout (float | None, optional) – The amount of time in seconds to time out the connection. Default is 30.
start_latency (float) – The starting amount of time in seconds to wait between polls.
backoff_multiplier (float) – The backoff factor for the exponential backoff.
validate_transaction (bool, optional) – Whether to validate the transaction. If True, will throw an exception if the resulting tx_receipt returned a failure status.
- Returns:
The transaction receipt
- Return type:
TxReceipt
- agent0.ethpy.base.initialize_web3_with_http_provider(ethereum_node: eth_typing.URI | str, request_kwargs: dict | None = None, reset_provider: bool = False) web3.Web3
Initialize a Web3 instance using an HTTP provider and inject a geth Proof of Authority (poa) middleware.
Note
The geth_poa_middleware is required to connect to geth –dev or the Goerli public network. It may also be needed for other EVM compatible blockchains like Polygon or BNB Chain (Binance Smart Chain). See more here.
- Parameters:
ethereum_node (URI | str) – Address of the http provider
request_kwargs (dict | None, optional) – The HTTPProvider uses the python requests library for making requests. If you would like to modify how requests are made, you can use the request_kwargs to do so.
reset_provider (bool, optional) – If true, will call anvil_reset before returning the Web3 instance.
- Returns:
The connected web3 instance
- Return type:
Web3
- agent0.ethpy.base.ETH_CONTRACT_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
- agent0.ethpy.base.EARLIEST_BLOCK_LOOKUP