Ankr.

Post

Share your knowledge.

GMAIL.
Jun 12, 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)

  • Polygon Miden
  • MATIC
  • dApp
1
3
Share
Comments
.

Answers

3
Protocol Dev.
Jun 12 2025, 12:47

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)

0
Official Answer
Comments
.
Protocol Dev.
Jun 17 2025, 12:25

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:

Protocol Dev.
Aug 5 2025, 06:03

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

GMAIL.
Jun 12 2025, 11:53

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
.
Email 50.
Aug 15 2025, 11:29

Generative AI: Creation of content through advanced AI models is transforming content generation, automation, and design.

Quantum Computing: Expected to revolutionize cryptography, drug discovery, and problem-solving for complex systems.

Augmented Reality (AR) & Virtual Reality (VR): New immersive experiences in gaming, training, and consumer applications.

0
Comments
.
Email 50.
Aug 15 2025, 11:30

Quantum Computing: Expected to revolutionize cryptography, drug discovery, and problem-solving for complex systems.

Do you know the answer?

Please log in and share it.

Community created on Polygon network

212Posts159Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

Gain Reputation Points & Get Rewards for Helping the Sui Community Grow.