verbs.abi#

Generate ABI types from ABI JSON

Convert ABI JSON into python types with functionality for encoding/decoding function arguments and events and generating calls to submit to the simulation EVM.

The generated type has attributes representing the functions and events of the abi, along with a constructor attribute for use when deploying a contract.

Examples

abi_json = [
    {
        "name": "foo",
        "inputs": [
            {"internalType": "int256", "name": "a", "type": "int256"}
        ],
        "outputs": [],
        "stateMutability": "view",
        "type": "function",
    },
    {
        "name": "bar",
        "anonymous": False,
        "inputs": [
            {
                "indexed": False,
                "internalType": "int256",
                "name": "b",
                "type": "int256"
            }
         ],
         "type": "event"
    }
 ]

 Abi = get_abi("Foo", abi_json)

 # Encode arguments & selector to bytes
 encoded_args = Abi.foo.encode([10])
 # Decode bytes returned from a contract function call
 decoded_result = Abi.foo.decode(result_bytes)
 # Decode data attached to an event/log
 decoded_event = Abi.bar.decode(event_data)

Notes

Overloaded functions (i.e. those with the same name) are mapped to attributes with numbered suffixes according to their order in the ABI, e.g. if the ABI contained two functions named foo the resulting type will have foo0 and foo1 attributes.

Functions

abi_from_str

Create an ABI type from a JSON string

get_abi

Create an ABI type from ABI JSON

load_abi

Load an ABI type from an ABI file

parse_input_types

Parses function / event input types necessary for encoding

Classes

Constructor

ABI constructor class

Event

ABI event class

Function

ABI function class