1

I tried to deploy both ERC20 contracts with burn functionality over the remix and both seems to work fine, I am confused if one way should be preferred over the other. Since, openzeppelin contract wizard seems to implement the first way but for me the second also works just fine. Can someone point out where I am going wrong, inheritance is getting confusing for me.

    pragma solidity ^0.8.4;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
    
    contract MyToken is ERC20, ERC20Burnable {
        constructor() ERC20("MyToken", "MTK") {
           _mint(msg.sender, 2000 * 10 ** decimals());
}
    }

OR

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";

contract MyToken is ERC20Burnable {
    constructor() ERC20("MyToken", "MTK") {
        _mint(msg.sender, 2000 * 10 ** decimals());
    }
}

2 Answers 2

0

Found this openzeppelin's discussion openzeppelin-contracts github discussion

0

ERC20Burnable inherits ERC20 contract so both ways are same.

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Burnable.sol

Inheriting ERC20 contract as well explicitly in your contract and initializing it makes it a bit more descriptive

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.