Legacy Chain API¶
Previously, chain objects provided an API for accessing your contract compile and deploy artifacts. This API was moved to the Provider API in the 1.6.0 Release.
Access To Contracts¶
All chain objects present the following API for interacting with your project contracts.
Warning
The Chain.get_contract_factory
API has moved to the Provider API. This function will be removed in subsequent releases.
get_contract_factory(contract_name, link_dependencies=None, validate_bytecode=True)
Returns the contract factory for the contract indicated by
contract_name
from the chain’scompiled_contracts
.If provided,
link_dependencies
should be a dictionary that maps library names to their on chain addresses that will be used during bytecode linking.If truthy (the default),
validate_bytecode
indicates whether the bytecode for any library dependencies for the given contract should be validated to match the on chain bytecode.If your project has no project migrations then the data used for these contract factories will come directly from the compiled project contracts.
If your project has migrations then the data used to build your contract factories will be populutated as follows.:
- The newest migration that has been run which deploys the requested contract.
- The newest migration which contains this contract in it’s
compiled_contracts
property - The compiled project contracts.
Warning
The Chain.get_contract
API has moved to the Provider API. This function will be removed in subsequent releases.
get_contract(contract_name, link_dependencies=None, validate_bytecode=True)
Returns the contract instance indicated by the
contract_name
from the chain’scompiled_contracts
.The
link_dependencies
argument behaves the same was as specified in theget_contract_factory
method.The
validate_bytecode
argument behaves the same way as specified in theget_contract_factory
with the added condition that the bytecode for the requested contract will also be checked.Note
When using a
TestRPCChain
theget_contract
method will lazily deploy your contracts for you. This lazy deployment will only work for simple contracts which do not require constructor arguments.
Warning
The Chain.is_contract_available
API has moved to the Provider API. This function will be removed in subsequent releases.
is_contract_available(contract_name, link_dependencies=None, validate_bytecode=True, raise_on_error=False)
Returns
True
orFalse
as to whether the contract indicated bycontract_name
from the chain’scompiled_contracts
is available through theChain.get_contract
API.The
link_dependencies
argument behaves the same was as specified in theget_contract_factory
method.The
validate_bytecode
argument behaves the same way as specified in theget_contract_factory
with the added condition that the bytecode for the requested contract will also be checked.If
raise_on_error
is truthy, then the method will raise an exception instead of returningFalse
for any of the failure cases.