def get_contract_by_name(chain: BaseChain, name: str) -> web3.contract.Contract: """Get web3.Contract class by its name. Sanity wrapper over everchanging Populus ABI. """ contract_data = chain.provider.get_contract_data(name) # There's a bug in populus where bytecode and bytecode-runtime can't be linked. # These fields are not needed during interaction with a smart contract, # so they can be ignored contract_factory_fields = filter( lambda x: x not in CONTRACT_FIELDS_TO_REMOVE, CONTRACT_FACTORY_FIELDS) factory_kwargs = { key: contract_data[key] for key in contract_factory_fields if key in contract_data } populus_meta = build_populus_meta(chain, contract_data) Contract = chain.web3.eth.contract( ContractFactoryClass=PopulusContract, populus_meta=populus_meta, **factory_kwargs, ) return Contract
def get_contract_by_name(chain: BaseChain, name: str) -> web3.contract.Contract: """Get web3.Contract class by its name. Sanity wrapper over everchanging Populus ABI. """ contract_data = chain.provider.get_contract_data(name) factory_kwargs = { key: contract_data[key] for key in CONTRACT_FACTORY_FIELDS if key in contract_data } populus_meta = build_populus_meta(chain, contract_data) Contract = chain.web3.eth.contract( ContractFactoryClass=PopulusContract, populus_meta=populus_meta, **factory_kwargs, ) return Contract