Token erc20 with specified contract owner

#1

hello
i want to create a standard erc20 token but i would like to specify a public address as contract owner instead of the address signing the transaction of contract creation.
Is this possible? how can i do this?
thanks
Massimo

#2

Hello @mssmx, welcome to the forum!

OpenZeppelin’s ERC20 contract has no owner to speak of, perhaps you’re referring to one of its variants, such as ERC20Mintable? In those cases, there are internal functions that you could call in your constructor to achieve the result you want. Perhaps you could share some code so we can better help you?

Again, welcome! Check out the intros thread and tell us a bit about you. :slight_smile:

#3

thank you for reply. at the moment i am referring to standard erc20. i know that there is no owner, but normally the signer of the contract creation transaction (msg.sender) is the “creator” which will receive the full amount. In my very simple case, i would like to specify a different address where to send all the tokens at creation time but this address does not belong to the msg.sender. please see below the code. is this ok on your opinion from that point of view?

pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
        string public name ;
        string public symbol;
        uint public decimals;
        uint private INITIAL_SUPPLY;

        constructor(
            string memory tokenName,
            string memory tokenSymbol,
            uint256 tokenDecimals,
            uint256 initialSupply,
            address tokenOwner
            ) public {
                name=tokenName;
                symbol=tokenSymbol;
                decimals=tokenDecimals;
                INITIAL_SUPPLY = initialSupply * (10 ** decimals);
		// send all the supply to tokenOwner
                _mint(tokenOwner,INITIAL_SUPPLY);
        }

}
#4

@nventuro do you have a suggestion about above?

#5

Hello @mssmx! No need to tag nventuro :slight_smile: he should be notified on replies.

As for the code you put, it seems fine for your needs! There’s no need to make INITIAL_SUPPLY a global variable though, you can just use it as totalSupply.

#6

ok Ivan thank you. sorry for unuseful tagging

1 Like
#7

Ah, I see what you mean. In your case, if you already know the address, you can simply include it in the constructor as a hard-coded value:

constructor() public {
  // replace below with intended recipient address
  _mint(0x36Fe25e27F640a8635Ba8f0F10F3eadFDf5bC04a, INITIAL_SUPPLY);
}

Alternatively, for a more flexible solution you could pass it as an argument:

constructor(address initialHolder) public {
  _mint(initialHolder, INITIAL_SUPPLY);
}

Finally, you can also inherit from ERC20Detailed, and make managing name, etc. easier that way :slight_smile:

contract is ERC20, ERC20Detailed  {
  constructor(
    address initialHolder,
     string memory name, 
     string memory symbol, 
     uint8 decimals)
  ERC20Detailed(name, string, decimals) 
  public {
    _mint(initialHolder, INITIAL_SUPPLY);
  }
}
#8

thank you! I used your last suggestion and all assembled i got this:

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";


contract MyToken is ERC20, ERC20Detailed  {
  constructor(
    address initialHolder,
     string memory name, 
     string memory symbol,
    uint256 initialSupply,
     uint8 decimals)
  ERC20Detailed(name, symbol , decimals) 
  public {
    _mint(initialHolder, initialSupply * (10 ** uint256(decimals)));
  }
}

it seems working. i pass all the details as arguments. am i ok?

1 Like
#9

Yes, your example looks great :slight_smile:

1 Like