ape.api

Submodules

Package Contents

Classes:

AccountAPI

AccountContainerAPI

Address

AddressAPI

ContractInstance

ContractLog

ConverterAPI

Abstract base class for generic types.

ExplorerAPI

An Explorer must work with a particular Network in a particular Ecosystem

EcosystemAPI

An Ecosystem is a set of related Networks

NetworkAPI

A Network is a wrapper around a Provider for a specific Ecosystem.

ProviderContextManager

ProviderAPI

A Provider must work with a particular Network in a particular Ecosystem

ReceiptAPI

TransactionAPI

TransactionStatusEnum

Enum where members are also (and must be) ints

Functions:

create_network_type(chain_id: int, network_id: int) → Type[NetworkAPI]

Helper function that allows creating a NetworkAPI subclass easily.


class ape.api.AccountAPI

Bases: ape.api.address.AddressAPI

container :AccountContainerAPI
__dir__(self)List[str]

Default dir() implementation.

property alias(self)Optional[str]

Override with whatever alias might want to use, if applicable

abstract sign_message(self, msg: ape.types.SignableMessage)Optional[ape.types.MessageSignature]
abstract sign_transaction(self, txn: ape.api.providers.TransactionAPI)Optional[ape.types.TransactionSignature]
call(self, txn: ape.api.providers.TransactionAPI, send_everything: bool = False)ape.api.providers.ReceiptAPI
_convert(self)Callable
transfer(self, account: Union[str, ape.types.AddressType, ape.api.address.AddressAPI], value: Union[str, int, None] = None, data: Union[bytes, str, None] = None, **kwargs)ape.api.providers.ReceiptAPI
deploy(self, contract_type: ape.types.ContractType, *args, **kwargs)ape.api.contracts.ContractInstance
class ape.api.AccountContainerAPI
data_folder :pathlib.Path
account_type :Type[AccountAPI]
property aliases(self)Iterator[str]
abstract __len__(self)int
abstract __iter__(self)Iterator[AccountAPI]
__getitem__(self, address: ape.types.AddressType)AccountAPI
append(self, account: AccountAPI)
abstract __setitem__(self, address: ape.types.AddressType, account: AccountAPI)
remove(self, account: AccountAPI)
abstract __delitem__(self, address: ape.types.AddressType)
__contains__(self, address: ape.types.AddressType)bool
_verify_account_type(self, account)
_verify_unused_alias(self, account)
class ape.api.Address

Bases: AddressAPI

_address :ape.types.AddressType
property address(self)ape.types.AddressType
class ape.api.AddressAPI
_provider :Optional[ape.api.providers.ProviderAPI]
property provider(self)ape.api.providers.ProviderAPI
property _receipt_class(self)Type[ape.api.providers.ReceiptAPI]
property _transaction_class(self)Type[ape.api.providers.TransactionAPI]
property address(self)ape.types.AddressType
__dir__(self)List[str]

Default dir() implementation.

__repr__(self)str

Return repr(self).

__str__(self)str

Return str(self).

property nonce(self)int
property balance(self)int
property code(self)bytes
property codesize(self)int
property is_contract(self)bool
class ape.api.ContractInstance

Bases: ape.api.address.AddressAPI

_address :ape.types.AddressType
_contract_type :ape.types.ContractType
__repr__(self)str

Return repr(self).

property address(self)ape.types.AddressType
__dir__(self)List[str]

Default dir() implementation.

__getattr__(self, attr_name: str)Any
class ape.api.ContractLog
name :str
data :Dict[str, Any]
class ape.api.ConverterAPI

Bases: Generic[ConvertedType]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
config :ape.api.config.ConfigItem
networks :ape.managers.networks.NetworkManager
abstract is_convertible(self, value: Any)bool

Returns True if string value provided by value is convertible using self.convert(value)

abstract convert(self, value: Any)ConvertedType

Implements any conversion logic on value to produce ABIType.

Must throw if not convertible.

class ape.api.ExplorerAPI

An Explorer must work with a particular Network in a particular Ecosystem

name :str
network :ape.api.networks.NetworkAPI
request_header :str
abstract get_address_url(self, address: str)str
abstract get_transaction_url(self, transaction_hash: str)str
class ape.api.EcosystemAPI

An Ecosystem is a set of related Networks

