1

The sample "Advanced Token" contract here: https://www.ethereum.org/token

Does not work when deployed on the test net. Trying to send ether to the contract to buy tokens results in the error message:

The contract won't allow this transaction to be executed

Nothing in the tutorial explains why this would happen.

  • Yea, OP says he fixed it but does not provide the solution because he "can't find which was precisely the mistake". – The Shoe Shiner Jan 12 '18 at 16:58
  • Understood. Have you tried running the code on Remix to see if it throws the same error? – Richard Horrocks Jan 12 '18 at 16:59
  • 1
    Thanks for the tip. I had executed it in Remix, but didn't realize the power of the Remix debugger, which lead me to what I described in the answer. – The Shoe Shiner Jan 12 '18 at 19:38
  • Argh - I take it back. Even with the fix, the contract wont execute. Remix says it will, and that it will take 30k gas, but the Ethereum client still reports that it will fail. So still no fix. – The Shoe Shiner Jan 13 '18 at 14:29
1

Edit So, I figured out the issue. My "payable" function is called buy(). I assumed that the contract would automatically select the payable function when sending ether, but it looks like you need the catch-all payable function, instead of a named one, to receive arbitrary ether payments. Once I removed the function name, it all worked.

Edit: Although the below information was part of the issue, the specific solution is above.

So as best I can tell here is the issue...

  • On create, the contract code gives the owner account the initial supply of tokens
  • So implicitly the contract account has zero tokens
  • The buy() operations are expected to pull from the contract account

So for buy() to work there are a couple options (in order of increasing complexity)

  • Add the initial supply to the contract account instead of the owner account. (requires contract code change)
  • Transfer some tokens to the contract account from the owner, post creation. (Requires 1 extra transactions, no code)
  • Send some ether to the contract account and sell tokens from the owner back to the contract (Requires 1 extra transaction and spending ether)

It makes perfect sense looking at the code in detail, just didnt catch the aspect of the owner address, referenced as "msg.sender" as opposed to the contract address, referenced as "this".

  • So, I figured out the issue. The "payable" function is called buy(). I assumed that the contract would automatically select the payable function when sending ether, but it looks like you need the catch-all payable function, instead of a named one, to receive arbitrary ether payments. Once I removed the function name, it all worked! – The Shoe Shiner Jan 13 '18 at 18:32
0

After contract creation, the initial coin allotment belongs to the contract owner. You need to transfer some of the new coins to the contract itself.

With a zero balance, the contract will not allow the transaction to happen.

  • Yep, this was part of the issue. So the example contract does not actually create a functioning setup, without manual involvement to move the tokens. – The Shoe Shiner Feb 21 '18 at 15:58

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.