MCPcopy
hub / github.com/raiden-network/raiden / deploy_single_contract

Method deploy_single_contract

raiden/network/rpc/client.py:1411–1477  ·  view source on GitHub ↗

Deploy a single solidity contract without dependencies. Args: contract_name: The name of the contract to compile. contract: The dictionary containing the contract information (like ABI and BIN) constructor_parameters: A tuple of arguments to pass

(
        self,
        contract_name: str,
        contract: CompiledContract,
        constructor_parameters: Sequence = None,
    )

Source from the content-addressed store, hash-verified

1409 return self.web3.eth.contract(abi=abi, address=contract_address)
1410
1411 def deploy_single_contract(
1412 self,
1413 contract_name: str,
1414 contract: CompiledContract,
1415 constructor_parameters: Sequence = None,
1416 ) -> Tuple[Contract, TxReceipt]:
1417 """
1418 Deploy a single solidity contract without dependencies.
1419
1420 Args:
1421 contract_name: The name of the contract to compile.
1422 contract: The dictionary containing the contract information (like ABI and BIN)
1423 constructor_parameters: A tuple of arguments to pass to the constructor.
1424 """
1425
1426 ctor_parameters = constructor_parameters or ()
1427
1428 contract_object = self.web3.eth.contract(abi=contract["abi"], bytecode=contract["bin"])
1429 contract_transaction = contract_object.constructor(*ctor_parameters).buildTransaction()
1430 constructor_call = ByteCode(contract_name, contract_transaction["data"])
1431
1432 block = self.get_block(BLOCK_ID_LATEST)
1433
1434 # Sometimes eth_estimateGas returns wrong values for contract deployments
1435 # Add a margin of 50%
1436 # See https://github.com/raiden-network/raiden/issues/5994
1437 gas_with_margin = int(contract_transaction["gas"] * 1.5)
1438 gas_price = gas_price_for_fast_transaction(self.web3)
1439 transaction = TransactionEstimated(
1440 from_address=self.address,
1441 data=constructor_call,
1442 eth_node=self.eth_node,
1443 extra_log_details={},
1444 estimated_gas=gas_with_margin,
1445 gas_price=gas_price,
1446 approximate_block=(BlockHash(block["hash"]), block["number"]),
1447 )
1448
1449 transaction_sent = self.transact(transaction)
1450 transaction_mined = self.poll_transaction(transaction_sent)
1451
1452 maybe_contract_address = transaction_mined.receipt["contractAddress"]
1453 assert maybe_contract_address is not None, "'contractAddress' not set in receipt"
1454 contract_address = to_canonical_address(maybe_contract_address)
1455
1456 if not was_transaction_successfully_mined(transaction_mined):
1457 check_transaction_failure(transaction_mined, self)
1458
1459 raise RuntimeError(
1460 f"Deployment of {contract_name} failed! Most likely a require "
1461 f"from the constructor was not satisfied, or there is a "
1462 f"compiler bug."
1463 )
1464
1465 deployed_code = self.web3.eth.get_code(contract_address)
1466
1467 if not deployed_code:
1468 raise RaidenUnrecoverableError(

Calls 10

get_blockMethod · 0.95
transactMethod · 0.95
poll_transactionMethod · 0.95
new_contract_proxyMethod · 0.95
ByteCodeClass · 0.85