Need help with the following code that throws an error!
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Capped.sol";
contract MyToken is ERC20PresetMinterPauser, ERC20Capped {
constructor() public ERC20PresetMinterPauser("MyToken","MNT") ERC20Capped(452552412) {
_setupDecimals(8);
}
}
Throws an error when compiling:
TypeError: Derived contract must override function "_beforeTokenTransfer". Two or more base classes define function with same name and parameter types.
2 Likes
Hi @DeusNexus,
Welcome to the community forum
Thanks for posting here.
As per the error we need to override function _beforeTokenTransfer
as both ERC20PresetMinterPauser
and ERC20Capped
define it. See your updated code below:
MyToken.sol
// contracts/MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Capped.sol";
contract MyToken is ERC20PresetMinterPauser, ERC20Capped {
constructor()
public
ERC20PresetMinterPauser("MyToken", "MNT")
ERC20Capped(452552412)
{
_setupDecimals(8);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override(ERC20PresetMinterPauser, ERC20Capped) {
super._beforeTokenTransfer(from, to, amount);
}
}
To learn more about hooks see: https://docs.openzeppelin.com/contracts/3.x/extending-contracts#rules_of_hooks
Please note, your cap is set to 452552412
. With decimals of 8 this is only 4.52552412
MNT.
See: https://docs.openzeppelin.com/contracts/3.x/erc20#a-note-on-decimals
1 Like
Awesome that cleared up a lot, the inheritance is kind of confusing when you first dive into this, many thanks!
Is there any documentation where I can read more about approve, decreaseAllowance, increaseAllowance, allowance. I want to use burnTokens but not sure how to properly use this in combination with allowence.
1 Like
Hi @DeusNexus,
Do you need any more information?