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.
-
__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
- *args –
-
class
solidbyte.deploy.objects.
ContractDependencyTree
[source]¶ A tree of Leafs describing contract library dependencies
Example: >>> deptree = ContractDependencyTree()
-
add_dependent
(name: str, parent: str = None) → solidbyte.deploy.objects.ContractLeaf[source]¶ Add a child dependent
-
-
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.
-
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