0

I am using the following code structure;

pragma solidity ^0.5.0;

  contract TtdmToken {

    uint256 public totalSupply;

    function TtdmToken () public {
        totalSupply = 1000000;
    }
   }

But when compiling with truffle compile I am getting the following error,

enter image description here

I have seen similar issue here suggesting the change of contract name I changed the contract to the following but still getting similar results.

pragma solidity ^0.5.0;

  contract TtdmToken {

    uint256 public totalSupply;

    function TtdmToken () public {
        totalSupply = 1000000;
    }

    contract constructor_TtdmToken {
        function TtdmToken()

    }

   }

And this is the error after making the change;

enter image description here

  • The title of your question doesn't seem to have anything to do with what you've posted inside the question! – goodvibration Jan 14 '20 at 18:48
  • And the issue that you've linked doesn't suggest to change the contract name, it suggests to change the function name to constructor! – goodvibration Jan 14 '20 at 18:50
  • I'm voting to close this question as off-topic because it's a duplicate of the exact same question which you have linked in it, and if you had read the answer to it more carefully then you would have gotten the solution to your problem. – goodvibration Jan 14 '20 at 18:52
  • When I changed the name it gave the error message in the tittle, then to replicate the same issue I went back to the original bug code which is the one linked. – Lucas Jan 14 '20 at 18:55
  • If you have a different problem then please post that other problem including the exact code which leads to it. Your code leads to a different problem than the title of your question, and the solution to it is given in the answer to the question that you've linked. On top of all that, please post everything in plain (copy-pastable) text, not in images. This question, in its current form, already has an answer. – goodvibration Jan 14 '20 at 18:58
0

The compiler complains because function TtdmToken() ends unexpectedly (your second attempt).

Use constructor() instead of function() (of any name) to make a constructor.

pragma solidity ^0.5.0;

contract TtdmToken {

  uint256 public totalSupply;

  constructor () public {
    totalSupply = 1000000;
  }
}

Hope it helps.

  • 1
    You're right. It was more off than I realized from just eyeballing it. Edited the answer. – Rob Hitchens Jan 15 '20 at 17:48
-1

The code worked and return the migration with the following correction;

pragma solidity ^0.5.0;

      contract TtdmToken {

        uint256 public totalSupply;

        function constructor_TtdmToken () public {
            totalSupply = 1000000;
        }
       }
  • 1
    You are very much mistaken in thinking that this function is now a constructor. In contrast with a constructor: 1. It will not execute automatically when you deploy the contract. 2. Much worse - anyone will be able to call it on your contract, thus resetting the total-supply. – goodvibration Jan 14 '20 at 19:38
  • Just so you know - there was a real time incident back in the days when the language syntax dictated that the name of the constructor should be the same as the name of the contract - somebody renamed their contract but forgot to rename their constructor function, and as soon as they deployed their contract, somebody simply called their "constructor" and drained out the contract. That is why the syntax has changed, and the name of the constructor function is now simply constructor (which is not what you did in your code above). – goodvibration Jan 14 '20 at 19:43
  • @goodvibration really appreciate your instructions the are really valuable, and the sharing of that observation. In this case then only the constructor should be used without adding_... – Lucas Jan 14 '20 at 23:19

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