name :str
network_manager :ape.managers.networks.NetworkManager
config_manager :ape.managers.config.ConfigManager
plugin_manager :pluggy.PluginManager
data_folder :pathlib.Path
request_header :str
transaction_class :Type[ape.api.providers.TransactionAPI]
receipt_class :Type[ape.api.providers.ReceiptAPI]
_default_network :str = development
config(self)ape.api.config.ConfigItem
networks(self)Dict[str, NetworkAPI]
__post_init__(self)
__iter__(self)Iterator[str]

Provides the set of all valid Network names in the ecosystem

__getitem__(self, network_name: str)NetworkAPI
__getattr__(self, network_name: str)NetworkAPI
add_network(self, network_name: str, network: NetworkAPI)

Used to attach new networks to an ecosystem (e.g. L2 networks like Optimism)

property default_network(self)str
set_default_network(self, network_name: str)
abstract encode_deployment(self, deployment_bytecode: bytes, abi: Optional[ape.types.ABI], *args, **kwargs)ape.api.providers.TransactionAPI
abstract encode_transaction(self, address: ape.types.AddressType, abi: ape.types.ABI, *args, **kwargs)ape.api.providers.TransactionAPI
abstract decode_event(self, abi: ape.types.ABI, receipt: ape.api.providers.ReceiptAPI)ape.api.contracts.ContractLog
_try_get_network(self, network_name)
get_network_data(self, network_name)Dict

Creates a dictionary of data about providers in the network.

Note: The keys are added in an opinionated order for nicely translating into yaml.

class ape.api.NetworkAPI

A Network is a wrapper around a Provider for a specific Ecosystem.

name :str
ecosystem :EcosystemAPI
config_manager :ape.managers.config.ConfigManager
plugin_manager :pluggy.PluginManager
data_folder :pathlib.Path
request_header :str
_default_provider :str =
config(self)ape.api.config.ConfigItem
property chain_id(self)int
property network_id(self)int
explorer(self)Optional[ape.api.explorers.ExplorerAPI]
providers(self)
use_provider(self, provider_name: str, provider_settings: dict = None)ProviderContextManager
property default_provider(self)str
set_default_provider(self, provider_name: str)
use_default_provider(self)ProviderContextManager
class ape.api.ProviderContextManager(network_manager: ape.managers.networks.NetworkManager, provider: ape.api.providers.ProviderAPI)
_connected_providers :List[ape.api.providers.ProviderAPI] = []
__init__(self, network_manager: ape.managers.networks.NetworkManager, provider: ape.api.providers.ProviderAPI)
__enter__(self, *args, **kwargs)
__exit__(self, *args, **kwargs)
ape.api.create_network_type(chain_id: int, network_id: int)Type[NetworkAPI]

Helper function that allows creating a NetworkAPI subclass easily.

class ape.api.ProviderAPI

A Provider must work with a particular Network in a particular Ecosystem

name :str
network :ape.api.networks.NetworkAPI
config :ape.api.config.ConfigItem
provider_settings :dict
data_folder :pathlib.Path
request_header :str
abstract connect(self)
abstract disconnect(self)
abstract update_settings(self, new_settings: dict)
property chain_id(self)int
abstract get_balance(self, address: str)int
abstract get_code(self, address: str)bytes
abstract get_nonce(self, address: str)int
abstract estimate_gas_cost(self, txn: TransactionAPI)int
property gas_price(self)int
abstract send_call(self, txn: TransactionAPI)bytes
abstract get_transaction(self, txn_hash: str)ReceiptAPI
abstract send_transaction(self, txn: TransactionAPI)ReceiptAPI
abstract get_events(self, **filter_params)Iterator[dict]
class ape.api.ReceiptAPI
txn_hash :str
status :TransactionStatusEnum
block_number :int
gas_used :int
gas_price :int
logs :List[dict] = []
contract_address :Optional[str]
__post_init__(self)
__str__(self)str

Return str(self).

abstract classmethod decode(cls, data: dict)ReceiptAPI
class ape.api.TransactionAPI
chain_id :int = 0
sender :str =
receiver :str =
nonce :Optional[int]
value :int = 0
gas_limit :Optional[int]
gas_price :Optional[int]
data :bytes = b''
signature :Optional[ape.types.TransactionSignature]
__post_init__(self)
property total_transfer_value(self)int

The total amount of WEI that a transaction could use. Useful for determining if an account balance can afford to submit the transaction.

property is_valid(self)
abstract encode(self)bytes

Take this object and produce a hash to sign to submit a transaction

as_dict(self)dict
__repr__(self)str

Return repr(self).

__str__(self)str

Return str(self).

class ape.api.TransactionStatusEnum

Bases: enum.IntEnum

Enum where members are also (and must be) ints

FAILING = 0
NO_ERROR = 1