I am trying to override _update
method from ERC1155 openzeppelin standard in my contract to write som additional logic but compiler somehow complains about "Function has override specified but does not override anything"
, this is my code:
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
contract MyContract is ERC1155, AccessControl {
...
function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal override {
// my custom logic...
super._update(from, to, ids, values);
}
...
}
Alongside with the error it says second error for super._update part Member "_update" not found or not visible after argument-dependent lookup in type(contract super MyContract)
.
So it looks like MyContract does not see ERC1155 functions from which it inherits? I am trying to comprehend how it works and never worked with inheritance in solidity. I am wondering whether I can override _update method in general, when it is marked as internal virtual
in ERC1155 standard. Can I actually override internal functions and will it work?
So the problem lies in two different versions of Openzeppelin repositary contracts. Compiler automatically imports older 0.8.0 version, which do not contain _update method at all and instead uses _beforeTokenTransfer and _afterTokenTransfer hooks. Those were probably removed in newer 0.8.20 version available in Openzeppelin github repositary and I thought compiler always imports the newest version.
So the problem has two solutions, either override _beforeTokenTransfer (which is what I did) or force compiler to import newer version and override _update method instead.
I hope this helps someone in the future. Compiler never lies.