从 0 到 1 (持续更新)

Scarb v2.3.1 https://github.com/software-mansion/scarb
starknet-foundry v0.10.2 https://github.com/foundry-rs/starknet-foundry
OpenZeppelin v0.8.0-beta.0 https://github.com/OpenZeppelin/cairo-contracts

0x0 初始化项目,并创建测试账户

0x1 第一个智能合约-编写、测试、部署和调用

0x2 让合约可升级

0x3 给升级方法加权限控制

0x4 发行token(ERC20)[非components方式]

0x5 发行NFT(ERC721)[非components方式][有bug,待修复]

说明

本系列文章是站在巨人肩膀上,感谢社区,感谢开源教程。

微信:w5pand

Twitter:https://twitter.com/0xpand

一起学习交流

Cairo在快速迭代更新中

历史版本使用过程中,有一些不太方便的地方

本系列文章目前基于以下版本开发:

OpenZeppelin v0.8.0-beta.0

v0.7.0是最新稳定版本,但是不利于代码复用,使用中有诸多不便 v0.8.0开始支持Components components提供了一种乐高组合合约代码的方式,教程https://book.cairo-lang.org/zh-cn/ch99-01-05-00-components.html

<aside> 💡

Components: Lego-Like Building Blocks for Smart Contracts组件:用于智能合约的乐高式构建块

Developing contracts sharing a common logic and storage can be painful and bug-prone, as this logic can hardly be reused and needs to be reimplemented in each contract. But what if there was a way to snap in just the extra functionality you need inside your contract, separating the core logic of your contract from the rest?开发共享通用逻辑和存储的合约可能会很痛苦并且容易出现错误,因为这种逻辑很难重用,并且需要在每个合约中重新实现。但是,如果有一种方法可以将您需要的额外功能嵌入到您的合约中,将您的合约的核心逻辑与其他逻辑分开呢?

Components provide exactly that. They are modular add-ons encapsulating reusable logic, storage, and events that can be incorporated into multiple contracts. They can be used to extend a contract's functionality, without having to reimplement the same logic over and over again.

Think of components as Lego blocks. They allow you to enrich your contracts by plugging in a module that you or someone else wrote. This module can be a simple one, like an ownership component, or more complex like a full-fledged ERC20 token.将组件视为乐高积木。它们允许您通过插入您或其他人编写的模块来丰富您的合同。该模块可以是一个简单的模块,例如所有权组件,也可以是更复杂的模块,例如成熟的 ERC20 代币。

A component is a separate module that can contain storage, events, and functions. Unlike a contract, a component cannot be declared or deployed. Its logic will eventually be part of the contract’s bytecode it has been embedded in.组件是一个单独的模块,可以包含存储、事件和函数。与合约不同,组件不能被声明或部署。它的逻辑最终将成为它嵌入的合约字节码的一部分。

What's in a Component?组件中有什么?

A component is very similar to a contract. It can contain:组件与合约非常相似。它可以包含:

Unlike a contract, a component cannot be deployed on its own. The component's code becomes part of the contract it's embedded to.与合约不同,组件不能单独部署。组件的代码成为其嵌入的合约的一部分。

</aside>

Scarb v2.3.1

starknet-foundry v0.10.2

VScode 下载cairo1插件(可省略)

相关链接

Scarb https://github.com/software-mansion/scarb

Cairo https://github.com/starkware-libs/cairo/tree/main

Cairo book https://book.cairo-lang.org/title-page.html

Cairo book 社区翻译 https://book.cairo-lang.org/zh-cn/title-page.html

Straknet-by-example https://starknet-by-example.voyager.online/starknet-by-example.html

Straknet-by-example社区翻译 https://starknet-by-example.voyager.online/zh-cn/starknet-by-example.html

Starknet-foundry https://github.com/foundry-rs/starknet-foundry

Starknet-foundry book https://foundry-rs.github.io/starknet-foundry/

oppenzeppelin https://github.com/OpenZeppelin/cairo-contracts

oppenzeppelin book https://docs.openzeppelin.com/contracts-cairo/0.8.0-beta.1/

区块链浏览器

Starkscan - Starknet Block Explorer

Voyager - Starknet block explorer

Starknet Astro 社区知识库

Starknet Astro 社区知识库

WTF Academy Cairo教程

看板 | WTF Academy

看板 | WTF Academy