Example #1
0
    def contract(self, abi, address=None, **kwargs):
        contract_class = construct_contract_factory(self.web3, abi, **kwargs)

        if address is None:
            return contract_class
        else:
            return contract_class(address=address)
Example #2
0
    def contract(self, abi, address=None, **kwargs):
        contract_class = construct_contract_factory(self.web3, abi, **kwargs)

        if address is None:
            return contract_class
        else:
            return contract_class(address=address)
 def contract_class(cls, web3: Web3) -> type:
     """Get web3 bound instance of a Contract proxy class."""
     contract_definition = cls.abi_factory()
     contract_class = construct_contract_factory(
         web3=web3,
         abi=contract_definition["abi"],
         code=contract_definition["code"],
         code_runtime=contract_definition["code_runtime"],
         source=contract_definition["source"],
     )
     return contract_class
Example #4
0
 def contract_class(cls, web3: Web3, contract_name=None) -> type:
     """Get web3 bound instance of a Contract proxy class."""
     contract_definition = cls.abi_factory(contract_name)
     contract_class = construct_contract_factory(
         web3=web3,
         abi=contract_definition["abi"],
         code=contract_definition["code"],
         code_runtime=contract_definition["code_runtime"],
         source=contract_definition["source"],
     )
     return contract_class
Example #5
0
def get_contract(web3: Web3, contract_definition: dict, address: str):
    """Get contract implementation in an address."""
    assert address.startswith("0x")

    contract_class = construct_contract_factory(
        web3=web3,
        abi=contract_definition["abi"],
        code=contract_definition["code"],
        code_runtime=contract_definition["code_runtime"],
        source=contract_definition["source"],
    )

    return contract_class(address)
Example #6
0
def get_contract(web3: Web3, contract_definition: dict, address: str):
    """Get contract implementation in an address."""
    assert address.startswith("0x")

    contract_class = construct_contract_factory(
        web3=web3,
        abi=contract_definition["abi"],
        code=contract_definition["code"],
        code_runtime=contract_definition["code_runtime"],
        source=contract_definition["source"],
    )

    return contract_class(address)
Example #7
0
def deploy_contract(
        web3: Web3,
        contract_definition: dict,
        gas=1500000,
        timeout=60.0,
        constructor_arguments: Optional[list]=None,
        from_account=None) -> Tuple[Contract, str]:
    """Deploys a single contract using Web3 client.

    :param web3: Web3 client instance

    :param contract_definition: Dictionary of describing the contract interface,
        as read from ``contracts.json`` Contains

    :param gas: Max gas

    :param timeout: How many seconds to wait the transaction to
        confirm to get the contract address.

    :param constructor_arguments: Arguments passed to the smart contract
        constructor. Automatically encoded through ABI signature.

    :param from_account: Geth account that's balance is used for deployment.
        By default, the gas is spent from Web3 coinbase account. Account must be unlocked.

    :return: Tuple containing Contract proxy object and the transaction hash where it was deployed

    :raise gevent.timeout.Timeout: If we can't get our contract in a block within given timeout
    """

    # Check we are passed valid contract definition
    assert "abi" in contract_definition, \
        "Please pass a valid contract definition dictionary, got {}".format(contract_definition)

    assert len(contract_definition["code"]) > 8, "Contract did not have properly compiled code payload"

    contract_class = construct_contract_factory(
        web3=web3,
        abi=contract_definition["abi"],
        code=contract_definition["code"],
        code_runtime=contract_definition["code_runtime"],
        source=contract_definition["source"],
        )

    if not from_account:
        from_account = web3.eth.coinbase

    # Set transaction parameters
    transaction = {
        "gas": gas,
        "from": from_account,
    }

    # Call web3 to deploy the contract
    txn_hash = contract_class.deploy(transaction, constructor_arguments)

    # Wait until we get confirmation and address
    address = get_contract_address_from_txn(web3, txn_hash, timeout=timeout)

    # Create Contract proxy object
    contract = contract_class(
        address=address,
    )

    return contract, txn_hash