Peera.

Post

Share your knowledge.

0xfbbe...7709.
Mar 06, 2025
Expert Q&A

Counter.sol not found in Openzeppelin Contracts

What is the replacement for Counter.sol in Openzeppelin contracts? I get this error when I try to run my contract:

lib/openzeppelin-contracts/contracts/utils/Counters.sol": No such file or directory (os error 2)

  • discussion
  • expert q&a
1
2
Share
Comments
.

Answers

2
0x67fc...27ac.
Mar 6 2025, 09:13

It has been removed in openzeppelin v5 and most likely not coming back. You can either downgrade OZ version to 4.x, which is not recommended since a lot of patches have been merged since then fixing various vulnurabilities, or you can replace counter with something else, in most cases a single variable will do the trick. For more details I'll advise to check out the PR which removed Counters.sol from OZ codebase - it contains the reasoning behind this move and different strategies how one can move on without it

1
Comments
.
0xfbbe...7709.
Mar 7 2025, 03:40

Oh ok, thanks a lot for the heads up. Will check the repo out now

0
Comments
.

Do you know the answer?

Please log in and share it.

Peera is a decentralized questions and answers protocol for Web3 where users can organize and store their interests and skills, creating a common community platform

207Posts336Answers
We use cookies to ensure you get the best experience on our website.
More info