dank_mids.brownie_patch package

Submodules

dank_mids.brownie_patch.call module

dank_mids.brownie_patch.call.decode(self, data)

A lambda function that decodes output data for contract calls. It uses the BROWNIE_DECODER_PROCESSES to run the __decode_input function asynchronously.

Parameters:
  • self – The contract method instance.

  • *args – The arguments to be encoded.

async dank_mids.brownie_patch.call.decode_output(call, data)
Parameters:
Return type:

Any

dank_mids.brownie_patch.call.encode(self, *args)

A lambda function that encodes input data for contract calls. It uses the BROWNIE_ENCODER_PROCESSES to run the __encode_input function asynchronously.

Parameters:
  • self – The contract method instance.

  • *args – The arguments to be encoded.

async dank_mids.brownie_patch.call.encode_input(call, len_inputs, get_request_data, *args)
Parameters:

call (ContractCall)

Return type:

HexStr

dank_mids.brownie_patch.call.format_input_but_cache_checksums(abi, inputs)
Parameters:
Return type:

List

dank_mids.brownie_patch.call.format_output_but_cache_checksums(abi, outputs)
Parameters:
Return type:

ReturnValue

dank_mids.brownie_patch.contract module

class dank_mids.brownie_patch.contract.Contract

Bases: Contract

An extended version of brownie.Contract with additional functionality for Dank Mids.

This class provides lazy initialization of contract methods and supports asynchronous operations through Dank Mids middleware.

__init__(*args, **kwargs)

Initialize the Contract instance.

This method sets up lazy initialization for contract methods.

balance()

Returns the current ether balance of the contract, in wei.

Return type:

Wei

decode_input(calldata)

Decode input calldata for this contract.

Parameters:

calldata (str | bytes) – Calldata for a call to this contract

Returns:

  • str – Signature of the function that was called

  • Any – Decoded input arguments

Return type:

Tuple[str, Any]

classmethod from_abi(name, address, abi, owner=None, persist=True)

Create a new Contract instance from an ABI.

This method allows for the creation of a Contract instance using a provided ABI, which is useful when working with contracts that are not in the project’s build files and not verified on a block explorer.

Parameters:
  • name (str) – The name of the contract.

  • address (str) – The address of the deployed contract.

  • abi (List[dict]) – The ABI (Application Binary Interface) of the contract.

  • owner (AccountsType | None) – The account that owns this contract instance.

  • persist (bool) – Whether to persist the contract data to brownie’s local db for future use.

Returns:

A new Contract instance.

Return type:

Contract

classmethod from_ethpm(name, manifest_uri, address=None, owner=None, persist=True)

Create a new Contract instance from an ethPM manifest.

This method allows for the creation of a Contract instance using an ethPM manifest, which is a standardized format for Ethereum smart contract packages.

Parameters:
  • name (str) – The name of the contract.

  • manifest_uri (str) – The URI of the ethPM manifest.

  • address (str | None) – The address of the deployed contract (optional).

  • owner (AccountsType | None) – The account that owns this contract instance.

  • persist (bool) – Whether to persist the contract data to brownie’s local db for future use.

Returns:

A new Contract instance.

Return type:

Contract

classmethod from_explorer(address, as_proxy_for=None, owner=None, silent=False, persist=True)

Create a new Contract instance by fetching the ABI from a block explorer.

This method is useful for interacting with contracts that are not part of the current project, as it automatically fetches the contract’s ABI from a block explorer.

Parameters:
  • address (str) – The address of the deployed contract.

  • as_proxy_for (str | None) – The address of the implementation contract if this is a proxy contract.

  • owner (AccountsType | None) – The account that owns this contract instance.

  • silent (bool) – Whether to suppress console output during the process.

  • persist (bool) – Whether to persist the contract data to brownie’s db for future use.

Returns:

A new Contract instance.

Return type:

Contract

get_method(calldata)
Parameters:

calldata (str)

Return type:

str | None

get_method_object(calldata)

Given a calldata hex string, returns a ContractMethod object.

Parameters:

calldata (str)

Return type:

_ContractMethod | None

classmethod get_solc_version(compiler_str, address)

Return the solc compiler version either from the passed compiler string or try to find the latest available patch semver compiler version.

