0
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

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

contract GNaira is ERC20, ERC20Capped, ERC20Burnable {
    address public owner;

    constructor(uint256 cap) ERC20("GNaira", "gNGN") ERC20Capped(cap * (10 ** decimals())) {
        owner = msg.sender;
        _mint(owner, 3000000000000 * (10 ** decimals())); // Mint initial supply up to the cap
    }

    function _mint(address account, uint256 amount) internal override(ERC20, ERC20Capped) {
        super._mint(account, amount);
    }

    function _beforeTokenTransfer(address from, address to, uint256 amount)
        internal
        override(ERC20, ERC20Capped, ERC20Burnable)
    {
        super._beforeTokenTransfer(from, to, amount);
    }
}
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

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

contract GNaira is ERC20Capped, ERC20Burnable {
    address public owner;

    constructor(
        uint256 cap
    ) ERC20("GNaira", "gNGN") ERC20Capped(cap * (10 ** decimals())) {
        owner = msg.sender;
        _mint(owner, 3000000000000 * (10 ** decimals()));
    }
}

The code below was the initial code. The code above was recommended as a solution and it still showing the same error. How do I fix it? I'd appreciate the help.

1 Answer 1

1

This is because both of the contracts you are inheriting are inherited from ERC20 itself.

This code should work, as you need to override the _update function only.

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

contract GNaira is ERC20, ERC20Capped, ERC20Burnable {
    address public owner;

    constructor(uint256 cap) ERC20("GNaira", "gNGN") ERC20Capped(cap * (10 ** decimals())) {
        owner = msg.sender;
        _mint(owner, 3000000000000 * (10 ** decimals())); // Mint initial supply up to the cap
    }

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

This should work as expected.

2
  • Thanks a lot. It works Commented May 29 at 6:25
  • Cool, you can check mark the answer if it solved the issue. Commented May 29 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.