How to create a capped & burnable ERC20 token using openzeppline V5

I wanted to create a capped & burnable ERC20 token using openzeppline V5, but I got error: "Derived contract must override function "_update". Two or more base classes define function with same name and parameter types." What would be the proper way of creating this token? Please see my codes below and this code works well for openzeppline V4.

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
contract MyToken is ERC20Capped, ERC20Burnable {
    address payable public owner;

    constructor(uint256 cap) ERC20("MyToken", "MT") ERC20Capped(cap * (10 ** decimals())) {
        owner = payable(msg.sender);
        _mint(owner, 70000000 * (10 ** decimals()));
    }
}

Because both ERC20 and ERC20Capped have an _update function, you need to add an override like this:

    function _update(address from, address to, uint256 value)
        internal
        override(ERC20, ERC20Capped)
    {
        super._update(from, to, value);
    }
2 Likes