Parameters:
  • compiler_str (str) – The compiler string passed from the contract metadata.

  • address (str) – The contract address to check for.

Return type:

Version

info()

Display NatSpec documentation for this contract.

Return type:

None

classmethod remove_deployment(address=None, alias=None)

Removes this contract from the internal deployments db with the passed address or alias.

Parameters:
  • address (str | None) – An address to apply

  • alias (str | None) – An alias to apply

Return type:

Tuple[Dict | None, Dict | None]

set_alias(alias, persist=True)

Apply a unique alias this object. The alias can be used to restore the object in future sessions.

Parameters:
  • alias (str | None) – An alias to apply. If None, any existing alias is removed.

  • persist (bool)

Return type:

None

property abi: List
property alias: str | None
signatures: Dict[Method, Signature]

A dictionary mapping method names to their corresponding signatures.

topics: Dict[str, str]

A dictionary mapping event names to their corresponding topics.

class dank_mids.brownie_patch.contract.EventName

A type representing the name of an event in a smart contract.

See also

brownie.network.contract.ContractEvents: Brownie’s implementation of contract events.

alias of str

class dank_mids.brownie_patch.contract.LogTopic

A type representing a log topic in Ethereum transactions.

See also

Web3.eth.get_logs(): Web3.py method for retrieving logs.

alias of str

class dank_mids.brownie_patch.contract.Method

A type representing the name of a method in a smart contract.

See also

brownie.network.contract.ContractMethod: Brownie’s implementation of contract methods.

alias of str

class dank_mids.brownie_patch.contract.Signature

A type representing the signature of a method in a smart contract.

alias of str

dank_mids.brownie_patch.contract.patch_contract(contract: Contract, w3: DankWeb3 | None = None) Contract
dank_mids.brownie_patch.contract.patch_contract(contract: Contract | str, w3: DankWeb3 | None = None) Contract

Patch a contract with async and call batching functionalities.

Parameters:
  • contract – The contract to patch.

  • w3 – Optional DankWeb3 instance.

Returns:

The patched contract.

dank_mids.brownie_patch.overloaded module

dank_mids.brownie_patch.types module

class dank_mids.brownie_patch.types.DankContractCall

Bases: _DankMethod, ContractCall

A subclass of brownie.network.contract.ContractCall with async support via the coroutine method.

This class uses less memory than a typical ContractTx by employing the __slots__ functionality alongside the FunctionABI singleton to manage the function ABI and related logic.

You can await an instance of this class directly to call the contract method without arguments at the latest block.

__call__(**kwargs)

Call the contract method without broadcasting a transaction.

Parameters:
  • args (Tuple) – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • block_identifier (int | str | bytes, optional) – A block number or hash that the call is executed at. If not given, the latest block used. Raises ValueError if this value is too far in the past and you are not using an archival node.

  • override (dict, optional) – A mapping from addresses to balance, nonce, code, state, stateDiff overrides for the context of the call.

Return type:

Contract method return value(s).

__init__(address, abi, name, owner, natspec=None)
Parameters:
  • address (str)

  • abi (Dict)

  • name (str)

  • owner (AccountsType | None)

  • natspec (Dict | None)

Return type:

None

call(*args, block_identifier=None, override=None)

Call the contract method without broadcasting a transaction.

Parameters:
  • *args – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • block_identifier (int | str | bytes, optional) – A block number or hash that the call is executed at. If not given, the latest block used. Raises ValueError if this value is too far in the past and you are not using an archival node.

  • override (dict, optional) – A mapping from addresses to balance, nonce, code, state, stateDiff overrides for the context of the call.

Return type:

Contract method return value(s).

async coroutine(*args, block_identifier=None, decimals=None, override=None)

Asynchronously call the contract method via dank mids and await the result.

Parameters:
  • *args (Any) – The arguments for the contract method.

  • block_identifier (int | None) – The block at which the chain will be read. If not provided, will read the chain at latest block.

  • decimals (int | None) – If provided, the output will be result / 10 ** decimals.

  • override (Dict[str, str] | None)

Raises:

ValueError – If the override parameter is used, as state overrides are not supported.

Returns:

The result of the contract method call.

Return type:

_EVMType

decode_input(hexstr)

Decode input call data for this method.

Parameters:

hexstr (str) – Hexstring of input call data

