Unable to inherit both ERC1155 and ERC2771 contracts at same time

I am trying to create an NFT Collection where users can mint with meta transactions. which go through defender relay. But when I inherit ERC1155 and ERC2771 or Ownable contracts it is giving the

TypeError: Derived contract must override function "_msgData". Two or more base classes define function with same name and parameter types

TypeError: Derived contract must override function "_msgSender". Two or more base classes define function with same name and parameter types

TypeError: Contract "Rootster" should be marked as abstract.

:1234: Code to reproduce

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/metatx/ERC2771Context.sol";
import "@openzeppelin/contracts/metatx/MinimalForwarder.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

contract Rootster is ERC1155, ERC2771Context {
    constructor(MinimalForwarder _trustedForwarder) ERC2771Context(address(_trustedForwarder)){

    }

    function udmint() public {
        require(isTrustedForwarder(msg.sender), "caller is not trusted");
        _mint(_msgSender(), 0, 1, "");
    }
}

:computer: Environment

Tried hardhat and Remix, both returns same problem

1 Like

Hi,

Well since more than 1 contract has a function called _msgData and _msgSender, you will need to create an override since the compiler wont know which implementation must be called during runtime if more than 1 function is there.

The error about the contract being abstract should go away once you implement those 2 overrides.

2 Likes

Here are the override functions that have to be included. Thank you

  function _msgSender() internal view override(Context, ERC2771Context)
      returns (address sender) {
      sender = ERC2771Context._msgSender();
  }

  function _msgData() internal view override(Context, ERC2771Context)
      returns (bytes calldata) {
      return ERC2771Context._msgData();
  }
2 Likes