1

I noticed some smart contracts have there name,symbol, and supply set up like this example #1 and setup a defined constructor. Notice, they did not fill in the "string public symbol", "string public name", or "unit decimals", or "unit total supply".

Example #1:

contract PucksToken is ERC20Interface, Owned, SafeMath {
    string public symbol;
    string public  name;
    uint8 public decimals;
    uint public _totalSupply;

    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;


    // ------------------------------------------------------------------------
    // Constructor
    // ------------------------------------------------------------------------
    constructor() public {
        symbol = "0PUCKS";
        name = "0 Pucks Token";
        decimals = 18;
        _totalSupply = 100000000000000000000000000;
        balances[0x5A86f0cafD4ef3ba4f0344C138afcC84bd1ED222] = _totalSupply;
        emit Transfer(address(0), 0x5A86f0cafD4ef3ba4f0344C138afcC84bd1ED222, _totalSupply);

And some set the smart contract like this and use the "string public constant" to define. Example #2:

contract BTClite is StandardToken, Ownable {

  string public constant name = "BTC LITE";
  string public constant symbol = "BTCL";
  uint8 public constant decimals = 8;

  uint256 public constant SUPPLY_CAP = 21000000 * (10 ** uint256(decimals));

  address NULL_ADDRESS = address(0);

My question is when writing a smart contract, in example #1 is the defined "construct" code info sufficicent to define the terms of the contract and you do not have to fill in the information "string public constant"?

Basically why did example #1 not fill/input this information in below?

string public symbol;
    string public  name;
    uint8 public decimals;
    uint public _totalSupply;

or are they both the same?

0

If the values were the same the end result would be the same. It's just a matter of programming style.

If you give the values as parameters to the constructor you can possibly launch multiple contracts with different constructor parameters and the contracts become different. If the values are hardcoded inside the code there's no way to change them and you can't reuse the same code for different contracts.

So it all depends on what you want to achieve. Typically it's better to give such values as constructor parameters so you can possibly reuse the code elsewhere and you/or you don't have to decide the exact values before you deploy the contract.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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