Return type:

Decoded values

decode_output(hexstr)

Decode hexstring data returned by this method.

Parameters:

hexstr (str) – Hexstring of returned call data

Return type:

Decoded values

encode_input(*args)

Generate encoded ABI data to call the method with the given arguments.

Parameters:

*args (Tuple) – Contract method inputs

Returns:

Hexstring of encoded ABI data

Return type:

str

estimate_gas(*args)

Estimate the gas cost for a transaction.

Raises VirtualMachineError if the transaction would revert.

Parameters:

*args (Tuple) – Contract method inputs

Returns:

Estimated gas value in wei.

Return type:

int

info()

Display NatSpec documentation for this method.

Return type:

None

async map(args, block_identifier=None, *, iter_args=False, decimals=None)

Asynchronously call the contract method with multiple sets of arguments.

This method allows for efficient batch calling of the contract method with different arguments.

Parameters:
  • args (Iterable[Any]) – An iterable of argument sets to be passed to the method.

  • block_identifier (int | None) – The block number or identifier for the calls.

  • iter_args (bool) – True if you are passing an Iterable of Iterables, False otherwise.

  • decimals (int | None) – The number of decimal places by which to scale numeric results.

Return type:

List[_EVMType]

transact(*args, silent=False)

Broadcast a transaction that calls this contract method.

Parameters:
  • *args (Tuple) – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • silent (bool)

Returns:

Object representing the broadcasted transaction.

Return type:

TransactionReceipt

property abi: dict

The ABI of the contract function.

This property provides access to the complete ABI dictionary of the function.

natspec

The NatSpec documentation for the function.

property payable: bool
property signature: str

The function signature.

This property returns the unique signature of the contract function, which is used to identify the function in transactions.

class dank_mids.brownie_patch.types.DankContractTx

Bases: _DankMethod, ContractTx

A subclass of brownie.network.contract.ContractTx with async support via the coroutine method.

This class is optimized for memory use compared to a standard ContractTx, by using __slots__ in combination with the FunctionABI singleton to handle the function ABI and associated logic.

Awaiting an instance of this class directly executes the contract method without arguments at the latest block.

__call__(*args, silent=False)

Broadcast a transaction that calls this contract method.

Parameters:
  • *args (Tuple) – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • silent (bool)

Returns:

Object representing the broadcasted transaction.

Return type:

TransactionReceipt

__init__(address, abi, name, owner, natspec=None)
Parameters:
  • address (str)

  • abi (Dict)

  • name (str)

  • owner (AccountsType | None)

  • natspec (Dict | None)

Return type:

None

call(*args, block_identifier=None, override=None)

Call the contract method without broadcasting a transaction.

Parameters:
  • *args – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • block_identifier (int | str | bytes, optional) – A block number or hash that the call is executed at. If not given, the latest block used. Raises ValueError if this value is too far in the past and you are not using an archival node.

  • override (dict, optional) – A mapping from addresses to balance, nonce, code, state, stateDiff overrides for the context of the call.

Return type:

Contract method return value(s).

async coroutine(*args, block_identifier=None, decimals=None, override=None)

Asynchronously call the contract method via dank mids and await the result.

Parameters:
  • *args (Any) – The arguments for the contract method.

  • block_identifier (int | None) – The block at which the chain will be read. If not provided, will read the chain at latest block.

  • decimals (int | None) – If provided, the output will be result / 10 ** decimals.

  • override (Dict[str, str] | None)

Raises:

ValueError – If the override parameter is used, as state overrides are not supported.

Returns:

The result of the contract method call.

Return type:

_EVMType

decode_input(hexstr)

Decode input call data for this method.

Parameters:

hexstr (str) – Hexstring of input call data

Return type:

Decoded values

decode_output(hexstr)

Decode hexstring data returned by this method.

Parameters:

hexstr (str) – Hexstring of returned call data

Return type:

Decoded values

encode_input(*args)

Generate encoded ABI data to call the method with the given arguments.

Parameters:

*args (Tuple) – Contract method inputs

Returns:

Hexstring of encoded ABI data

Return type:

str

estimate_gas(*args)

Estimate the gas cost for a transaction.

Raises VirtualMachineError if the transaction would revert.

Parameters:

*args (Tuple) – Contract method inputs

Returns:

