How to ensure only certain accounts can burn tokens?

For the ERC20 contract, I can’t see that there’s an addBurner() function (like addMinter). How do you make sure that only certain accounts can burn tokens?

You can most definitely do that, you just need to know how to configure your contract. Please share a github gist of your contract code.

2 Likes

I think in most cases, only token owner can burn their tokens, just like this contract ERC20Burnable.sol:

function burn(uint256 amount) public virtual {
    _burn(_msgSender(), amount);
}

For me, I think it is a little weird to allow specific accounts to be able to burn, but if you just want to do like so, I think it is ok. You can write a function to achieve it, and just like you mentioned above, you can use a contract to set permission to burn, I think you can have a look at this contract AccessControl.sol
And here is more details about this contract: Access Control | OpenZeppelin Docs

1 Like

Many thanks @Skyge . The AccessControl appears to be a great solution. :slight_smile: Very clean. If all failed I was just going to place a require statement inside a custom burn function (that calls the _burn function of the ERC20), that ensures only the smart contract address that I desire would be able to call the burn function. But this is a better solution. I'll give this a go. :slight_smile:

Many thanks

2 Likes

No problem @STYJ . @Skyge has provided me with a good solution using the AccessControl functionalities. So I'll give that a try :slight_smile:

Many thanks

2 Likes