1

I would like to test sending ERC20 tokens with my client, so I need to create some tokens on a Testnet. I'm using Remix and Rinkeby testnet, but remix is not what I'm used to anymore. When I did this before (created a contract), there used to be a text field where one could put the constructor parameters to deploy the contract. But now all I see is a test field of Local contract from Address. Where is the constructor field that used to be there?

This is what I see:

enter image description here

And this is my contract:

/*
Implements EIP20 token standard: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
.*/


pragma solidity ^0.4.21;

import "./EIP20Interface.sol";
import "./SafeMath.sol";


contract MyToken is EIP20Interface {

    uint256 constant private MAX_UINT256 = 2**256 - 1;
    mapping (address => uint256) public balances;
    mapping (address => mapping (address => uint256)) public allowed;
    /*
    NOTE:
    The following variables are OPTIONAL vanities. One does not have to include them.
    They allow one to customise the token contract & in no way influences the core functionality.
    Some wallets/interfaces might not even bother to look at this information.
    */
    string public name;                   //fancy name: eg Simon Bucks
    uint8 public decimals;                //How many decimals to show.
    string public symbol;                 //An identifier: eg SBX

    function Constructor (
        uint256 _initialAmount,
        string _tokenName,
        uint8 _decimalUnits,
        string _tokenSymbol
    ) public {
        balances[msg.sender] = _initialAmount;               // Give the creator all initial tokens
        totalSupply = _initialAmount;                        // Update total supply
        name = _tokenName;                                   // Set the name for display purposes
        decimals = _decimalUnits;                            // Amount of decimals for display purposes
        symbol = _tokenSymbol;                               // Set the symbol for display purposes
    }

    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(balances[msg.sender] >= _value);
        balances[msg.sender] = SafeMath.sub(balances[msg.sender], _value);
        balances[_to] = SafeMath.add(balances[_to], _value);
        emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        uint256 allowance = allowed[_from][msg.sender];
        require(balances[_from] >= _value && allowance >= _value);
        balances[_to] = SafeMath.add(balances[_to], _value);
        balances[_from] = SafeMath.sub(balances[_from], _value);
        if (allowance < MAX_UINT256) {
            allowed[_from][msg.sender] = SafeMath.sub(allowed[_from][msg.sender], _value);
        }
        emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function balanceOf(address _owner) public view returns (uint256 balance) {
        return balances[_owner];
    }

    function approve(address _spender, uint256 _value) public returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
        return allowed[_owner][_spender];
    }
}

EDIT:

I found that if I change the constructor from Constructor to MyToken, it works. Apparently remix recomments using Constructor and calls using the class name as deprecated, but then if you do that, you won't be able to deploy your contract. Sounds like a bug?

2

You don't have to add function keyword in front of constructor. it won't show up during deployment because you are declaring it as contract function. Remove function keyword and try. definitely it will work.

constructor (uint256 _initialAmount, string _tokenName, uint8 _decimalUnits, string _tokenSymbol) public {
    balances[msg.sender] = _initialAmount; // Give the creator all initial tokens 
    totalSupply = _initialAmount; // Update total supply 
    name = _tokenName; // Set the name for display purposes 
    decimals = _decimalUnits; // Amount of decimals for display purposes 
    symbol = _tokenSymbol; // Set the symbol for display purposes 
}
1

Go to the compile tab at the top right and click the "compile" button and then tick the "autocompile" checkbox.

When you go back to Deploy you should have the text box to pass initial parameters.

  • Autocompile is already checked... – The Quantum Physicist Jul 4 '18 at 16:54
  • Does it compile and give you the text box on the javascript VM? – Dean Brown Jul 4 '18 at 16:56
  • Nothing changes when changing to Javascript VM. – The Quantum Physicist Jul 4 '18 at 16:59
  • I think I found the problem... if I change the constructor name from Constructor to MyToken, it works. It's a bug in remix. – The Quantum Physicist Jul 4 '18 at 17:14
  • Oh you're right! constructor wasn't introduced until solidity 0.4.22. – Dean Brown Jul 4 '18 at 17:18

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.