Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit 235d589

Browse files
authored
📝 apply best starkli practices (#189)
* Add starkli, scarb compiler version * Update first_contract.adoc Update this section according to starkli official website suggestion * Update first_contract.adoc
1 parent eaf87a7 commit 235d589

File tree

1 file changed

+58
-52
lines changed

1 file changed

+58
-52
lines changed

chapters/book/modules/chapter_1/pages/first_contract.adoc

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,51 @@ scarb --version # For Cairo code compilation
1313
starkli --version # To interact with Starknet
1414
----
1515

16+
== Find the compiler versions supported
17+
18+
We have to make sure that our Starkli compiler version match Scarb compiler version
19+
20+
To find the compiler versions supported by Starkli, execute:
21+
22+
[source,bash]
23+
----
24+
starkli declare --help
25+
----
26+
27+
You'll see a list of possible compiler versions under the `--compiler-version` flag.
28+
29+
[source,bash]
30+
----
31+
--compiler-version <COMPILER_VERSION>
32+
Statically-linked Sierra compiler version [possible values: [COMPILER VERSIONS]]]
33+
----
34+
35+
Note that the Scarb compiler version might not align with Starkli's supported versions. To check Scarb's version:
36+
37+
[source,bash]
38+
----
39+
scarb --version
40+
----
41+
42+
You'll see a list that contains scarb, cairo and sierra version.
43+
44+
[source,bash]
45+
----
46+
scarb <SCARB VERSION>
47+
cairo: <COMPILER VERSION>
48+
sierra: <SIERRA VERSION>
49+
----
50+
51+
If there's a mismatch, it is suggested that you install the version of Scarb that uses the compiler version that Starkli supports. You can find previous releases on https://github.com/software-mansion/scarb/releases[Scarb]'s GitHub repo.
52+
53+
To install a specific version, such as 0.6.1, run:
54+
55+
[source,bash]
56+
----
57+
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 0.6.1
58+
----
59+
60+
1661
== Smart Wallet Setup
1762

1863
A smart wallet comprises a Signer and an Account Descriptor. The Signer is a smart contract with a private key for signing transactions, while the Account Descriptor is a JSON file detailing the wallet's address and public key.
@@ -211,66 +256,32 @@ With the smart contract compiled, we're ready to declare it using Starkli. Befor
211256

212257
There are three main options for RPC providers, sorted by ease of use:
213258

214-
. *Starknet Sequencer's Gateway*: The quickest option and the one we'll use in this tutorial. It's the default for Starkli. As you dig deeper into Starknet, consider other options. The Sequencer's Gateway can get overloaded, causing transaction delays and it will be deprecated in the near future.
259+
. *Starknet Sequencer's Gateway*: The quickest option and it's the default for Starkli for now. The sequencer gateway is deprecated and will be disabled by StarkWare soon. You're strongly recommended to use a third-party JSON-RPC API provider like Infura, Alchemy, or Chainstack.
215260
. *Infura or Alchemy*: A step up in complexity. You'll need to set up an API key and choose an endpoint. For Infura, it would look like `https://starknet-goerli.infura.io/v3/<API_KEY>`. Learn more in the https://docs.infura.io/networks/starknet/how-to/choose-a-network[Infura documentation].
216261
. *Your Own Node*: For those who want full control. It's the most complex but offers the most freedom. Check out https://book.starknet.io/chapter_4/node.html[Chapter 4 of the Starknet Book] or https://www.kasar.io/[Kasar] for setup guides.
217262

218-
=== Declaring Your Contract
219-
220-
Run this command to declare your contract using the default Starknet Sequencer's Gateway:
263+
In this tutorial, we will use Alchemy. We can set the STARKNET_RPC environment variable to make command invocations easier:
221264

222265
[source,bash]
223266
----
224-
starkli declare target/dev/contracts_Ownable.sierra.json --network=goerli-1 --compiler-version=2.1.0
267+
export STARKNET_RPC="https://starknet-goerli.g.alchemy.com/v2/<API_KEY>"
225268
----
226269

227-
The `--network` and `--compiler-version` flags are critical for successful smart contract declaration and deployment with Starkli.
228-
229-
* The `--network` flag allows you to specify the target blockchain network, like "mainnet."
230-
* The `--compiler-version` flag lets you set the version of the Sierra compiler used to compile your contract.
231-
232-
To find the compiler versions supported by Starkli, execute:
233-
234-
[source,bash]
235-
----
236-
starkli declare --help
237-
----
238-
239-
You'll see a list of possible compiler versions under the `--compiler-version` flag.
240-
241-
[source,bash]
242-
----
243-
--compiler-version <COMPILER_VERSION>
244-
Statically-linked Sierra compiler version [possible values: [COMPILER VERSIONS]]]
245-
----
270+
=== Declaring Your Contract
246271

