← 返回
开发者工具 中文

Setup Cairo Contracts

Set up a Cairo smart contract project with OpenZeppelin Contracts for Cairo on Starknet. Use when users need to: (1) create a new Scarb/Starknet project, (2)...
使用OpenZeppelin Cairo合约库在Starknet上设置Cairo智能合约项目。适用于用户需要:(1)创建新的Scarb/Starknet项目,(2)...
samledger67-dotcom
开发者工具 clawhub v1.0.1 2 版本 100000 Key: 无需
★ 0
Stars
📥 493
下载
💾 8
安装
2
版本
#latest

概述

Cairo Setup

Project Scaffolding

Install toolchain and create a project:

curl --proto '=https' --tlsv1.2 -sSf https://sh.starkup.sh | sh
scarb new my_project --test-runner=starknet-foundry

This scaffolds a complete Starknet project with snforge testing preconfigured.

OpenZeppelin Dependencies

Look up the current version from https://docs.openzeppelin.com/contracts-cairo before adding. Add to Scarb.toml:

Full library (umbrella package):

[dependencies]
openzeppelin = "<VERSION>"

Individual packages (faster builds — only compiles what you use):

[dependencies]
openzeppelin_token = "<VERSION>"
openzeppelin_access = "<VERSION>"

Available individual packages: openzeppelin_access, openzeppelin_account, openzeppelin_finance, openzeppelin_governance, openzeppelin_interfaces, openzeppelin_introspection, openzeppelin_merkle_tree, openzeppelin_presets, openzeppelin_security, openzeppelin_token, openzeppelin_upgrades, openzeppelin_utils.

> openzeppelin_interfaces and openzeppelin_utils are versioned independently. Check the docs for their specific versions. All other packages share the same version.

Import Conventions

The import path depends on which dependency is declared:

  • Umbrella package (openzeppelin = "..."): use openzeppelin:: as the root
  • Individual packages (openzeppelin_token = "..."): use the package name as the root
// Individual packages
use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl};
use openzeppelin_access::ownable::OwnableComponent;
use openzeppelin_upgrades::UpgradeableComponent;

// Umbrella package equivalents
use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::upgrades::UpgradeableComponent;

Components are integrated via the component! macro, embedded impls, and substorage:

component!(path: ERC20Component, storage: erc20, event: ERC20Event);

#[abi(embed_v0)]
impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl<ContractState>;
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;

> Storage collision warning: When composing multiple components, #[substorage(v0)] flattens component storage into the contract's namespace. If two components use the same internal storage variable names, they will silently share the same storage slot, causing state corruption. Review the source of each component you compose to verify there are no naming conflicts across components.

版本历史

共 2 个版本

  • v1.0.1 当前
    2026-05-01 20:22 安全 安全
  • v1.0.0
    2026-03-20 02:29 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

data-analysis

Financial Analysis Agent

samledger67-dotcom
面向AI智能体的财务分析技能,涵盖差异分析、现金流预测、月结自动化、CFO评述生成及13周现金流等内容。
★ 2 📥 1,583
developer-tools

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 68 📥 180,347
developer-tools

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 921 📥 185,826