[Ethereum] Mist Testnet error “it seems this transaction will fail”

gasgas-estimatemisttestnets

I am very new to Ethereum, and just working through some early tutorials using the testnet. My version is up to date; the blockchain is also up to date; and I have only one account in the keystore, the main account.

As I try to deploy a simple contract (or any contract for that matter – including the examples on ethereum.org), the code compiles correctly:

enter image description here

When I go ahead and hit deploy contract, the confirmation popup gives me this error: "it seems this transaction will fail. If you submit it, it may consume all the gas you send"

enter image description here

It gives me this error irrespective of whether I send 1 eth or 20eth, and regardless of the fee amount I choose.

If I press on regardless, the contract appears to be created on the mist wallet UI, but sits with another error message under the transaction saying basically that no data reached the blockchain: " No data is deployed on the contract address!".

My apologies if this is basic. I have scanned previous questions and they either didn't quite cover this scenario, or had a fix that didn't work for me (like reselecting the FROM account just before deploying)

Many thanks in advance.

Best Answer

You can't send ether to this constructor or it will fail by design. If you want the opposite behavior then you specify the keyword "payable" in the function. It helps prevent errant transactions sending ether to contracts with no hope of recovering it.

Hope it helps.

UPDATE:

Example for clarity.

pragma solidity ^0.4.2;
contract Example {

   string public brandName;

   function Example(string yourCompanyName) payable { // <--- here    
       brandName = yourCompanyName;
   }

}

As eluded to earlier, there is no way to make the contract send ether, so any funds deposited there are marooned. We could fix that with a simple indiscriminate withdraw function.

function withdraw(uint amount) public returns(bool success) {
   if(!msg.sender.send(amount) throw;
   return true;
}
Related Topic