Estimated gas value in wei.

Return type:

int

info()

Display NatSpec documentation for this method.

Return type:

None

async map(args, block_identifier=None, *, iter_args=False, decimals=None)

Asynchronously call the contract method with multiple sets of arguments.

This method allows for efficient batch calling of the contract method with different arguments.

Parameters:
  • args (Iterable[Any]) – An iterable of argument sets to be passed to the method.

  • block_identifier (int | None) – The block number or identifier for the calls.

  • iter_args (bool) – True if you are passing an Iterable of Iterables, False otherwise.

  • decimals (int | None) – The number of decimal places by which to scale numeric results.

Return type:

List[_EVMType]

transact(*args, silent=False)

Broadcast a transaction that calls this contract method.

Parameters:
  • *args (Tuple) – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • silent (bool)

Returns:

Object representing the broadcasted transaction.

Return type:

TransactionReceipt

property abi: dict

The ABI of the contract function.

This property provides access to the complete ABI dictionary of the function.

natspec

The NatSpec documentation for the function.

property payable: bool
property signature: str

The function signature.

This property returns the unique signature of the contract function, which is used to identify the function in transactions.

class dank_mids.brownie_patch.types.DankOverloadedMethod

Bases: OverloadedMethod, _DankMethodMixin

A subclass of brownie.network.contract.OverloadedMethod with async support via the coroutine method.

This class is designed to be memory efficient compared to a typical OverloadedMethod, employing __slots__ and the FunctionABI singleton to manage the function ABI and related logic.

You can await instances of this class directly to call the contract method without arguments at the latest block.

__call__(*args, block_identifier=None, override=None)

Call self as a function.

Parameters:
Return type:

Any

__getitem__(key)
Parameters:

key (Tuple | str)

Return type:

_ContractMethod

__init__(address, name, owner)
Parameters:
  • address (str)

  • name (str)

  • owner (AccountsType | None)

call(*args, block_identifier=None, override=None)

Call the contract method without broadcasting a transaction.

The specific function called is chosen based on the number of arguments given. If more than one function exists with this number of arguments, a ValueError is raised.

Parameters:
  • *args – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • block_identifier (int | str | bytes, optional) – A block number or hash that the call is executed at. If not given, the latest block used. Raises ValueError if this value is too far in the past and you are not using an archival node.

  • override (dict, optional) – A mapping from addresses to balance, nonce, code, state, stateDiff overrides for the context of the call.

Return type:

Contract method return value(s).

async coroutine(*args, block_identifier=None, decimals=None, override=None)

Asynchronously call the contract method using dank mids and await the result.

Parameters:
  • *args – The arguments for the contract method.

  • block_identifier (optional) – Specifies the block at which the chain will be read. Defaults to the latest block if not provided.

  • decimals (optional) – If specified, the output will be result / 10 ** decimals.

  • override (Dict[str, str] | None)

Returns:

Whatever the node sends back as the output for this contract method.

Return type:

_EVMType

decode_input(hexstr)

Decode input call data for this method.

Parameters:

hexstr (str) – Hexstring of input call data

Return type:

Decoded values

decode_output(hexstr)

Decode hexstring data returned by this method.

Parameters:

hexstr (str) – Hexstring of returned call data

Return type:

Decoded values

encode_input(*args)

Generate encoded ABI data to call the method with the given arguments.

Parameters:

*args (Tuple) – Contract method inputs

Returns:

Hexstring of encoded ABI data

Return type:

str

info()

Display NatSpec documentation for this method.

Return type:

None

async map(args, block_identifier=None, *, iter_args=False, decimals=None)

Asynchronously call the contract method with multiple sets of arguments.

This method allows for efficient batch calling of the contract method with different arguments.

Parameters:
  • args (Iterable[Any]) – An iterable of argument sets to be passed to the method.

  • block_identifier (int | None) – The block number or identifier for the calls.

  • iter_args (bool) – True if you are passing an Iterable of Iterables, False otherwise.

  • decimals (int | None) – The number of decimal places by which to scale numeric results.

Return type:

List[_EVMType]

transact(*args)

Broadcast a transaction that calls this contract method.

The specific function called is chosen based on the number of arguments given. If more than one function exists with this number of arguments, a ValueError is raised.

Parameters:

