0

I created and deployed the smart contract using ConsenSys EIP20 sample (https://github.com/ConsenSys/Tokens/tree/master/contracts/eip20). Basically, I took the file EIP20.sol and changed the name of the contract to the name of my token, in Remix. I also added the file EIP20Interface.sol to Remix, as the smart contract had the line "import "./EIP20Interface.sol";" When I was verifying the contract on Etherscan, I combined two files in one single file and removed "import" line from the smart contract. The ERC20 has been successfully verified on the Etherscan.

  1. Could you please advise if this approach of creating one single code was correct? I'm planning to publish the code in Github and not sure whether It's better to upload two separate files as it was done in Remix or only one single code as it was done on Etherscan? The single code that was published on Etherscan is attached. The first part of the code is what has been taken from the EIP20Interface.sol file. The ERC20 contract: 0xa150Db9b1Fa65b44799d4dD949D922c0a33Ee606

     contract EIP20Interface {
         /// total amount of tokens
         uint256 public totalSupply;
    
         /// @param _owner The address from which the balance will be retrieved
         /// @return The balance
         function balanceOf(address _owner) public view returns (uint256 balance);
    
         /// @notice send `_value` token to `_to` from `msg.sender`
         /// @param _to The address of the recipient
         /// @param _value The amount of token to be transferred
         /// @return Whether the transfer was successful or not
         function transfer(address _to, uint256 _value) public returns (bool success);
    
         /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
         /// @param _from The address of the sender
         /// @param _to The address of the recipient
         /// @param _value The amount of token to be transferred
         /// @return Whether the transfer was successful or not
         function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
    
         /// @notice `msg.sender` approves `_spender` to spend `_value` tokens
         /// @param _spender The address of the account able to transfer the tokens
         /// @param _value The amount of tokens to be approved for transfer
         /// @return Whether the approval was successful or not
         function approve(address _spender, uint256 _value) public returns (bool success);
    
         /// @param _owner The address of the account owning tokens
         /// @param _spender The address of the account able to transfer the tokens
         /// @return Amount of remaining tokens allowed to spent
         function allowance(address _owner, address _spender) public view returns (uint256 remaining);
    
         // solhint-disable-next-line no-simple-event-func-name
         event Transfer(address indexed _from, address indexed _to, uint256 _value);
         event Approval(address indexed _owner, address indexed _spender, uint256 _value);
     }
    
     pragma solidity ^0.4.26;
    
     contract DigitalReserveCurrency is EIP20Interface {
    
         uint256 constant private MAX_UINT256 = 2**256 - 1;
         mapping (address => uint256) public balances;
         mapping (address => mapping (address => uint256)) public allowed;
    
         string public name;                   
         uint8 public decimals;                
         string public symbol;                 
    
         constructor(
             uint256 _initialAmount,
             string _tokenName,
             uint8 _decimalUnits,
             string _tokenSymbol
         ) public {
             balances[msg.sender] = _initialAmount;               
             totalSupply = _initialAmount;                        
             name = _tokenName;                                   
             decimals = _decimalUnits;                            
             symbol = _tokenSymbol;                               
         }
    
         function transfer(address _to, uint256 _value) public returns (bool success) {
             require(balances[msg.sender] >= _value);
             balances[msg.sender] -= _value;
             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] += _value;
             balances[_from] -= _value;
             if (allowance < MAX_UINT256) {
                 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];
         }
     }
    
  2. My second question is that I indicated the total supply and decimals when was deploying the ERC20 smart contract in Remix. This was not included in the code itself. So it seems that it's not possible to find out information about the total supply just reading the code. This information can be found in Etherscan, not in the code. Could you please confirm this as well?

1 Answer 1

0
  1. The two approaches are correct. However, I would say that putting the contract and its interface in two different files is a best practice, as it increases readability. But that's purely surjective.

  2. Yes, the variables totalSupply, name, decimals, symbol are passed to the constructor. Their values are therefore not visible in the code itself and set during the contract deployment. However, Solidity creates automatically getters for all public state variables, which makes them readable from the outside.

1
  • Thank you so much for your detailed answers. It was very helpful!
    – user63373
    Sep 2, 2020 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy