1

I can add a mint to increase the supply but how do I decrease the supply of my token? I can send it to 0x0000000000000000000000000000000000000000 or create a contract which immediately self destructs and sends to its own address to make them unrecoverable but technically that doesn't change the total supply and frankly it's a bit crude. Is there a more elegant solution that preferably decreases the supply?

0

In order to de-mint coins you would just change the value of the given address that holds the tokens and then subtract that amount from the totalSupply. So you could have a function like

function demint(address owner, uint amount) {
    balances[owner] -= amount;
    totalSupply -= amount;
}

Assuming you have a state variable balances[] that maps addresse to uint. This is basically the withdrawal method except that instead of transferring you are simply deminting. You would also need permission from the owner of the tokens.

| improve this answer | |
1

Well, there is no standardized burn/de-mint function neither in the ERC-20, nor in the ERC233 token standard, however OpenZeppelin could be a good starting point for you. I suggest you to have a look at this github repo. You can just import this BurnableToken.sol in your project and use it.

here is the function from OpenZeppelin what you are looking for:

function burn(uint256 _value) public {
        require(_value > 0);
        require(_value <= balances[msg.sender]);
        // no need to require value <= totalSupply, since that would imply the
        // sender's balance is greater than the totalSupply, which *should* be an assertion failure

        address burner = msg.sender;
        balances[burner] = balances[burner].sub(_value);
        totalSupply = totalSupply.sub(_value);
        Burn(burner, _value);
    }
| improve this answer | |

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.