1

This is my ERC1155 contract:

    // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
pragma abicoder v2;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
contract TestERC1155 is ERC1155 {
    constructor()
        ERC1155(
            "https:/asdasdasd.com/{id}.json"
        )
    {}
    /**
     * @dev Hook that is called after any token transfer. This includes minting
     * and burning, as well as batched variants.
     *
     * The same hook is called on both single and batched variants. For single
     * transfers, the length of the `id` and `amount` arrays will be 1.
     *
     * Calling conditions (for each `id` and `amount` pair):
     *
     * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * of token type `id` will be  transferred to `to`.
     * - When `from` is zero, `amount` tokens of token type `id` will be minted
     * for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
     * will be burned.
     * - `from` and `to` are never both zero.
     * - `ids` and `amounts` have the same, non-zero length.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual override {
        super._afterTokenTransfer(operator,from,to,ids,amounts,data);
        //handle our custom code after transfers

    }
}

@openzeppelin/contracts/token/ERC1155/ERC1155.sol has clearly defined virtual functions _beforeTokenTransfer (which I can override with 0 issues) and _afterTokenTransfer (which crashes and burns)

, yet this contract refuses to compile in remix with error:

TypeError: Function has override specified but does not override anything.
--> contracts/testERC1155.sol:38:24:
38 | ) internal virtual override {
                      | ^^^^^^^^

TypeError: Member "_afterTokenTransfer" not found or not visible after argument-dependent lookup in type(contract super TestERC1155).
--> contracts/testERC1155.sol:39:9:
39 | super._afterTokenTransfer(operator,from,to,ids,amounts,data);
| ^^^^^^^^^^^^^^^^^^^^^^^^^

Why doesnt my contract see the virtual function it should have inherited?

2
  • The code you posted here is how you are overriding the function? Yes?
    – Sky
    Apr 15, 2022 at 9:44
  • Correct. For now I have put the code into _beforeTokenTransfer and it works, I just dont understand why _afterTokenTransfer isnt recognized.
    – Joze Jerse
    Apr 15, 2022 at 9:51

0

Your Answer

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