1

i am learning solidity contracts and ethereum dapps. I have created a smart contract for creating a ERC20 token on using truffle dev environment.

pragma solidity ^0.5.0;

contract LearnTokens {
    string  public name = "LearnToken";
    string  public symbol = "LT";
    string  public standard = "LearnToken Token v1.0";
    uint256 public totalSupply;

    event Transfer(
        address indexed _from,
        address indexed _to,
        uint256 _value
    );

    mapping(address => uint256) public balanceOf;

    function LearnToken (uint256 _initialSupply) public payable{
        balanceOf[msg.sender] = _initialSupply;
        totalSupply = _initialSupply;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(_value <= balanceOf[_from]);


        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;



        emit Transfer(_from, _to, _value);

        return true;
    } }

This is my migration file

var LearnToken = artifacts.require("./LearnToken.sol");

module.exports = function(deployer) {
    deployer.deploy(LearnToken,100);
};

And When i try to run truffle test, it throws following error.

1) Contract: LearnToken
       sets the total supply upon deployment:

      sets the total supply to 100
      + expected - actual

      -0
      +100

I have assumed it here that when i run truffle migrate, it sets the initial supply to 100, as i have seen in a tutorial. Am i getting this right or there is another way? TIA

3

1 Answer 1

2

Upon running truffle migrate your contract will not set anything to initial supply. It has no constructor. Upon close inspection I found that you have a function

function LearnToken (uint256 _initialSupply) public payable{
    balanceOf[msg.sender] = _initialSupply;
    totalSupply = _initialSupply;
}

Are you trying to make it your constructor? The function name doesn't match with your contract name. Even if it matched you will get another error as you are using solidity version ^5.0.0. You need to write your constructor as below

constructor (uint256 _initialSupply) public payable{
    balanceOf[msg.sender] = _initialSupply;
    totalSupply = _initialSupply;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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