4

This is my smartcontract code

pragma solidity ^0.5.0;

contract DappToken{


uint256 public totalSupply;

constructor DappToken() public{
    totalSupply = 10000;    

 }

}

This is code for migration in truffle.

const Dapptoken = artifacts.require("DappToken.sol");

module.exports = function(deployer) {

deployer.deploy(Dapptoken);

Blockquote

};

5

Prior to Solidity v0.4.21:

contract ContractName {
    function ContractName(...) public {
        ...
    }
    ...
}

Solidity v0.4.21 onward:

contract ContractName {
    constructor(...) public {
        ...
    }
    ...
}

The reason:

In the older version, if you renamed the contract but forgot to rename the constructor, the latter would turn into a public function which anyone could execute at will. Subsequently, terrible things could happen to the state (funds and variables) of your contract. BTW, this is based on a true story.

2

Constructor functions should not have a name. Just this will do fine as a constructor:

constructor() public {
    totalSupply = 10000;    

 }
1

You should remove DappToken from after constructor, then your problem is fixed

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.