[Ethereum] How to automatically mint ERC-20 Tokens Every time the owner wallet transfers coins

dappserc-20solidity

I want to start with a total_supply of 1,000 Tokens in the owner wallet. Each token will represent a gram of gold. Every time 1 token is transferred from owner wallet to another wallet, the owner wallet should be refilled with 1 token. Thus, always keeping the owner wallet at 1,000 Tokens.

Questions:

1. What is the best way to do this?

2. Is there a way where I wouldn't have to pay gas every time coins are minted to owner_wallet?

3. I'd like to accept Bitcoins and Alt coins for this token. What is a good process to have the owner tokens send automatically to people who have paid with Bitcoin and Alt coins? Is there a Dapp or open source script you recommend looking at?

4. Do you have any recommendations or suggestions If I want each token to represent a commodity?

Thanks in advance

Best Answer

You can simply create a function like this:

function mint(uint howMany, address to) public returns (bool) {
  totalSupply = safeAdd(totalSupply, howMany);
  balances[for] = safeAdd(balances[to], howMany);
  Transfer(0, to, howMany);
  return true;
}

Calling that instead of transfer will create new tokens. If you still want to use the transfer function (may be required if you use simpler ERC20 wallets) change the code to this:

    function transfer(address to, uint tokens) public returns (bool success) {
    if(msg.sender == owner) {

        mint(tokens, to);

    }else{
             balances[msg.sender] = balances[msg.sender].sub(tokens);
             balances[to] = balances[to].add(tokens);
             Transfer(msg.sender, to, tokens);
             return true;
     }

Sadly it is not possible to accept Bitcoin or Altcoins in an Ethereum smart contract or Dapp, you will have to rely on a third party solution.

Recommendations about tokens representing commodities: Don't do it. It is very hard to get a license to do stuff like that and you probably need a legal team and regular audits to do so.

Related Topic