From 55737074b1960bc6b4da77d344f582ae0ebbe0d9 Mon Sep 17 00:00:00 2001 From: Daniel Bejarano Date: Wed, 11 Oct 2023 08:36:02 -0600 Subject: [PATCH 1/2] prettier formatter integration --- .github/workflows/deploy.yml | 12 +- .gitignore | 1 + .prettierrc | 1 + CHANGELOG.md | 43 ++--- README.md | 14 +- package-lock.json | 27 +++ package.json | 8 + src/SUMMARY.md | 3 +- src/ch00-00-introduction.md | 91 +++++---- src/ch01-00-getting-started.md | 32 ++-- src/ch02-00-starknet-tooling.md | 12 +- src/ch02-02-compile-deploy-interact.md | 172 +++++++++--------- src/ch02-03-scarb.md | 54 +++--- src/ch02-07-01-01-million-dollar-homepage.md | 157 ++++++++-------- src/ch02-07-starknet-js.md | 67 +++---- src/ch02-08-starknet-react.md | 36 ++-- src/ch02-11-foundry-forge.md | 1 - src/ch02-12-foundry-cast.md | 2 +- src/ch03-00-architecture.md | 34 ++-- src/ch03-01-transactions.md | 5 +- src/ch03-02-sequencers.md | 89 +++++---- src/ch03-03-provers.md | 46 ++--- src/ch03-04-nodes.md | 70 +++---- src/ch03-05-layer-3.md | 80 ++++---- src/ch04-00-account-abstraction.md | 90 ++++----- src/ch04-01-accounts.md | 52 +++--- src/ch04-02-hello-account.md | 30 +-- src/ch04-03-standard-account.md | 132 +++++++------- src/ch04-04-01-multicaller.md | 16 +- src/ch04-04-02-multisig.md | 25 ++- src/ch05-01-basics.md | 58 +++--- src/ch05-02-01-number-theory.md | 42 ++--- src/ch05-02-02-geometry.md | 20 +- src/ch05-02-03-cryptographic-primitives.md | 21 +-- src/ch05-03-arithimization.md | 18 +- src/ch05-04-low-degree-testing.md | 66 +++---- src/ch05-05-fri-protocol.md | 12 +- ...07-01-trace-low-degree-extension-python.md | 26 +-- src/ch05-07-02-constraints-python.md | 12 +- src/ch05-07-03-fri-commitments-python.md | 12 +- src/ch05-07-04-query-phase-python.md | 20 +- ...5-08-01-trace-low-degree-extension-rust.md | 26 +-- src/ch05-08-02-constraints-rust.md | 12 +- src/ch05-08-03-fri-commitments-rust.md | 12 +- src/ch05-08-04-query-phase-rust.md | 20 +- src/title-page.md | 75 ++++---- 46 files changed, 931 insertions(+), 923 deletions(-) create mode 100644 .prettierrc create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3fc7ee116..4e810ac2c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,15 +12,15 @@ permissions: # Allow one concurrent deployment concurrency: - group: pages - cancel-in-progress: true + group: pages + cancel-in-progress: true jobs: deploy: runs-on: ubuntu-latest permissions: - contents: read # To push a branch - pages: write # To push to a GitHub Pages site + contents: read # To push a branch + pages: write # To push to a GitHub Pages site id-token: write # To update the deployment status steps: - uses: actions/checkout@v3 @@ -42,10 +42,10 @@ jobs: # - name: Deploy to GitHub Pages # id: deployment # uses: actions/deploy-pages@v2 - + - name: Rename book to public_html run: mv book public_html - name: scp upload to production site run: | - sshpass -p ${{ secrets.PROD_PASS }} scp -o 'StrictHostKeyChecking no' -r public_html/ ${{ secrets.PROD_USER }}@${{ secrets.PROD_IP }}:~/ \ No newline at end of file + sshpass -p ${{ secrets.PROD_PASS }} scp -o 'StrictHostKeyChecking no' -r public_html/ ${{ secrets.PROD_USER }}@${{ secrets.PROD_IP }}:~/ diff --git a/.gitignore b/.gitignore index 1e0a6a165..075f0f9a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ book target output +node_modules # Editors tmp files. *~ diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{} diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b481b0c5..4a821e076 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -262,10 +262,9 @@ All notable changes to this project will be documented in this file. See [standa ## [1.2.0](https://github.com/starknet-edu/starknetbook/compare/v1.1.81...v1.2.0) (2023-05-16) - ### Features -* add pragma and eliminate stork ✨ ([#102](https://github.com/starknet-edu/starknetbook/issues/102)) ([9b9c2d1](https://github.com/starknet-edu/starknetbook/commit/9b9c2d1ac3296671c500340e9f4db882f329c242)) +- add pragma and eliminate stork ✨ ([#102](https://github.com/starknet-edu/starknetbook/issues/102)) ([9b9c2d1](https://github.com/starknet-edu/starknetbook/commit/9b9c2d1ac3296671c500340e9f4db882f329c242)) ### [1.1.81](https://github.com/starknet-edu/starknetbook/compare/v1.1.80...v1.1.81) (2023-05-16) @@ -419,15 +418,14 @@ All notable changes to this project will be documented in this file. See [standa ### [1.1.6](https://github.com/starknet-edu/starknetbook/compare/v1.1.5...v1.1.6) (2023-04-10) - ### Bug Fixes -* typo ([cb5d950](https://github.com/starknet-edu/starknetbook/commit/cb5d950c7446d52f78179875a2565611f2c7ef94)) -* typo ([c6e07ec](https://github.com/starknet-edu/starknetbook/commit/c6e07ec75dc2d2f056fa7aa3f38525f2cb4d6d83)) -* typo ([f3da9e0](https://github.com/starknet-edu/starknetbook/commit/f3da9e0f0d83ee903c91b1e0af6998876afffbcf)) -* typo ([4a3112e](https://github.com/starknet-edu/starknetbook/commit/4a3112ed93371527b0343243ae88d8cd04f36ecc)) -* typos ([3d52039](https://github.com/starknet-edu/starknetbook/commit/3d52039c665bfbaf540b106ab52c11efe996c262)) -* typos ([0f3c7c7](https://github.com/starknet-edu/starknetbook/commit/0f3c7c7901af43a6c28536a34d00403539bd48ea)) +- typo ([cb5d950](https://github.com/starknet-edu/starknetbook/commit/cb5d950c7446d52f78179875a2565611f2c7ef94)) +- typo ([c6e07ec](https://github.com/starknet-edu/starknetbook/commit/c6e07ec75dc2d2f056fa7aa3f38525f2cb4d6d83)) +- typo ([f3da9e0](https://github.com/starknet-edu/starknetbook/commit/f3da9e0f0d83ee903c91b1e0af6998876afffbcf)) +- typo ([4a3112e](https://github.com/starknet-edu/starknetbook/commit/4a3112ed93371527b0343243ae88d8cd04f36ecc)) +- typos ([3d52039](https://github.com/starknet-edu/starknetbook/commit/3d52039c665bfbaf540b106ab52c11efe996c262)) +- typos ([0f3c7c7](https://github.com/starknet-edu/starknetbook/commit/0f3c7c7901af43a6c28536a34d00403539bd48ea)) ### [1.1.5](https://github.com/starknet-edu/starknetbook/compare/v1.1.4...v1.1.5) (2023-04-10) @@ -441,24 +439,23 @@ All notable changes to this project will be documented in this file. See [standa ## 1.1.0 (2023-04-04) - ### Features -* **buidl:** fix python tests ([533a338](https://github.com/starknet-edu/starknetbook/commit/533a3389dadd54794d8742083827aad7b265912b)) -* **camp 4:** faster hardhat tests ([d216d65](https://github.com/starknet-edu/starknetbook/commit/d216d65b646843acc9f9e14ae192dd057220dd13)) -* **camp_4:** release the beast ([fe543ef](https://github.com/starknet-edu/starknetbook/commit/fe543ef229c7268cfe3733016e2eef9d9e9e5e79)) - +- **buidl:** fix python tests ([533a338](https://github.com/starknet-edu/starknetbook/commit/533a3389dadd54794d8742083827aad7b265912b)) +- **camp 4:** faster hardhat tests ([d216d65](https://github.com/starknet-edu/starknetbook/commit/d216d65b646843acc9f9e14ae192dd057220dd13)) +- **camp_4:** release the beast ([fe543ef](https://github.com/starknet-edu/starknetbook/commit/fe543ef229c7268cfe3733016e2eef9d9e9e5e79)) ### Bug Fixes -* **buidl:** protostar + python ([6c56aad](https://github.com/starknet-edu/starknetbook/commit/6c56aadf0ffd522ada2e95587a3ce456d217d276)) -* **buidl:** update hardhat ([f8f5e1f](https://github.com/starknet-edu/starknetbook/commit/f8f5e1f147e6fff241c1c0913913266a1ff62b2b)) -* camp_1 readme typos ([03f4b22](https://github.com/starknet-edu/starknetbook/commit/03f4b22b06c0e721d0761714c907e4625821efa0)) -* camp_2 readme typos ([418fcbb](https://github.com/starknet-edu/starknetbook/commit/418fcbb94bf9e8340b9975f1c1f7d2fba935699d)) -* camp_3 readme typos ([5196e10](https://github.com/starknet-edu/starknetbook/commit/5196e109d0c97e257eff89dc8cc1d66c25be6434)) -* camp_4 readme typos ([547c66f](https://github.com/starknet-edu/starknetbook/commit/547c66f69a11b3632b14969e006c345b00782335)) -* camp_5 readme typos ([9e94295](https://github.com/starknet-edu/starknetbook/commit/9e94295846d2afc3bde113d9d049fae7d07b29b7)) -* fix broken link in camp_2 module ([#39](https://github.com/starknet-edu/starknetbook/issues/39)) ([8652b6f](https://github.com/starknet-edu/starknetbook/commit/8652b6f3f6c3a57593de9621c626359c1cdc5435)) +- **buidl:** protostar + python ([6c56aad](https://github.com/starknet-edu/starknetbook/commit/6c56aadf0ffd522ada2e95587a3ce456d217d276)) +- **buidl:** update hardhat ([f8f5e1f](https://github.com/starknet-edu/starknetbook/commit/f8f5e1f147e6fff241c1c0913913266a1ff62b2b)) +- camp_1 readme typos ([03f4b22](https://github.com/starknet-edu/starknetbook/commit/03f4b22b06c0e721d0761714c907e4625821efa0)) +- camp_2 readme typos ([418fcbb](https://github.com/starknet-edu/starknetbook/commit/418fcbb94bf9e8340b9975f1c1f7d2fba935699d)) +- camp_3 readme typos ([5196e10](https://github.com/starknet-edu/starknetbook/commit/5196e109d0c97e257eff89dc8cc1d66c25be6434)) +- camp_4 readme typos ([547c66f](https://github.com/starknet-edu/starknetbook/commit/547c66f69a11b3632b14969e006c345b00782335)) +- camp_5 readme typos ([9e94295](https://github.com/starknet-edu/starknetbook/commit/9e94295846d2afc3bde113d9d049fae7d07b29b7)) +- fix broken link in camp_2 module ([#39](https://github.com/starknet-edu/starknetbook/issues/39)) ([8652b6f](https://github.com/starknet-edu/starknetbook/commit/8652b6f3f6c3a57593de9621c626359c1cdc5435)) -# (2023-04-04) + +# (2023-04-04) diff --git a/README.md b/README.md index adca97687..464317064 100644 --- a/README.md +++ b/README.md @@ -23,16 +23,16 @@ $ cargo install mdbook --version 0.4.31 Follow these steps to build and view the book: 1. Build the book: - + ```bash -$ mdbook build +$ mdbook build ``` - + 2. After building, the compiled content will be located in the **`book`** subdirectory. 3. To view the content in a browser: - + ```bash -$ mdbook serve --open -``` +$ mdbook serve --open +``` + Tip: After making edits, simply refresh your browser to see the updates. - \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..6a05c5ae9 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,27 @@ +{ + "name": "starknetbook", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "devDependencies": { + "prettier": "3.0.3" + } + }, + "node_modules/prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 000000000..3e2421088 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "scripts": { + "format": "prettier . --write" + }, + "devDependencies": { + "prettier": "3.0.3" + } +} diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 0a38f9033..a9116c298 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -25,7 +25,6 @@ - [Foundry Forge: Testing 🚧](ch02-11-foundry-forge.md) - [Foundry Cast: Interacting with Starknet 🚧](ch02-12-foundry-cast.md) - ## Architecture - [Architecture](ch03-00-architecture.md) @@ -33,7 +32,7 @@ - [Sequencers](ch03-02-sequencers.md) - [Provers 🚧](ch03-03-provers.md) - [Nodes 🚧](ch03-04-nodes.md) - - [Layer 3 and App Chains 🚧 ](ch03-05-layer-3.md) + - [Layer 3 and App Chains 🚧 ](ch03-05-layer-3.md) - [Solidity Verifier 🚧](ch03-06-solidity-verifier.md) - [Decentralization 🚧](ch03-07-decentralization.md) diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index 9534dd7b5..c77f15611 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -2,9 +2,10 @@ ## Preamble -Historically, societal roles like currency, property rights, and social status titles have been governed by *protocols* and *registries*. Their value stems from a widely accepted understanding of their integrity. These functions have predominantly been overseen by centralized entities prone to challenges such as corruption, agency conflicts, and exclusion ([Eli Ben-Sasson, Bareli, Brandt, Volokh, 2023](https://hackmd.io/@Elibensasson/ryMelVulp)). +Historically, societal roles like currency, property rights, and social status titles have been governed by _protocols_ and _registries_. Their value stems from a widely accepted understanding of their integrity. These functions have predominantly been overseen by centralized entities prone to challenges such as corruption, agency conflicts, and exclusion ([Eli Ben-Sasson, Bareli, Brandt, Volokh, 2023](https://hackmd.io/@Elibensasson/ryMelVulp)). + +Satoshi's creation, Bitcoin, introduced a novel approach for these functions, termed an _integrity web_. This is an infrastructure for societal roles that: -Satoshi's creation, Bitcoin, introduced a novel approach for these functions, termed an *integrity web*. This is an infrastructure for societal roles that: 1. Is openly described by a public protocol. 2. Operates over a wide, inclusive, peer-to-peer network. 3. Distributes value fairly and extensively to maintain societal consensus on its integrity. @@ -29,20 +30,22 @@ Starknet bridges the gap between scalability and broad consensus. It integrates ## Starknet’s Mission -*Starknet’s mission is to allow individuals to freely implement and use any social function they desire.* +_Starknet’s mission is to allow individuals to freely implement and use any social function they desire._ ## Starknet’s Values Starknet's ethos is anchored in core principles ([Eli Ben-Sasson, Bareli, Brandt, Volokh, 2023](https://hackmd.io/@Elibensasson/ryMelVulp)): - **Lasting Broadness.** Starknet continuously resists power consolidation. Key points include: - - Broad power distribution underpins Starknet's legitimacy and must persist across operations and decision-making. While centralized operation may be necessary at times, it should be short-lived. - - Starknet's protocol and governance should always be open and transparent. - - Governance should bolster inclusivity, with a flexible structure that can evolve to ensure enduring inclusivity. + + - Broad power distribution underpins Starknet's legitimacy and must persist across operations and decision-making. While centralized operation may be necessary at times, it should be short-lived. + - Starknet's protocol and governance should always be open and transparent. + - Governance should bolster inclusivity, with a flexible structure that can evolve to ensure enduring inclusivity. - **Neutrality.** Starknet remains impartial to the societal functions it supports. - - The objectives and ethos of functions on Starknet lie with their creators. - - **Censorship resistance:** Starknet remains agnostic to the nature and meaning of user transactions. + + - The objectives and ethos of functions on Starknet lie with their creators. + - **Censorship resistance:** Starknet remains agnostic to the nature and meaning of user transactions. - **Individual Empowerment.** At its core, Starknet thrives on a well-informed and autonomous user base. This is achieved by fostering a culture rooted in its core mission and values, with a strong emphasis on education. @@ -50,34 +53,34 @@ Starknet's ethos is anchored in core principles ([Eli Ben-Sasson, Bareli, Brandt These are some key features of Starknet: -- Low Costs: Transactions on Starknet cost less than on Ethereum. - Future updates like Volition and EIP 4844 will make it even cheaper. +- Low Costs: Transactions on Starknet cost less than on Ethereum. + Future updates like Volition and EIP 4844 will make it even cheaper. -- Developer-Friendly: Starknet lets developers easily build - decentralized apps using its native language, Cairo. +- Developer-Friendly: Starknet lets developers easily build + decentralized apps using its native language, Cairo. -- Speed and Efficiency: Upcoming releases aim to make transactions - even faster and cheaper. +- Speed and Efficiency: Upcoming releases aim to make transactions + even faster and cheaper. -- CVM: Thanks to Cairo, Starknet runs on it´s own VM, called Cairo VM - (CVM), that allow us to innovate beyond the Ethereum Virtual Machine - (EVM) and create a new paradigm for decentralized applications. +- CVM: Thanks to Cairo, Starknet runs on it´s own VM, called Cairo VM + (CVM), that allow us to innovate beyond the Ethereum Virtual Machine + (EVM) and create a new paradigm for decentralized applications. Here some of them: -- Account Abstraction: Implemented at the protocol level, this - facilitates diverse signing schemes while ensuring user security and - self-custody of assets. +- Account Abstraction: Implemented at the protocol level, this + facilitates diverse signing schemes while ensuring user security and + self-custody of assets. -- Volition: Will be implemented on testnet during Q4 2023 will allow - developers to regulate data availability on Ethereum (L1) or on - Starknet (L2). Reducing L1 onchain data can radically reduce costs. +- Volition: Will be implemented on testnet during Q4 2023 will allow + developers to regulate data availability on Ethereum (L1) or on + Starknet (L2). Reducing L1 onchain data can radically reduce costs. -- Paymaster: StarkNet will allow users to choose how to pay for - transaction fee, follows the guidelines laid out in EIP 4337 and - allows the transaction to specify a specific contract, a - **Paymaster**, to pay for their transaction. Supports gasless - transactions, enhancing user accessibility. +- Paymaster: StarkNet will allow users to choose how to pay for + transaction fee, follows the guidelines laid out in EIP 4337 and + allows the transaction to specify a specific contract, a + **Paymaster**, to pay for their transaction. Supports gasless + transactions, enhancing user accessibility. ## Cairo: The Language of Starknet @@ -92,26 +95,26 @@ conveniently. ### Why Choose Cairo? -Cairo is designed for *Provable Computation,* a new paradigm that lets +Cairo is designed for _Provable Computation,_ a new paradigm that lets programs prove their correctness without re-running them. Here’s why it stands out: -- Purpose-Built: Designed specifically for smart contracts. +- Purpose-Built: Designed specifically for smart contracts. -- No EVM Limits: Goes beyond what the Ethereum Virtual Machine can do. +- No EVM Limits: Goes beyond what the Ethereum Virtual Machine can do. -- Flexibility: Uses traits for more flexibility than inheritance. +- Flexibility: Uses traits for more flexibility than inheritance. ## Governance The Starknet Foundation oversees Starknet’s governance. Its duties include: -- Managing Starknet’s development and operations +- Managing Starknet’s development and operations -- Overseeing the Starknet DAO, which enables community involvement +- Overseeing the Starknet DAO, which enables community involvement -- Setting rules to maintain network integrity +- Setting rules to maintain network integrity Our focus is on technical input and debate for improving the protocol. While we value all perspectives, it’s often the technical insights that @@ -120,13 +123,12 @@ steer us forward. Members can influence Starknet by voting on changes. Here’s the process: A new version is tested on the Goerli Testnet. Members then have six days to review it. A Snapshot proposal is made, and the community votes. -A majority of *YES* votes means an upgrade to the Mainnet. +A majority of _YES_ votes means an upgrade to the Mainnet. In short, governance is key to Starknet’s evolution. To propose an improvement, create a SNIP. - ### SNIP: StarkNet Improvement Proposals SNIP is short for StarkNet Improvement Proposal. It’s essentially a @@ -159,21 +161,18 @@ suggestions—they’re a roadmap. It’s beneficial for implementers to keep a list of the SNIPs they’ve executed. This transparency helps users gauge the state of a particular implementation or software library. - ## Learning Resources For deeper insights into Starknet and Cairo: -- [The Starknet Book](https://book.starknet.io): For mastering - Starknet +- [The Starknet Book](https://book.starknet.io): For mastering + Starknet -- [The Cairo Book](https://cairo-book.github.io/): For mastering Cairo +- [The Cairo Book](https://cairo-book.github.io/): For mastering Cairo -- [Starklings](https://github.com/shramee/starklings-cairo1): - Practical tutorials and examples +- [Starklings](https://github.com/shramee/starklings-cairo1): + Practical tutorials and examples ## Conclusion -In decentralized technology, Starknet offers a solution to challenges that previous systems encountered. It's based on established *protocols* and *registries*, following the initial concepts introduced by figures such as Satoshi. Through a specific mathematical method, Starknet seeks a balance between scalability and consensus. As this technology progresses, Starknet adheres to principles of inclusivity, neutrality, and user empowerment. It's poised for continuous adaptation and improvement in the field. - - +In decentralized technology, Starknet offers a solution to challenges that previous systems encountered. It's based on established _protocols_ and _registries_, following the initial concepts introduced by figures such as Satoshi. Through a specific mathematical method, Starknet seeks a balance between scalability and consensus. As this technology progresses, Starknet adheres to principles of inclusivity, neutrality, and user empowerment. It's poised for continuous adaptation and improvement in the field. diff --git a/src/ch01-00-getting-started.md b/src/ch01-00-getting-started.md index a5e5b284e..6b5a38c36 100644 --- a/src/ch01-00-getting-started.md +++ b/src/ch01-00-getting-started.md @@ -14,7 +14,6 @@ We will use the Starknet Remix Plugin to compile, deploy and interact with our s 4. After enabling, the Starknet logo appears on the left sidebar. Click it to interact with opened Cairo files. - ## Introduction to Starknet Smart Contracts The script below is a simple `Ownable` contract pattern written in Cairo for Starknet. It features: @@ -23,7 +22,7 @@ The script below is a simple `Ownable` contract pattern written in Cairo for Sta - A method to transfer ownership. - A method to check the current owner. - An event notification for ownership changes. - + ```rust use starknet::ContractAddress; @@ -41,7 +40,7 @@ mod Ownable { #[event] #[derive(Drop, starknet::Event)] enum Event { - OwnershipTransferred1: OwnershipTransferred1, + OwnershipTransferred1: OwnershipTransferred1, } #[derive(Drop, starknet::Event)] @@ -94,18 +93,18 @@ mod Ownable { The following is a brief description of the components in the contract. We will get into more details when we get deeper into Cairo so feel free to skip this section for now if you are not familiar with smart contract development. 1. **Dependencies and Interface**: - - **`starknet::ContractAddress`**: Represents a Starknet contract address. - - **`OwnableTrait`**: Specifies functions for transferring and getting ownership. + - **`starknet::ContractAddress`**: Represents a Starknet contract address. + - **`OwnableTrait`**: Specifies functions for transferring and getting ownership. 2. **Events**: - - **`OwnershipTransferred1`**: Indicates ownership change with previous and new owner details. + - **`OwnershipTransferred1`**: Indicates ownership change with previous and new owner details. 3. **Storage**: - - **`Storage`**: Holds the contract's state with the current owner's address. + - **`Storage`**: Holds the contract's state with the current owner's address. 4. **Constructor**: - - Initializes the contract with a starting owner. + - Initializes the contract with a starting owner. 5. **External Functions**: - - Functions for transferring ownership and retrieving the current owner's details. + - Functions for transferring ownership and retrieving the current owner's details. 6. **Private Methods**: - - **`only_owner`**: Validates if the caller is the current owner. + - **`only_owner`**: Validates if the caller is the current owner. ## Compilation Process @@ -150,9 +149,9 @@ Here's a step-by-step guide to deploying your smart contract on the development Post-deployment, Remix's terminal will send various logs. These logs provide crucial details, including: - - `transaction_hash`: The unique hash of the transaction. This hash can be used to track the transaction's status. - - `contract_address`: The address of the deployed contract. Use this address to interact with your contract. - - `calldata`: Contains the `init_owner` address fed to the constructor. +- `transaction_hash`: The unique hash of the transaction. This hash can be used to track the transaction's status. +- `contract_address`: The address of the deployed contract. Use this address to interact with your contract. +- `calldata`: Contains the `init_owner` address fed to the constructor. ```bash { @@ -168,7 +167,6 @@ Post-deployment, Remix's terminal will send various logs. These logs provide cru By following the above process, you successfully deploy your smart contract on the development network. - ## Interaction with the Contract With the contract now active on the development network, interaction becomes possible. Here's a guide to effectively interact with your contract on Starknet: @@ -177,7 +175,7 @@ With the contract now active on the development network, interaction becomes pos - Navigate to the "Starknet" tab. - Select the "Interact" option. - + 2. **Calling the `get_owner` Function** - Choose the `get_owner` function. Since this function doesn't require arguments, the calldata field remains blank. (This is a read function, hence calling it is termed as a "call".) @@ -219,7 +217,6 @@ For these transactions, the terminal logs will exhibit a "status" variable, indi You've now adeptly compiled, deployed, and interacted with your inaugural Starknet smart contract. Well done! - ## Deploying on Starknet Testnet After testing your smart contract on a development network, it's time to deploy it to the Starknet Testnet. Starknet Testnet is a public platform available for everyone, ideal for testing smart contracts and collaborating with fellow developers. @@ -255,11 +252,10 @@ You can monitor transaction hashes and addresses using any Starknet block explor These tools provide a visual representation of transactions and contract state alterations. Notably, when you alter the contract ownership using the `transfer_ownership` function, the event emitted by the contract appears in the block explorer. It's an effective method to track contract events. - ## Your Next Steps Decide your direction from the following choices: 1. **Deepen Your Starknet Knowledge**: For an extensive grasp of Starknet's inner workings and potential use cases, delve into Chapter 3 of the Starknet Book. This chapter details Starknet’s architectural nuances. Then go ahead from there. -2. **Dive into Cairo**: If you're more attuned to coding and wish to craft Starknet contracts, then Cairo is essential. It stands as Starknet's core contract language. Begin with Chapters 1-6 of the [Cairo Book](https://book.cairo-lang.org/title-page.html), ranging from basics in *Getting Started* to more advanced aspects such as *Enums and Pattern Matching*. Conclude by navigating to the [Starknet Smart Contracts chapter](https://book.cairo-lang.org/ch99-00-starknet-smart-contracts.html), ensuring you have a well-rounded understanding. \ No newline at end of file +2. **Dive into Cairo**: If you're more attuned to coding and wish to craft Starknet contracts, then Cairo is essential. It stands as Starknet's core contract language. Begin with Chapters 1-6 of the [Cairo Book](https://book.cairo-lang.org/title-page.html), ranging from basics in _Getting Started_ to more advanced aspects such as _Enums and Pattern Matching_. Conclude by navigating to the [Starknet Smart Contracts chapter](https://book.cairo-lang.org/ch99-00-starknet-smart-contracts.html), ensuring you have a well-rounded understanding. diff --git a/src/ch02-00-starknet-tooling.md b/src/ch02-00-starknet-tooling.md index c590916f8..5be9248fb 100644 --- a/src/ch02-00-starknet-tooling.md +++ b/src/ch02-00-starknet-tooling.md @@ -3,7 +3,7 @@ To make the most of this chapter, a basic grasp of the Cairo programming language is advised. We suggest reading chapters 1-6 of the [Cairo Book](https://book.cairo-lang.org/title-page.html), covering topics from -*Getting Started* to *Enums and Pattern Matching.* Follow this by +_Getting Started_ to _Enums and Pattern Matching._ Follow this by studying the [Starknet Smart Contracts chapter](https://book.cairo-lang.org/ch99-00-starknet-smart-contracts.html) in the same book. With this background, you’ll be well-equipped to @@ -20,14 +20,14 @@ solutions. In this chapter, you’ll explore: -- Frameworks: Build using Protostar or Hardhat +- Frameworks: Build using Protostar or Hardhat -- SDKs: Discover multi-language support through Starknet.js, - Starknet-rs, Starknet\_py, and Caigo +- SDKs: Discover multi-language support through Starknet.js, + Starknet-rs, Starknet_py, and Caigo -- Front-end Development: Use Starknet.js and React +- Front-end Development: Use Starknet.js and React -- Testing: Understand testing methods with Protostar and the Devnet +- Testing: Understand testing methods with Protostar and the Devnet By chapter’s end, you’ll have a complete grasp of Starknet’s toolset, enabling efficient dApp development. diff --git a/src/ch02-02-compile-deploy-interact.md b/src/ch02-02-compile-deploy-interact.md index 850bea3e7..b1ed182a3 100644 --- a/src/ch02-02-compile-deploy-interact.md +++ b/src/ch02-02-compile-deploy-interact.md @@ -129,7 +129,7 @@ transactions. Let’s demystify what goes on under the hood. Key Components: -1. **Private Key**: A 256-bit/32-byte/64-character (ignoring the *0x* +1. **Private Key**: A 256-bit/32-byte/64-character (ignoring the _0x_ prefix) hexadecimal key that is the cornerstone of your wallet’s security. @@ -150,83 +150,83 @@ To view the details of the previously created keystore file: Anatomy of the `keystore.json` File: ```json - { - "crypto": { - "cipher": "aes-128-ctr", - "cipherparams": { - "iv": "dba5f9a67456b121f3f486aa18e24db7" - }, - "ciphertext": "b3cda3df39563e3dd61064149d6ed8c9ab5f07fbcd6347625e081fb695ddf36c", - "kdf": "scrypt", - "kdfparams": { - "dklen": 32, - "n": 8192, - "p": 1, - "r": 8, - "salt": "6dd5b06b1077ba25a7bf511510ea0c608424c6657dd3ab51b93029244537dffb" - }, - "mac": "55e1616d9ddd052864a1ae4207824baac58a6c88798bf28585167a5986585ce6" - }, - "id": "afbb9007-8f61-4e62-bf14-e491c30fd09a", - "version": 3 - } +{ + "crypto": { + "cipher": "aes-128-ctr", + "cipherparams": { + "iv": "dba5f9a67456b121f3f486aa18e24db7" + }, + "ciphertext": "b3cda3df39563e3dd61064149d6ed8c9ab5f07fbcd6347625e081fb695ddf36c", + "kdf": "scrypt", + "kdfparams": { + "dklen": 32, + "n": 8192, + "p": 1, + "r": 8, + "salt": "6dd5b06b1077ba25a7bf511510ea0c608424c6657dd3ab51b93029244537dffb" + }, + "mac": "55e1616d9ddd052864a1ae4207824baac58a6c88798bf28585167a5986585ce6" + }, + "id": "afbb9007-8f61-4e62-bf14-e491c30fd09a", + "version": 3 +} ``` -- **`version`**: The version of the smart wallet implementation. +- **`version`**: The version of the smart wallet implementation. -- **`id`**: A randomly generated identification string. +- **`id`**: A randomly generated identification string. -- **`crypto`**: Houses all encryption details. +- **`crypto`**: Houses all encryption details. Inside **`crypto`**: -- **`cipher`**: Specifies the encryption algorithm used, which in this - case is AES-128-CTR. +- **`cipher`**: Specifies the encryption algorithm used, which in this + case is AES-128-CTR. - - **AES (Advanced Encryption Standard)**: A globally accepted - encryption standard. + - **AES (Advanced Encryption Standard)**: A globally accepted + encryption standard. - - **128**: Refers to the key size in bits, making it a 128-bit - key. + - **128**: Refers to the key size in bits, making it a 128-bit + key. - - **CTR (Counter Mode)**: A specific mode of operation for the AES - cipher. + - **CTR (Counter Mode)**: A specific mode of operation for the AES + cipher. -- **`cipherparams`**: Contains an Initialization Vector (IV), which - ensures that encrypting the same plaintext with the same key will - produce different ciphertexts. +- **`cipherparams`**: Contains an Initialization Vector (IV), which + ensures that encrypting the same plaintext with the same key will + produce different ciphertexts. - - **`iv` (Initialization Vector)**: A 16-byte hex string that - serves as a random and unique starting point for each encryption - operation. + - **`iv` (Initialization Vector)**: A 16-byte hex string that + serves as a random and unique starting point for each encryption + operation. -- **`ciphertext`**: This is the private key after encryption, securely - stored so that only the correct password can reveal it. +- **`ciphertext`**: This is the private key after encryption, securely + stored so that only the correct password can reveal it. -- **`kdf` and `kdfparams`**: KDF stands for Key Derivation Function. - This adds a layer of security by requiring computational work, - making brute-force attacks harder. +- **`kdf` and `kdfparams`**: KDF stands for Key Derivation Function. + This adds a layer of security by requiring computational work, + making brute-force attacks harder. - - **`dklen`**: The length (in bytes) of the derived key. Typically - 32 bytes. + - **`dklen`**: The length (in bytes) of the derived key. Typically + 32 bytes. - - **`n`**: A cost factor representing CPU/memory usage. A higher - value means more computational work is needed, thus increasing - security. + - **`n`**: A cost factor representing CPU/memory usage. A higher + value means more computational work is needed, thus increasing + security. - - **`p`**: Parallelization factor, affecting the computational - complexity. + - **`p`**: Parallelization factor, affecting the computational + complexity. - - **`r`**: Block size for the hash function, again affecting - computational requirements. + - **`r`**: Block size for the hash function, again affecting + computational requirements. - - **`salt`**: A random value that is combined with the password to - deter dictionary attacks. + - **`salt`**: A random value that is combined with the password to + deter dictionary attacks. -- **`mac` (Message Authentication Code)**: This is a cryptographic - code that ensures the integrity of the message (the encrypted - private key in this case). It is generated using a hash of both the - ciphertext and a portion of the derived key. +- **`mac` (Message Authentication Code)**: This is a cryptographic + code that ensures the integrity of the message (the encrypted + private key in this case). It is generated using a hash of both the + ciphertext and a portion of the derived key. ### Creating an Account Descriptor @@ -260,28 +260,28 @@ To see the details of your Account Descriptor, run: Here’s what a typical descriptor might look like: ```json - { - "version": 1, - "variant": { - "type": "braavos", - "version": 1, - "implementation": "0x5dec330eebf36c8672b60db4a718d44762d3ae6d1333e553197acb47ee5a062", - "multisig": { - "status": "off" - }, - "signers": [ - { - "type": "stark", - "public_key": "0x49759ed6197d0d385a96f9d8e7af350848b07777e901f5570b3dc2d9744a25e" - } - ] - }, - "deployment": { - "status": "deployed", - "class_hash": "0x3131fa018d520a037686ce3efddeab8f28895662f019ca3ca18a626650f7d1e", - "address": "0x6dcb489c1a93069f469746ef35312d6a3b9e56ccad7f21f0b69eb799d6d2821" +{ + "version": 1, + "variant": { + "type": "braavos", + "version": 1, + "implementation": "0x5dec330eebf36c8672b60db4a718d44762d3ae6d1333e553197acb47ee5a062", + "multisig": { + "status": "off" + }, + "signers": [ + { + "type": "stark", + "public_key": "0x49759ed6197d0d385a96f9d8e7af350848b07777e901f5570b3dc2d9744a25e" } - } + ] + }, + "deployment": { + "status": "deployed", + "class_hash": "0x3131fa018d520a037686ce3efddeab8f28895662f019ca3ca18a626650f7d1e", + "address": "0x6dcb489c1a93069f469746ef35312d6a3b9e56ccad7f21f0b69eb799d6d2821" + } +} ``` Note: The structure will differ if you use an Argent wallet. @@ -304,9 +304,9 @@ efficient. Deploying a smart contract on Starknet involves two steps: -- Declare your contract’s code. +- Declare your contract’s code. -- Deploy an instance of the declared code. +- Deploy an instance of the declared code. To get started, navigate to the `contracts/` directory in the [first chapter](https://github.com/starknet-edu/starknetbook/tree/main/chapters/book/modules/chapter_1/pages/contracts) @@ -323,7 +323,7 @@ section. ``` This creates a compiled contract in `target/dev/` as -"contracts\_Ownable.sierra.json" (in Chapter 2 of the book we will learn +"contracts_Ownable.sierra.json" (in Chapter 2 of the book we will learn more details about Scarb). With the smart contract compiled, we’re ready to declare it using @@ -350,7 +350,7 @@ There are three main options for RPC providers, sorted by ease of use: Starknet Book](https://book.starknet.io/chapter_4/node.html) or [Kasar](https://www.kasar.io/) for setup guides. -In this tutorial, we will use Alchemy. We can set the STARKNET\_RPC +In this tutorial, we will use Alchemy. We can set the STARKNET_RPC environment variable to make command invocations easier: ```bash @@ -388,7 +388,7 @@ Starknet. For example: Class hash declared: 0x04c70a75f0246e572aa2e1e1ec4fffbe95fa196c60db8d5677a5c3a3b5b6a1a8 ``` -You can think of this hash as the contract class’s *address.* Use a +You can think of this hash as the contract class’s _address._ Use a block explorer like [StarkScan](https://testnet.starkscan.co/class/0x04c70a75f0246e572aa2e1e1ec4fffbe95fa196c60db8d5677a5c3a3b5b6a1a8) to verify this hash on the blockchain. @@ -411,7 +411,7 @@ main components: 2. Any constructor arguments that the contract expects. -In our example, the constructor expects an *owner* address. You can +In our example, the constructor expects an _owner_ address. You can learn more about constructors in \[Chapter 12 of The Cairo Book\](). @@ -425,7 +425,7 @@ The command would look like this: Here’s a specific example with an actual class hash and constructor inputs (as the owner address use the address of your smart wallet so you -can invoke the transfer\_ownership function later): +can invoke the transfer_ownership function later): ```bash starkli deploy \ diff --git a/src/ch02-03-scarb.md b/src/ch02-03-scarb.md index 0198f20bf..267adcbc6 100644 --- a/src/ch02-03-scarb.md +++ b/src/ch02-03-scarb.md @@ -3,7 +3,7 @@ To make the most of this chapter, a basic grasp of the Cairo programming language is advised. We suggest reading chapters 1-6 of the [Cairo Book](https://book.cairo-lang.org/title-page.html), covering topics from -*Getting Started* to *Enums and Pattern Matching.* Follow this by +_Getting Started_ to _Enums and Pattern Matching._ Follow this by studying the [Starknet Smart Contracts chapter](https://book.cairo-lang.org/ch99-00-starknet-smart-contracts.html) in the same book. With this background, you’ll be well-equipped to @@ -47,12 +47,12 @@ Cairo packages, also referred to as "crates" in some contexts, are the building blocks of a Cairo project. Each package must follow several rules: -- A package must include a `Scarb.toml` file, which is Scarb’s - manifest file. It contains the dependencies for your package. +- A package must include a `Scarb.toml` file, which is Scarb’s + manifest file. It contains the dependencies for your package. -- A package must include a `src/lib.cairo` file, which is the root of - the package tree. It allows you to define functions and declare used - modules. +- A package must include a `src/lib.cairo` file, which is the root of + the package tree. It allows you to define functions and declare used + modules. Package structures might look like the following case where we have a package named `my_package`, which includes a `src` directory with the @@ -129,7 +129,7 @@ following: } In this instance, the `lib.cairo` file contains a module declaration -referencing *hello\_scarb*, which includes the *hello\_scarb.cairo* +referencing _hello_scarb_, which includes the _hello_scarb.cairo_ file’s implementation. For more on modules, imports, and the `lib.cairo` file, please refer to the subchapter on [imports in Chapter 2](https://book.starknet.io/chapter_2/imports.html). @@ -156,7 +156,7 @@ To remove the build artifacts and delete the target directory, use the Scarb facilitates the seamless management of dependencies for your Cairo packages. Here are two methods to add dependencies to your project: -- Edit Scarb.toml File +- Edit Scarb.toml File Open the Scarb.toml file in your project directory and locate the `[dependencies]` section. If it doesn’t exist, add it. To include a @@ -174,14 +174,14 @@ hash: After adding the dependency, remember to save the file. -- Use the scarb add Command +- Use the scarb add Command Alternatively, you can use the `scarb add` command to add dependencies to your project. Open your terminal and execute the following command: $ scarb add alexandria_math --git https://github.com/keep-starknet-strange/alexandria.git -This command will add the alexandria\_math dependency from the specified +This command will add the alexandria_math dependency from the specified Git repository to your project. To remove a dependency, you can use the `scarb rm` command. @@ -194,9 +194,9 @@ updated with the new dependency information. After dependencies are added to your project, you can start utilizing them in your Cairo code. -For example, let’s assume you have added the alexandria\_math +For example, let’s assume you have added the alexandria_math dependency. Now, you can import and utilize functions from the -alexandria\_math library in your `src/hello_scarb.cairo` file: +alexandria_math library in your `src/hello_scarb.cairo` file: // src/hello_scarb.cairo use alexandria_math::fibonacci; @@ -206,25 +206,25 @@ alexandria\_math library in your `src/hello_scarb.cairo` file: } In the above example, we import the fibonacci function from the -alexandria\_math library and utilize it in the main function. +alexandria_math library and utilize it in the main function. # Scarb Cheat Sheet Here’s a quick cheat sheet of some of the most commonly used Scarb commands: -- `scarb new `: Initialize a new project with the given - project name. +- `scarb new `: Initialize a new project with the given + project name. -- `scarb build`: Compile your Cairo code into Sierra code. +- `scarb build`: Compile your Cairo code into Sierra code. -- `scarb add --git `: Add a dependency to - your project from a specified Git repository. +- `scarb add --git `: Add a dependency to + your project from a specified Git repository. -- `scarb rm `: Remove a dependency from your project. +- `scarb rm `: Remove a dependency from your project. -- `scarb run