verbs.abi.Function#

class Function[source]#

ABI function class

Class representing a contract function with functionality to encode and decode calls and results to/from this function.

Parameters:

abi (dict) – Parsed ABI JSON of the function.

inputs#

List of function input types.

Type:

list[str]

outputs#

List of function output types.

Type:

list[str]

selector#

ABI encoded function selector

Type:

bytes

Examples

f_abi = {
    "name": "foo",
    "inputs": [
        {"internalType": "int256", "name": "a", "type": "int256"}
    ],
    "outputs": [],
    "stateMutability": "view",
    "type": "function",
}

f = Function(f_abi)
encoded_args = f.encode([10])
result = f.call(
    env, sender_address, contract_address, args
)
__init__(abi: Dict)[source]#
call(env: EmptyEnvRandom | EmptyEnvGasPriority | ForkEnvRandom | ForkEnvGasPriority, sender: bytes, address: bytes, args: List[Any], value: int = 0) Tuple[Tuple[Any, ...], List, int][source]#

Directly call this function without committing any changes

Parameters:
  • env (verbs.types.Env) – Simulation environment.

  • sender (bytes) – Address of the caller.

  • address (bytes) – Address of the contract to call.

  • args (list) – List of function arguments.

  • value (int, optional) – Value of the transaction.

Returns:

  • results (tuple) – Tuple of values returned from the function call.

  • logs (list) – List of events/logs generated by this function call.

  • gas-used (int) – Gas used by this transaction.

decode(output: bytes) Tuple[Any, ...][source]#

Decode result(s) from this function

Parameters:

output (bytes) – Bytes returned from the EVM from a call to this function.

Returns:

tuple – Tuple of decoded return values from this function.

encode(args: List[Any]) bytes[source]#

ABI encode function arguments

Parameters:

args (list) – List of function arguments.

Returns:

bytes – ABI encoded args with function selector.

execute(env: EmptyEnvRandom | EmptyEnvGasPriority | ForkEnvRandom | ForkEnvGasPriority, sender: bytes, address: bytes, args: List[Any], value: int = 0) Tuple[Tuple[Any, ...], List, int][source]#

Directly call this function and commit any changes

Parameters:
  • env (verbs.types.Env) – Simulation environment.

  • sender (bytes) – Address of the caller.

  • address (bytes) – Address of the contract to call.

  • args (list) – List of function arguments.

  • value (int, optional) – Value of the transaction.

Returns:

  • results (tuple) – Tuple of values returned from the function call.

  • logs (list) – List of events/logs generated by this function call.

  • gas-used (int) – Gas used by this transaction.

transaction(sender: bytes, address: bytes, args: List[Any], checked: bool = True, gas_priority_fee: int | None = None, nonce: int | None = None, value: int | None = None) Tuple[bytes, bytes, bytes, bool, int | None, int | None, int | None][source]#

Create a transaction to submit to the current simulation block

Parameters:
  • sender (bytes) – Address of the call sender.

  • address (bytes) – Address of the contract to call.

  • args (list) – List of arguments to this function.

  • value (int, optional) – Value attached to the transaction, default 0.

  • checked (bool, optional) – If True the simulation will panic if the transaction from this call is reverted (default False).

  • gas_priority_fee (int, optional) – Transaction priority, default None is ignored

  • nonce (int, optional) – Transaction nonce, default None is ignored

  • value – Transaction value, default None is ignored

Returns:

verbs.types.Transaction – Transaction that can be submitted to the simulation for execution in the next block.