Skip to content

Commit 1a5d518

Browse files
cptarturkkawulafranciszekjob
authored
Add sncast 101 to docs (#2761)
<!-- Reference any GitHub issues resolved by this PR --> Closes #2504 ## Introduced changes <!-- A brief description of the changes --> - ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md` --------- Co-authored-by: kkawula <57270771+kkawula@users.noreply.github.com> Co-authored-by: Franciszek Job <54181625+franciszekjob@users.noreply.github.com>
1 parent 6364553 commit 1a5d518

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
# `sncast` Overview
4444

4545
* [Outline](starknet/sncast-overview.md)
46+
* [`sncast` 101](starknet/101.md)
4647
* [Creating And Deploying Accounts](starknet/account.md)
4748
* [Importing Accounts](starknet/account-import.md)
4849
* [Declaring New Contracts](starknet/declare.md)

docs/src/starknet/101.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# `sncast` 101
2+
3+
This page showcases the standard usage of various `sncast` commands.
4+
For more in-depth explanation, please follow other guides from "sncast Overview".
5+
6+
## Create and Deploy an Account
7+
8+
First, create an account contract ready for deployment.
9+
This generates the account details but doesn't put it on the network yet.
10+
11+
<!-- { "ignored": true } -->
12+
```shell
13+
$ sncast account create \
14+
--name my_account \
15+
--network sepolia
16+
```
17+
18+
<details>
19+
<summary>Output:</summary>
20+
21+
```shell
22+
command: account create
23+
add_profile: --add-profile flag was not set. No profile added to snfoundry.toml
24+
address: 0x[..]
25+
max_fee: [..]
26+
message: Account successfully created. Prefund generated address with at least <max_fee> STRK tokens. It is good to send more in the case of higher demand.
27+
28+
After prefunding the address, run:
29+
sncast account deploy --network sepolia --name my_account
30+
```
31+
32+
</details>
33+
34+
After creating an account, send enough STRK tokens to the address to cover the price of the
35+
account creation.
36+
At least `max_fee` amount of fri (1 STRK = 10<sup>18</sup> fri) should be sent.
37+
38+
> 💡 **Tip**
39+
> On Sepolia, [this free faucet](https://starknet-faucet.vercel.app/) can be used to fund the account.
40+
41+
42+
Then, deploy the account using the command that was provided in output, below `After prefunding the address, run`:
43+
44+
<!-- { "ignored": true } -->
45+
```shell
46+
$ sncast account deploy \
47+
--network sepolia \
48+
--name my_account
49+
```
50+
51+
<details>
52+
<summary>Output:</summary>
53+
54+
```shell
55+
command: account deploy
56+
transaction_hash: 0x[..]
57+
58+
59+
To see invocation details, visit:
60+
transaction: https://sepolia.starkscan.co/tx/0x[..]
61+
```
62+
63+
</details>
64+
65+
Read more about accounts [here](./account-import.md)
66+
67+
> 💡 **Tip**
68+
> Existing accounts can be imported to `sncast` as well. See [Importing Accounts](./account-import.md) for more
69+
> information.
70+
71+
## Calling a Contract
72+
73+
Calling a contract doesn't require an account
74+
75+
```shell
76+
$ sncast call \
77+
--contract-address 0x00cd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 \
78+
--function get \
79+
--arguments '0x123' \
80+
--network sepolia
81+
```
82+
83+
<details>
84+
<summary>Output:</summary>
85+
86+
```shell
87+
command: call
88+
response: [0x0]
89+
```
90+
91+
</details>
92+
93+
[Read more about calling contracts here](./call.md)
94+
95+
## Sending a Transaction
96+
97+
To send a transaction, invoke a contract.
98+
99+
> 📝 **Note**
100+
> `--account` argument must be passed before invoke subcommand.
101+
> This is the same for other commands that send transactions as well.
102+
103+
```shell
104+
$ sncast \
105+
--account my_account \
106+
invoke \
107+
--contract-address 0x00cd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 \
108+
--function put \
109+
--arguments '0x123, 100' \
110+
--network sepolia
111+
```
112+
113+
> 💡 **Tip**
114+
> `--arguments` flag supports various kinds of Cairo types including
115+
> structs `--arguments 'MyStruct { a: 1, b: 2 }` and enums `--arguments MyEnum::Variant1`.
116+
>
117+
> See [Calldata Transformation](./calldata-transformation.md) for more details.
118+
119+
<details>
120+
<summary>Output:</summary>
121+
122+
```shell
123+
command: invoke
124+
transaction_hash: 0x[..]
125+
126+
To see invocation details, visit:
127+
transaction: https://sepolia.starkscan.co/tx/0x[..]
128+
```
129+
130+
</details>
131+
132+
[Read more about sending transactions here](./invoke.md)
133+
134+
## Declare a Contract
135+
136+
`sncast` uses `scarb` to build contracts and can find contracts by their names (part after `mod` for
137+
`#[starknet::contract]`).
138+
To declare a contract, simply pass it name to `sncast`.
139+
140+
> 💡 **Tip**
141+
> There is no need to run `scarb build` before declaration.
142+
> `sncast` will do that automatically
143+
144+
Create a project
145+
146+
```shell
147+
snforge new my_project
148+
```
149+
150+
From inside the `my_project` directory run
151+
152+
<!-- { "ignored": true, "package_name": "hello_starknet" } -->
153+
```shell
154+
$ sncast \
155+
--account my_account \
156+
declare \
157+
--contract-name HelloStarknet \
158+
--network sepolia
159+
```
160+
161+
<details>
162+
<summary>Output:</summary>
163+
164+
```shell
165+
command: declare
166+
class_hash: 0x[..]
167+
transaction_hash: 0x[..]
168+
169+
To see declaration details, visit:
170+
class: https://sepolia.starkscan.co/class/0x[..]
171+
transaction: https://sepolia.starkscan.co/tx/0x[..]
172+
```
173+
174+
</details>
175+
176+
[Read more about declaring contracts here](./declare.md)
177+
178+
## Deploy a Contract
179+
180+
Provide a class hash of your contract obtained from declaring it. It's the part after `class_hash:`.
181+
182+
<!-- { "ignored": true } -->
183+
```shell
184+
$ sncast \
185+
--account my_account \
186+
deploy \
187+
--class-hash 0x06813150c8b6256546fe2324b49f85021a207b6a383fc207d587f4bfacec00d8 \
188+
--network sepolia
189+
```
190+
191+
<details>
192+
<summary>Output:</summary>
193+
194+
```shell
195+
command: deploy
196+
contract_address: 0x[..]
197+
transaction_hash: 0x[..]
198+
199+
To see deployment details, visit:
200+
contract: https://sepolia.starkscan.co/contract/0x[..]
201+
transaction: https://sepolia.starkscan.co/tx/0x[..]
202+
```
203+
204+
</details>
205+
206+
[Read more about deploying contracts here](./deploy.md)

0 commit comments

Comments
 (0)