ape.contracts

class ape.contracts.base.ContractInstance(_address: ChecksumAddress, _converter: ConversionManager, _contract_type: ethpm_types.contract_type.ContractType, _provider: Optional[ape.api.providers.ProviderAPI] = None, **kwargs)

Bases: ape.api.address.AddressAPI

An interactive instance of a smart contract. After you deploy a contract using the deploy method, you get back a contract instance.

Usage example:

from ape import accounts, project

a = accounts.load("alias")  # Load an account by alias
contract = a.deploy(project.MyContract)  # The result of 'deploy()' is a ContractInstance
__dir__()List[str]

Display methods to IPython on c.[TAB] tab completion.

Returns

List[str]

__getattr__(attr_name: str)Any

Access a method or property on the contract using . access.

Usage example:

result = contract.vote()  # Implies a method named "vote" exists on the contract.
Parameters

attr_name (str) – The name of the method or property to access.

Returns

The return value from the contract call, or a transaction receipt.

Return type

any

property address

The address of the contract.

Returns

AddressType

class ape.contracts.base.ContractContainer(contract_type: ethpm_types.contract_type.ContractType, _provider: Optional[ape.api.providers.ProviderAPI], _converter: ConversionManager)

Bases: object

A wrapper around the contract type that has access to the provider. When you import your contracts from the ape.managers.project.ProjectManager, you are using this class.

Usage example:

from ape import project

contract_container = project.MyContract  # Assuming there is a contract named "MyContract"
at(address: str)ape.contracts.base.ContractInstance

Get a contract at the given address.

Usage example:

from ape import project

my_contract = project.MyContract.at("0xAbC1230001112223334445566611855443322111")
Parameters

address (str) – The address to initialize a contract. NOTE: Things will not work as expected if the contract is not actually deployed to this address or if the contract at the given address has a different ABI than contract_type.

Returns

ContractInstance

contract_type: ethpm_types.contract_type.ContractType

The type of the contract.