*args (Tuple) – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

Returns:

Object representing the broadcasted transaction.

Return type:

TransactionReceipt

property abi: dict

The ABI of the contract function.

This property provides access to the complete ABI dictionary of the function.

methods: Dict[Tuple[str, ...], DankContractCall | DankContractTx]
natspec: Dict
property signature: str

The function signature.

This property returns the unique signature of the contract function, which is used to identify the function in transactions.

dank_mids.brownie_patch.types.ContractMethod

Type alias for Brownie contract methods.

alias of ContractCall | ContractTx | OverloadedMethod

dank_mids.brownie_patch.types.DankContractMethod

Alias for ContractMethod objects with async support via an additional coroutine method.

These objects consume less memory than standard ContractMethod objects by utilizing the FunctionABI singleton to handle the function ABI and associated logic.

Instances of this class can be awaited directly to call the contract method without arguments at the latest block.

alias of DankContractCall | DankContractTx | DankOverloadedMethod

Module contents

class dank_mids.brownie_patch.Contract

Bases: Contract

An extended version of brownie.Contract with additional functionality for Dank Mids.

This class provides lazy initialization of contract methods and supports asynchronous operations through Dank Mids middleware.

__init__(*args, **kwargs)

Initialize the Contract instance.

This method sets up lazy initialization for contract methods.

balance()

Returns the current ether balance of the contract, in wei.

Return type:

Wei

decode_input(calldata)

Decode input calldata for this contract.

Parameters:

calldata (str | bytes) – Calldata for a call to this contract

Returns:

  • str – Signature of the function that was called

  • Any – Decoded input arguments

Return type:

Tuple[str, Any]

classmethod from_abi(name, address, abi, owner=None, persist=True)

Create a new Contract instance from an ABI.

This method allows for the creation of a Contract instance using a provided ABI, which is useful when working with contracts that are not in the project’s build files and not verified on a block explorer.

Parameters:
  • name (str) – The name of the contract.

  • address (str) – The address of the deployed contract.

  • abi (List[dict]) – The ABI (Application Binary Interface) of the contract.

  • owner (AccountsType | None) – The account that owns this contract instance.

  • persist (bool) – Whether to persist the contract data to brownie’s local db for future use.

Returns:

A new Contract instance.

Return type:

Contract

classmethod from_ethpm(name, manifest_uri, address=None, owner=None, persist=True)

Create a new Contract instance from an ethPM manifest.

This method allows for the creation of a Contract instance using an ethPM manifest, which is a standardized format for Ethereum smart contract packages.

Parameters:
  • name (str) – The name of the contract.

  • manifest_uri (str) – The URI of the ethPM manifest.

  • address (str | None) – The address of the deployed contract (optional).

  • owner (AccountsType | None) – The account that owns this contract instance.

  • persist (bool) – Whether to persist the contract data to brownie’s local db for future use.

Returns:

A new Contract instance.

Return type:

Contract

classmethod from_explorer(address, as_proxy_for=None, owner=None, silent=False, persist=True)

Create a new Contract instance by fetching the ABI from a block explorer.

This method is useful for interacting with contracts that are not part of the current project, as it automatically fetches the contract’s ABI from a block explorer.

Parameters:
  • address (str) – The address of the deployed contract.

  • as_proxy_for (str | None) – The address of the implementation contract if this is a proxy contract.

  • owner (AccountsType | None) – The account that owns this contract instance.

  • silent (bool) – Whether to suppress console output during the process.

  • persist (bool) – Whether to persist the contract data to brownie’s db for future use.

Returns:

A new Contract instance.

Return type:

Contract

get_method(calldata)
Parameters:

calldata (str)

Return type:

str | None

get_method_object(calldata)

Given a calldata hex string, returns a ContractMethod object.

Parameters:

calldata (str)

Return type:

_ContractMethod | None

classmethod get_solc_version(compiler_str, address)

Return the solc compiler version either from the passed compiler string or try to find the latest available patch semver compiler version.

Parameters:
  • compiler_str (str) – The compiler string passed from the contract metadata.

  • address (str) – The contract address to check for.

Return type:

Version

info()

Display NatSpec documentation for this contract.

Return type:

None

classmethod remove_deployment(address=None, alias=None)

Removes this contract from the internal deployments db with the passed address or alias.

