Let's say I'm building an ERC1155 contract, and I incorporate OpenZeppelin's ERC1155Supply. That, at least as of the current master, has the following:

mapping(uint256 => uint256) private _totalSupply;

Now let's say I want to access that mapping directly. I obviously can't do:


or something like that, since the whole point of private is that it can't be seen by the child, but I did think that something like:


would work, but unfortunately the compiler doesn't seem to agree with me.

TypeError: Member "_totalSupply" not found or not visible after argument-dependent lookup in type(contract ERC1155Supply).

Is there any way to access the mapping from the child contract? If there isn't, is there some kind of other solution? Since it isn't a public variable, I can't even override it.

1 Answer 1


If you can alter the parent contract I can advise you to use the internal access modifier. Then it works out of the box.

Otherwise implement a set function in you parent contract. For example:

uint256 private number;

function setNumber(uint256 num) public{
    number = num;

Then in the child contract:

function setNumberChild(uint256 num) public{

You could use internal for the set function in the parent contract as well.

  • 1
    the problem here is that I'm inheriting a contract from OZ, so I don't want to modify it - my last resort would be to literally copy the code into my contract and modify it (ERC1155Supply isn't very big), but I'm hoping to avoid it, and there would be other cases where it would be super unwieldy Commented Nov 11, 2021 at 17:38
  • (and OZ didn't put a setter on this one) Commented Nov 11, 2021 at 17:39
  • @TheRenaissance Yeah it kindof makes sense that there is no setter for this ERC1155Supply. Changing to what I indicated probably leads to some vulnerabilities. From what I see their contract isn't designed to facilitate incrementing the totalSupply at a later point.
    – cqx
    Commented Nov 11, 2021 at 17:52
  • or rather it only increments through _beforeTokenTransfer, so if I wanted to make an unsafe (but gas cheaper) mint function, I'm stuck Commented Nov 11, 2021 at 19:12

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.