Deployer Objects

Contract deployer

class solidbyte.deploy.objects.Contract(name: str, network_name: str, from_account: str, metafile: MetaFile, web3: Web3 = None)[source]

The representation of a smart contract deployment state on a specific network.

This object is exposed to users’ in their deploy script, instantiated for each of their contracts. The general use is to provide information about the contract state, a Web3 Contract instance and deploy it if necessary. There’s a bunch of properties, but two primary methods to interact with the contract.

  • check_needs_deployment(bytecode: str) -> bool: This function will take the provided bytecode
    and return whether or not there’s been a change compared to the known, deployed bytecode.
  • deployed(*args: T, **kwargs: T) -> web3.eth.Contract: This is the primary interaction a user
    has with this object in a deploy script. It will return an instantiated web3.eth.Contract instance and in the process, deploy the smart contract if necessary.
__init__(name: str, network_name: str, from_account: str, metafile: MetaFile, web3: Web3 = None)[source]

Initialize the Contract

Parameters:
  • name – The name of… me. The name of the contract I represent.
  • network_name – The name of of the network, as defined in networks.yml.
  • from_account – The address of the account to deploy with.
  • metafile – An instantiated MetaFile object.
  • web3 – An instantiated Web3 object
Example:
>>> from solidbyte.deploy.objects import Contract
>>> MyContract = Contract(
...         'TestContract',
...         'test',
...         '0xdeadbeef00000000000000000000000000000000',
...         MetaFile(),
...         Web3(),
... )
>>> my_contract = MyContract.deployed()
abi

The latest deployed ABI

address

The latest deployed address

bytecode_hash

The latest deployed bytecode hash

check_needs_deployment(bytecode: str) → bool[source]

Check if this contract has been changed since last deployment

NOTE: This method does not take into account dependencies. Check with Deployer

Parameters:bytecode – The hex bytecode to compare to the latest known deployment.
Returns:If the bytecode differs from the last known deployment.
Example:
>>> from solidbyte.deploy.objects import Contract
>>> MyContract = Contract('test', '0xdeadbeef00000000000000000000000000000000', {
...         'abi': [],
...         'bytecode': '0x1234...'
...         'name': 'MyContract'
...     }, {}, MetaFile())
>>> assert Mycontract.check_needs_deployment('0x2234...')
deployed(*args, **kwargs)[source]

Return an instantiated web3.eth.Contract tinstance and deploy the contract if necessary.

Parameters:
  • *args

    Any args to provide the constructor.

  • **kargs

    Any kwargs to provide the constructor OR one of the following special kwargs: - gas: The gas limit for the deploy transaction. - gas_price: The gas price to use, in wei. - links: This is a dict of {name,address} of library links for the contract.

Returns:

If the bytecode differs from the last known deployment.

Example:
>>> from solidbyte.deploy.objects import Contract
>>> MyContract = Contract('test', '0xdeadbeef00000000000000000000000000000000', {
...         'abi': [],
...         'bytecode': '0x1234...'
...         'name': 'MyContract'
...     }, {}, MetaFile())
>>> contract = Mycontract.deploy(links={
            'MyLibrary': '0xdeadbeef00000000000000000000000000000001'
        })
>>> assert contract.functions.owner().call() == contract.from_account
is_deployed() → bool[source]

Return if this contract has deployments

refresh() → None[source]

Refresh metadata from MetaFile and the compiled artifacts

class solidbyte.deploy.objects.ContractDependencyTree[source]

A tree of Leafs describing contract library dependencies

Example:
>>> deptree = ContractDependencyTree()
__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

add_dependent(name: str, parent: str = None) → solidbyte.deploy.objects.ContractLeaf[source]

Add a child dependent

has_dependencies(name: str)[source]

Check of name has dependencies

has_dependents(name: str)[source]

Check of name has dependents

move(name: str, new_parent: solidbyte.deploy.objects.ContractLeaf) → solidbyte.deploy.objects.ContractLeaf[source]

Move an element to be a child of another

search_tree(name: str) → Tuple[Optional[solidbyte.deploy.objects.ContractLeaf], int][source]

Search a tree for a named leaf

Parameters:name – The name of the leaf to look for
class solidbyte.deploy.objects.ContractLeaf(name: str, tree: solidbyte.deploy.objects.ContractDependencyTree, parent: Optional[solidbyte.deploy.objects.ContractLeaf] = None)[source]

A leaf object in the dependency tree

Definitions:
  • dependent: Leaves that this leaf depends on
  • dependency: A leaf that depends on this leaf
__init__(name: str, tree: solidbyte.deploy.objects.ContractDependencyTree, parent: Optional[solidbyte.deploy.objects.ContractLeaf] = None) → None[source]

Initialize self. See help(type(self)) for accurate signature.

add_dependent(name: str) → solidbyte.deploy.objects.ContractLeaf[source]

Add a dependent leaf

attach_dependent(el: solidbyte.deploy.objects.ContractLeaf) → None[source]

Attach an element to this Leaf as dependent

get_dependencies() → Set[solidbyte.deploy.objects.ContractLeaf][source]

Resolve and return all dependencies in a flat set

get_dependents() → Set[solidbyte.deploy.objects.ContractLeaf][source]

Resolve and return all dependents in a flat set

get_parent() → Optional[solidbyte.deploy.objects.ContractLeaf][source]

Return the parent ContractLeaf

has_dependencies() → bool[source]

Does this leaf have dependencies?

has_dependents() → bool[source]

Does this leaf have dependents

is_root() → bool[source]

Is this the root leaf?

class solidbyte.deploy.objects.Deployment(network: str, address: str, bytecode_hash: str, date: datetime.datetime, abi: List[Dict[str, Optional[Any]]])[source]

representation of a simgle contract deployment

__init__(network: str, address: str, bytecode_hash: str, date: datetime.datetime, abi: List[Dict[str, Optional[Any]]])[source]

Initialize self. See help(type(self)) for accurate signature.

solidbyte.deploy.objects.get_lineage(leaf: solidbyte.deploy.objects.ContractLeaf) → Set[solidbyte.deploy.objects.ContractLeaf][source]

Climb a deptree and return all elements “above” the provided leaf