Parameters:
  • address (str | None) – An address to apply

  • alias (str | None) – An alias to apply

Return type:

Tuple[Dict | None, Dict | None]

set_alias(alias, persist=True)

Apply a unique alias this object. The alias can be used to restore the object in future sessions.

Parameters:
  • alias (str | None) – An alias to apply. If None, any existing alias is removed.

  • persist (bool)

Return type:

None

property abi: List
property alias: str | None
signatures: Dict[Method, Signature]

A dictionary mapping method names to their corresponding signatures.

topics: Dict[str, str]

A dictionary mapping event names to their corresponding topics.

class dank_mids.brownie_patch.DankContractCall

Bases: _DankMethod, ContractCall

A subclass of brownie.network.contract.ContractCall with async support via the coroutine method.

This class uses less memory than a typical ContractTx by employing the __slots__ functionality alongside the FunctionABI singleton to manage the function ABI and related logic.

You can await an instance of this class directly to call the contract method without arguments at the latest block.

__call__(**kwargs)

Call the contract method without broadcasting a transaction.

Parameters:
  • args (Tuple) – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • block_identifier (int | str | bytes, optional) – A block number or hash that the call is executed at. If not given, the latest block used. Raises ValueError if this value is too far in the past and you are not using an archival node.

  • override (dict, optional) – A mapping from addresses to balance, nonce, code, state, stateDiff overrides for the context of the call.

Return type:

Contract method return value(s).

__init__(address, abi, name, owner, natspec=None)
Parameters:
  • address (str)

  • abi (Dict)

  • name (str)

  • owner (AccountsType | None)

  • natspec (Dict | None)

Return type:

None

call(*args, block_identifier=None, override=None)

Call the contract method without broadcasting a transaction.

Parameters:
  • *args – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • block_identifier (int | str | bytes, optional) – A block number or hash that the call is executed at. If not given, the latest block used. Raises ValueError if this value is too far in the past and you are not using an archival node.

  • override (dict, optional) – A mapping from addresses to balance, nonce, code, state, stateDiff overrides for the context of the call.

Return type:

Contract method return value(s).

async coroutine(*args, block_identifier=None, decimals=None, override=None)

Asynchronously call the contract method via dank mids and await the result.

Parameters:
  • *args (Any) – The arguments for the contract method.

  • block_identifier (int | None) – The block at which the chain will be read. If not provided, will read the chain at latest block.

  • decimals (int | None) – If provided, the output will be result / 10 ** decimals.

  • override (Dict[str, str] | None)

Raises:

ValueError – If the override parameter is used, as state overrides are not supported.

Returns:

The result of the contract method call.

Return type:

_EVMType

decode_input(hexstr)

Decode input call data for this method.

Parameters:

hexstr (str) – Hexstring of input call data

Return type:

Decoded values

decode_output(hexstr)

Decode hexstring data returned by this method.

Parameters:

hexstr (str) – Hexstring of returned call data

Return type:

Decoded values

encode_input(*args)

Generate encoded ABI data to call the method with the given arguments.

Parameters:

*args (Tuple) – Contract method inputs

Returns:

Hexstring of encoded ABI data

Return type:

str

estimate_gas(*args)

Estimate the gas cost for a transaction.

Raises VirtualMachineError if the transaction would revert.

Parameters:

*args (Tuple) – Contract method inputs

Returns:

Estimated gas value in wei.

Return type:

int

info()

Display NatSpec documentation for this method.

Return type:

None

async map(args, block_identifier=None, *, iter_args=False, decimals=None)

Asynchronously call the contract method with multiple sets of arguments.

This method allows for efficient batch calling of the contract method with different arguments.

Parameters:
  • args (Iterable[Any]) – An iterable of argument sets to be passed to the method.

  • block_identifier (int | None) – The block number or identifier for the calls.

  • iter_args (bool) – True if you are passing an Iterable of Iterables, False otherwise.

  • decimals (int | None) – The number of decimal places by which to scale numeric results.

Return type:

List[_EVMType]

transact(*args, silent=False)

Broadcast a transaction that calls this contract method.

Parameters:
  • *args (Tuple) – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • silent (bool)

Returns:

Object representing the broadcasted transaction.

Return type:

TransactionReceipt

property abi: dict

