Eth.contract(address=None, contract_name=None, ContractFactoryClass=Contract, **contract_factory_kwargs) If address is provided, then this method will return an instance of the contract defined by abi. The address may be a checksum string, or an ENS name like 'mycontract.eth'.
from web3 import Web3
w3 = Web3(...)
contract = w3.eth.contract(address='0x000000000000000000000000000000000000dEaD', abi=...)
contract = w3.eth.contract(address='mycontract.eth', abi=...) Note
If you use an ENS name to initialize a contract, the contract will be looked up by name on each use. If the name could ever change maliciously, first Look up the address for an ENS name, and then create the contract with the checksum address.
If address is not provided, the newly created contract class will be returned. That class will then be initialized by supplying the address.
from web3 import Web3
w3 = Web3(...)
Contract = w3.eth.contract(abi=...)
contract1 = Contract(address='0x000000000000000000000000000000000000dEaD') contract2 = Contract(address='mycontract.eth') contract_name will be used as the name of the contract class. If it is None then the name of the ContractFactoryClass will be used.
ContractFactoryClass will be used as the base Contract class.
The following arguments are accepted for contract class creation.
abi
asm
ast
bytecode
bytecode_runtime
clone_bin
dev_doc
interface
metadata
opcodes
src_map
src_map_runtime
user_doc
See Contracts for more information about how to use contracts.
Eth.set_contract_factory(contractFactoryClass) Modify the default contract factory from Contract to contractFactoryClass. Future calls to Eth.contract() will then default to contractFactoryClass.
An example of an alternative Contract Factory is ConciseContract.
Eth.setContractFactory(contra
