Interfaces

Starting from version 3.x.x, OpenZeppelin Contracts for Cairo interfaces have been separated from their implementation modules into a dedicated package called openzeppelin_interfaces. This architectural change brings several important benefits:

Decoupled Dependencies

The main motivation behind this separation is to decouple dependencies among packages when only interfaces are needed. For example, if a project only needs to interact with an ERC20 contract but doesn’t need to implement one, it can depend solely on the interfaces package without pulling in the full implementation.

[dependencies]
openzeppelin_interfaces = "2.1.0"
The version of the interfaces package is independent from the version of the implementation packages. The current umbrella version is v3.0.0-alpha.1, and it depends on the openzeppelin_interfaces package v2.1.0.

Stable Versioning

The interfaces package follows its own versioning scheme, independent from the implementation packages. Since interfaces are meant to be stable and rarely change, the major version of the interfaces package won’t be updated as frequently as the implementation packages.

This stability means that:

  • Dependencies can remain compatible for longer periods

  • Breaking changes in implementations won’t force interface updates

  • Projects depending only on interfaces are less likely to face version conflicts

Usage

The interfaces package provides three main types of traits that can be imported directly from their respective modules:

Interface Traits

Standard interface traits that define the contract’s functions:

use openzeppelin_interfaces::erc20::IERC20;
use openzeppelin_interfaces::erc721::IERC721;

Dispatchers

Contract dispatchers for interacting with deployed contracts:

use openzeppelin_interfaces::erc20::IERC20Dispatcher;
use openzeppelin_interfaces::erc721::IERC721Dispatcher;

ABI Traits

Complete external ABI definition of a given component/contract:

use openzeppelin_interfaces::erc20::ERC20ABI;
use openzeppelin_interfaces::erc721::ERC721ABI;

This modular approach provides a cleaner and more maintainable way to work with OpenZeppelin contracts, especially in larger projects with multiple dependencies.