0

I get this error when I try to create the contract with some ETH, but if I just click create without sending ether the contract is correctly deployed.

enter image description here

1

Your constructor isn't payable.

Contract functions throw if Ether is sent and the function isn't explicitly marked payable. This helps prevent Ether from becoming marooned in contracts that weren't expecting it and have no withdraw function with which to get it back.

Since function MyToken( .... isn't payable the deployment itself fails with an exception when unwanted/unexpected Ether arrives.

You can resolve that with

function MyToken(...) payable {}

I see you have a payable fallback function so you could deploy the contact, then send funds to the contract address.

On first look, this contract appears to have no way to recover Ether sent to it, so it's effectively burned once transferred. This does indeed show that it's important for designers to consider how Ether moves in and out and why it's desirable to prevent unwanted receipts.

Hope it helps.

| improve this answer | |
0

Thank for the answer; I have another question for you: why the fallback function is called even though I send 0 ether at the start?

| improve this answer | |
  • You posted this as an answer but it is actually a new question. You will get better answers if you post it as a new question. – Ajoy Bhatia Jul 11 '17 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.