upgrade-cairo-contracts

Replace Cairo contract class hashes on Starknet using OpenZeppelin's UpgradeableComponent.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/phpmac/foundry --skill upgrade-cairo-contracts-phpmac
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: upgrade-cairo-contracts
Source: https://github.com/phpmac/foundry/tree/main/.agents/skills/upgrade-cairo-contracts
Command: npx skills add https://github.com/phpmac/foundry --skill upgrade-cairo-contracts-phpmac

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill documents how to perform safe, atomic upgrades of Cairo smart contracts on Starknet by replacing contract class hashes, integrating OpenZeppelin's UpgradeableComponent, and ensuring storage and access-control compatibility so upgrades do not corrupt state or enable unauthorized code replacement.

Core Features & Use Cases

  • UpgradeableComponent integration: Guidance for declaring and wiring OpenZeppelin's UpgradeableComponent alongside an access control component and exposing an upgrade entrypoint that calls replace_class_syscall.
  • Access control best practices: Recommendations to guard upgrade functions with Ownable, RBAC, multisig, or governance to prevent unauthorized upgrades.
  • Storage compatibility and safety: Rules for preserving storage names and types, using substorage conventions, and avoiding major-version upgrades without review.
  • Testing upgrade paths: Steps to deploy V1/V2 on a local devnet, migrate state, run validation checks, and verify event emission and API compatibility.

Quick Start

Declare and deploy the new class hash on-chain, guard an external upgrade function with your access control, call the upgrade to replace the class hash, and validate state and behavior on a local devnet.

Frequently Asked Questions about upgrade-cairo-contracts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I upgrade Cairo smart contracts on Starknet?

You can upgrade Cairo smart contracts on Starknet by integrating OpenZeppelin's UpgradeableComponent to expose an upgrade entrypoint. This securely replaces the class hash to deploy new logic while preserving the contract address and storage.

How does replace_class_syscall work for Starknet contract upgrades?

The replace_class_syscall atomically updates a contract's class hash on Starknet to point to newly declared logic. It enables state-preserving upgrades without redeploying to a new address.

Do I need OpenZeppelin's UpgradeableComponent to upgrade contracts on Starknet?

Using OpenZeppelin's UpgradeableComponent is recommended for Starknet contract upgrades. It provides the standard logic to wire access control and safely execute the replace_class_syscall during an upgrade.

What is the best way to prevent unauthorized contract upgrades on Starknet?

The best way to prevent unauthorized Starknet contract upgrades is to guard the upgrade entrypoint with strict access control. You can use Ownable, RBAC, multisig, or governance mechanisms to restrict calls.

What are the storage compatibility limitations when upgrading Cairo contracts?

Storage compatibility limitations during Cairo contract upgrades require preserving storage names and types exactly. You must follow substorage conventions and avoid major-version upgrades without thorough review to prevent state corruption.

How do I test a Cairo contract upgrade on a local devnet?

To test a Cairo contract upgrade on a local devnet, deploy V1 and V2 classes, migrate the state, and call the upgrade function. Validate state integrity, event emission, and API compatibility afterward.