The ABI of the contract function.

This property provides access to the complete ABI dictionary of the function.

natspec

The NatSpec documentation for the function.

property payable: bool
property signature: str

The function signature.

This property returns the unique signature of the contract function, which is used to identify the function in transactions.

class dank_mids.brownie_patch.DankContractTx

Bases: _DankMethod, ContractTx

A subclass of brownie.network.contract.ContractTx with async support via the coroutine method.

This class is optimized for memory use compared to a standard ContractTx, by using __slots__ in combination with the FunctionABI singleton to handle the function ABI and associated logic.

Awaiting an instance of this class directly executes the contract method without arguments at the latest block.

__call__(*args, silent=False)

Broadcast a transaction that calls this contract method.

Parameters:
  • *args (Tuple) – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • silent (bool)

Returns:

Object representing the broadcasted transaction.

Return type:

TransactionReceipt

__init__(address, abi, name, owner, natspec=None)
Parameters:
  • address (str)

  • abi (Dict)

  • name (str)

  • owner (AccountsType | None)

  • natspec (Dict | None)

Return type:

None

call(*args, block_identifier=None, override=None)

Call the contract method without broadcasting a transaction.

Parameters:
  • *args – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • block_identifier (int | str | bytes, optional) – A block number or hash that the call is executed at. If not given, the latest block used. Raises ValueError if this value is too far in the past and you are not using an archival node.

  • override (dict, optional) – A mapping from addresses to balance, nonce, code, state, stateDiff overrides for the context of the call.

Return type:

Contract method return value(s).

async coroutine(*args, block_identifier=None, decimals=None, override=None)

Asynchronously call the contract method via dank mids and await the result.

Parameters:
  • *args (Any) – The arguments for the contract method.

  • block_identifier (int | None) – The block at which the chain will be read. If not provided, will read the chain at latest block.

  • decimals (int | None) – If provided, the output will be result / 10 ** decimals.

  • override (Dict[str, str] | None)

Raises:

ValueError – If the override parameter is used, as state overrides are not supported.

Returns:

The result of the contract method call.

Return type:

_EVMType

decode_input(hexstr)

Decode input call data for this method.

Parameters:

hexstr (str) – Hexstring of input call data

Return type:

Decoded values

decode_output(hexstr)

Decode hexstring data returned by this method.

Parameters:

hexstr (str) – Hexstring of returned call data

Return type:

Decoded values

encode_input(*args)

Generate encoded ABI data to call the method with the given arguments.

Parameters:

*args (Tuple) – Contract method inputs

Returns:

Hexstring of encoded ABI data

Return type:

str

estimate_gas(*args)

Estimate the gas cost for a transaction.

Raises VirtualMachineError if the transaction would revert.

Parameters:

*args (Tuple) – Contract method inputs

Returns:

Estimated gas value in wei.

Return type:

int

info()

Display NatSpec documentation for this method.

Return type:

None

async map(args, block_identifier=None, *, iter_args=False, decimals=None)

Asynchronously call the contract method with multiple sets of arguments.

This method allows for efficient batch calling of the contract method with different arguments.

Parameters:
  • args (Iterable[Any]) – An iterable of argument sets to be passed to the method.

  • block_identifier (int | None) – The block number or identifier for the calls.

  • iter_args (bool) – True if you are passing an Iterable of Iterables, False otherwise.

  • decimals (int | None) – The number of decimal places by which to scale numeric results.

Return type:

List[_EVMType]

transact(*args, silent=False)

Broadcast a transaction that calls this contract method.

Parameters:
  • *args (Tuple) – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • silent (bool)

Returns:

Object representing the broadcasted transaction.

Return type:

TransactionReceipt

property abi: dict

The ABI of the contract function.

This property provides access to the complete ABI dictionary of the function.

natspec

The NatSpec documentation for the function.

property payable: bool
property signature: str

The function signature.

This property returns the unique signature of the contract function, which is used to identify the function in transactions.

class dank_mids.brownie_patch.DankOverloadedMethod

Bases: OverloadedMethod, _DankMethodMixin

A subclass of brownie.network.contract.OverloadedMethod with async support via the coroutine method.

This class is designed to be memory efficient compared to a typical OverloadedMethod, employing __slots__ and the FunctionABI singleton to manage the function ABI and related logic.