247-
Note that the Scarb compiler version might not align with Starkli's supported versions. To check Scarb's version:
272+
Run this command to declare your contract using the default Starknet Sequencer's Gateway:
248273

249274
[source,bash]
250275
----
251-
scarb --version
276+
starkli declare target/dev/contracts_Ownable.sierra.json
252277
----
253278

254-
If there's a mismatch, it is suggested that you install the version of Scarb that uses the compiler version that Starkli supports. You can find previous releases on https://github.com/software-mansion/scarb/releases[Scarb]'s GitHub repo.
255-
256-
To install a specific version, such as 0.6.1, run:
279+
According to the STARKNET_RPC url, starkli can recognize the target blockchain network, in this case "goerli", so it is not necessary explicitly specify it.
257280

258-
[source,bash]
259-
----
260-
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 0.6.1
261-
----
281+
Unless you're working with custom networks where it's infeasible for Starkli to detect the right compiler version, you shouldn't need to manually choose a version with `--network` and `--compiler-version`.
262282

263283
If you encounter an "Error: Invalid contract class," it likely means your Scarb's compiler version is incompatible with Starkli. Follow the steps above to align the versions. Starkli usually supports compiler versions accepted by mainnet, even if Scarb's latest version is not yet compatible.
264284

265-
If you're using third-party providers like Infura or Alchemy for your Remote Procedure Call (RPC), the declaration command would be modified to include the `--rpc` flag.
266-
267-
[source,bash]
268-
----
269-
starkli declare target/dev/contracts_Ownable.sierra.json \
270-
--rpc=https://starknet-goerli.infura.io/v3/<API_KEY> \
271-
--compiler-version=2.1.0
272-
----
273-
274285
After running the command, you'll receive a contract class hash. This unique hash serves as the identifier for your contract class within Starknet. For example:
275286

276287
[source,bash]
@@ -304,8 +315,7 @@ The command would look like this:
304315
----
305316
starkli deploy \
306317
<CLASS_HASH> \
307-
<CONSTRUCTOR_INPUTS> \
308-
--network=goerli-1
318+
<CONSTRUCTOR_INPUTS>
309319
----
310320

311321
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):
@@ -314,8 +324,7 @@ Here's a specific example with an actual class hash and constructor inputs (as t
314324
----
315325
starkli deploy \
316326
0x04c70a75f0246e572aa2e1e1ec4fffbe95fa196c60db8d5677a5c3a3b5b6a1a8 \
317-
0x02cdAb749380950e7a7c0deFf5ea8eDD716fEb3a2952aDd4E5659655077B8510 \
318-
--network=goerli-1
327+
0x02cdAb749380950e7a7c0deFf5ea8eDD716fEb3a2952aDd4E5659655077B8510
319328
----
320329

321330
After executing the command and entering your password, you should see output like the following:
@@ -344,8 +353,7 @@ The `call` command enables you to query a smart contract function without sendin
344353
----
345354
starkli call \
346355
<CONTRACT_ADDRESS> \
347-
get_owner \
348-
--network=goerli-1
356+
get_owner
349357
----
350358

351359
Replace `<CONTRACT_ADDRESS>` with the address of your contract. The command will return the owner's address, which was initially set during the contract's deployment:
@@ -366,8 +374,7 @@ You can modify the contract's state using the `invoke` command. For example, let
366374
starkli invoke \
367375
<CONTRACT_ADDRESS> \
368376
transfer_ownership \
369-
<NEW_OWNER_ADDRESS> \
370-
--network=goerli-1
377+
<NEW_OWNER_ADDRESS>
371378
----
372379

373380
Replace `<CONTRACT_ADDRESS>` with the address of the contract and `<NEW_OWNER_ADDRESS>` with the address you want to transfer ownership to. If the smart wallet you're using isn't the contract's owner, an error will appear. Note that the initial owner was set when deploying the contract:
@@ -394,8 +401,7 @@ To verify that the ownership has successfully transferred, you can call the `get
394401
----
395402
starkli call \
396403
<CONTRACT_ADDRESS> \
397-
get_owner \
398-
--network=goerli-1
404+
get_owner
399405
----
400406

401407
If the function returns the new owner's address, the transfer was successful.

0 commit comments

Comments
 (0)