Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quickstart refactor #1480

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
14 changes: 13 additions & 1 deletion .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,18 @@ RewriteRule ^documentation/getting_started/unit_tests/$ /quick-start/environment
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^documentation/tools/CLI/starknet\-compiler\-options/$ /cli/starknet-compiler-options/? [R=301,L]

RewriteRule ^tools/starknet\-book/$ https://docs.starknet.io/? [R=301,L]
RewriteRule ^tools/starknet\-book/$ / [R=301,L]

RewriteRule ^documentation/architecture_and_concepts/Smart_Contracts/system-calls/$ /architecture-and-concepts/smart-contracts/system-calls-cairo1/? [R=301,L]

RewriteRule ^/quick-start/declare-a-smart-contract/$ /quick-start/overview/? [R=301,L]

RewriteRule ^/quick-start/deploy-a-smart-contract/$ /quick-start/overview/? [R=301,L]

RewriteRule ^/quick-start/interact-with-a-smart-contract/$ /quick-start/overview/? [R=301,L]

RewriteRule ^/quick-start/set-up-an-account/$ /quick-start/overview/? [R=301,L]

RewriteRule ^/quick-start/deploy-interact-with-a-smart-contract-remix/$ /quick-start/overview/? [R=301,L]

RewriteRule ^/quick-start/using_devnet/$ /quick-start/devnet/? [R=301,L]
5 changes: 1 addition & 4 deletions components/Starknet/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
About Starknet

* xref:index.adoc[]
// * xref:notational-conventions.adoc[]
* xref:index.adoc[]
6 changes: 3 additions & 3 deletions components/Starknet/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ specialized programming language.
[pass]
++++
<div class="home-cta-container">
<a href="https://docs.starknet.io/documentation/quick_start/environment_setup/" class="home-cta home-cta-first" id="cta1">
<a href="/quick-start/overview/" class="home-cta home-cta-first" id="cta1">
<div class="image-container">
<img src="_images/developers.svg" style="filter: none; border-radius: 0px;" class="cta-image" id="img_1">
</div>
Expand All @@ -21,7 +21,7 @@ specialized programming language.
<p class="chakra-card__body css-jintet" id="text2"><b>Explore ></b></p>
</a>

<a href="https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/header/" class="home-cta" id="cta2">
<a href="/architecture-and-concepts/accounts/introduction/" class="home-cta" id="cta2">
<div class="image-container">
<img src="_images/how_SN_works.svg" style="filter: none; border-radius: 0px;" class="cta-image" id="img_2">
</div>
Expand All @@ -30,7 +30,7 @@ specialized programming language.
<p class="chakra-card__body css-jintet" id="text4"><b>Explore ></b></p>
</a>

<a href="https://docs.starknet.io/documentation/starknet_versions/version_notes/" class="home-cta" id="cta3">
<a href="starknet-versions/version-notes/" class="home-cta" id="cta3">
<div class="image-container">
<img src="_images/roadmap.svg" style="filter: none; border-radius: 0px;" class="cta-image" id="img_3">
</div>
Expand Down
12 changes: 6 additions & 6 deletions components/Starknet/modules/quick-start/nav.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
* Quickstart
** xref:environment-setup.adoc[Setting up your environment]
** xref:set-up-an-account.adoc[Setting up an account]
** xref:declare-a-smart-contract.adoc[Declaring a smart contract]
** xref:deploy-a-smart-contract.adoc[Deploying a smart contract]
** xref:interact-with-a-smart-contract.adoc[Interacting with a smart contract]
** xref:using_devnet.adoc[]
** xref:quick-start:overview.adoc[Overview]
** xref:quick-start:environment-setup.adoc[Setting up your environment]
** xref:quick-start:compiling-hellostarknet.adoc[Compiling `HelloStarknet`]
** xref:quick-start:devnet.adoc[Declaring, deploying, and interacting with `HelloStarknet` locally]
** xref:quick-start:sepolia.adoc[Deploying and interacting with `HelloStarknet` on Sepolia]
** xref:quick-start:next-steps.adoc[Recommended next steps]
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
= Compiling the `HelloStarknet` contract

== Introduction

Welcome to the second installment of the "Hello, Starknet!" quickstart series, the official tutorial for starting your journey as a Starknet developer! 🚀

Before a contract can be deployed on Starknet, its compiled code needs to be submitted to the network (also known as _declaring_ it). This installment of the series will therefore walk you though compiling Scarb's default `HelloStarknet` contract, which will be used throughout the following installments.

[TIP]
====
To learn more about Starknet smart contracts, see the xref:architecture-and-concepts:smart-contracts/contract-classes.adoc[Contracts section].
====

== Generating `HelloStarknet`

Scarb's default `HelloStarknet` contract can be generated by simply running:

[source,terminal]
----
scarb new hello_starknet
----

and selecting to set up the `Starknet Foundry (default)` test runner.

For the purpose of this tutorial, you can ignore all files in the `hello_starknet` directory other than `hello_starknet/src/lib.cairo`, which holds the contract's code:

[#example-cairo-contract]
[source,cairo]
----
/// Interface representing `HelloContract`.
/// This interface allows modification and retrieval of the contract balance.
#[starknet::interface]
pub trait IHelloStarknet<TContractState> {
/// Increase contract balance.
fn increase_balance(ref self: TContractState, amount: felt252);
/// Retrieve contract balance.
fn get_balance(self: @TContractState) -> felt252;
}

/// Simple contract for managing balance.
#[starknet::contract]
mod HelloStarknet {
use core::starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};

#[storage]
struct Storage {
balance: felt252,
}

#[abi(embed_v0)]
impl HelloStarknetImpl of super::IHelloStarknet<ContractState> {
fn increase_balance(ref self: ContractState, amount: felt252) {
assert(amount != 0, 'Amount cannot be 0');
self.balance.write(self.balance.read() + amount);
}

fn get_balance(self: @ContractState) -> felt252 {
self.balance.read()
}
}
}
----

As its comments read, this is a simple contract with two basic functions:

* `get_balance`, which reads the contract's current balance from storage.
* `increase_balance`, which reads the contract's current balance from storage, increases it by `amount` and writes the new balance to storage.

== Compiling `HelloStarknet`

To compile the `HelloStarknet` contract, navigate into the newly created `hello_starknet` directory and run:

[source,terminal]
----
scarb build
----

[NOTE]
====
The first time a project is built, some components of Scarb are compiled locally with the Rust toolchain. This process may take a few minutes, but will not happen in subsequent builds.
====

The compiled contract should now be saved inside the `hello_starknet/target/dev/` directory as `hello_starknet_HelloStarknet.contract_class.json`.

This file was deleted.

This file was deleted.

Loading