You can await instances of this class directly to call the contract method without arguments at the latest block.

__call__(*args, block_identifier=None, override=None)

Call self as a function.

Parameters:
Return type:

Any

__getitem__(key)
Parameters:

key (Tuple | str)

Return type:

_ContractMethod

__init__(address, name, owner)
Parameters:
  • address (str)

  • name (str)

  • owner (AccountsType | None)

call(*args, block_identifier=None, override=None)

Call the contract method without broadcasting a transaction.

The specific function called is chosen based on the number of arguments given. If more than one function exists with this number of arguments, a ValueError is raised.

Parameters:
  • *args – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

  • block_identifier (int | str | bytes, optional) – A block number or hash that the call is executed at. If not given, the latest block used. Raises ValueError if this value is too far in the past and you are not using an archival node.

  • override (dict, optional) – A mapping from addresses to balance, nonce, code, state, stateDiff overrides for the context of the call.

Return type:

Contract method return value(s).

async coroutine(*args, block_identifier=None, decimals=None, override=None)

Asynchronously call the contract method using dank mids and await the result.

Parameters:
  • *args – The arguments for the contract method.

  • block_identifier (optional) – Specifies the block at which the chain will be read. Defaults to the latest block if not provided.

  • decimals (optional) – If specified, the output will be result / 10 ** decimals.

  • override (Dict[str, str] | None)

Returns:

Whatever the node sends back as the output for this contract method.

Return type:

_EVMType

decode_input(hexstr)

Decode input call data for this method.

Parameters:

hexstr (str) – Hexstring of input call data

Return type:

Decoded values

decode_output(hexstr)

Decode hexstring data returned by this method.

Parameters:

hexstr (str) – Hexstring of returned call data

Return type:

Decoded values

encode_input(*args)

Generate encoded ABI data to call the method with the given arguments.

Parameters:

*args (Tuple) – Contract method inputs

Returns:

Hexstring of encoded ABI data

Return type:

str

info()

Display NatSpec documentation for this method.

Return type:

None

async map(args, block_identifier=None, *, iter_args=False, decimals=None)

Asynchronously call the contract method with multiple sets of arguments.

This method allows for efficient batch calling of the contract method with different arguments.

Parameters:
  • args (Iterable[Any]) – An iterable of argument sets to be passed to the method.

  • block_identifier (int | None) – The block number or identifier for the calls.

  • iter_args (bool) – True if you are passing an Iterable of Iterables, False otherwise.

  • decimals (int | None) – The number of decimal places by which to scale numeric results.

Return type:

List[_EVMType]

transact(*args)

Broadcast a transaction that calls this contract method.

The specific function called is chosen based on the number of arguments given. If more than one function exists with this number of arguments, a ValueError is raised.

Parameters:

*args (Tuple) – Contract method inputs. You can optionally provide a dictionary of transaction properties as the last arg.

Returns:

Object representing the broadcasted transaction.

Return type:

TransactionReceipt

property abi: dict

The ABI of the contract function.

This property provides access to the complete ABI dictionary of the function.

methods: Dict[Tuple[str, ...], DankContractCall | DankContractTx]
natspec: Dict
property signature: str

The function signature.

This property returns the unique signature of the contract function, which is used to identify the function in transactions.

dank_mids.brownie_patch.patch_contract(contract, w3=None)

Patch a contract with async and call batching functionalities.

Parameters:
  • contract (Contract | Contract | str) – The contract to patch.

  • w3 (DankWeb3 | None) – Optional DankWeb3 instance.

Returns:

The patched contract.

Return type:

Contract | Contract

dank_mids.brownie_patch.dank_eth: DankEth = <dank_mids.eth.DankEth object>

An instance of DankEth, providing access to Ethereum blockchain methods via dank_web3. This is initialized if Brownie is installed and connected when this module is loaded. If Brownie is not installed or not connected to an RPC, this instance will not be available.

dank_mids.brownie_patch.dank_web3: DankWeb3 = <web3.main.AsyncWeb3 object>

An instance of DankWeb3, which is a wrapper around brownie’s standard Web3 object with Dank Middleware injected. This is initialized if Brownie is installed and connected when this module is loaded. If Brownie is not installed or not connected to an RPC, this instance will not be available.