HeadlinesBriefing favicon HeadlinesBriefing.com

Solidity Super Keyword Explained

DEV Community •
×

Solidity developers use the super keyword to access a parent contract's overridden function implementation. Rather than discarding parent logic, super allows child contracts to extend it by adding their own code. This maintains the original behavior while introducing new functionality, a common pattern in object-oriented programming adapted for blockchain development.

Consider a Parent contract with an increment function. A Child contract can override this method, first calling super.increment() to execute the parent's logic (adding one to a counter), then applying its own logic (multiplying the counter by two). This ensures the inheritance chain executes properly without duplicating code.

The key difference lies in execution flow. super.functionName() follows the entire inheritance hierarchy, triggering all relevant parent implementations in order. Calling a parent directly (e.g., A.foo()) bypasses this chain, targeting only that specific contract. Developers must choose based on whether they need comprehensive parent logic or a targeted override.