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

Add sncast 101 to docs #2761

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
# `sncast` Overview

* [Outline](starknet/sncast-overview.md)
* [`sncast` 101](starknet/101.md)
* [Creating And Deploying Accounts](starknet/account.md)
* [Importing Accounts](starknet/account-import.md)
* [Declaring New Contracts](starknet/declare.md)
Expand Down
201 changes: 201 additions & 0 deletions docs/src/starknet/101.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# `sncast` 101

This page showcases the standard usage of various `sncast` commands.
For more in-depth explanation, please follow other guides from "sncast Overview".

## Create and Deploy an Account

First, create an account.
This generates the account details but doesn't put it on the network yet.

```shell
sncast account create \
--name my_account \
--url https://starknet-sepolia.public.blastapi.io/rpc/v0_7
```

<details open>
<summary>Output:</summary>

```shell
command: account create
add_profile: --add-profile flag was not set. No profile added to snfoundry.toml
address: 0x01**************************
max_fee: 152899122468
message: Account successfully created. Prefund generated address with at least <max_fee> STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand.
```

> 📝 **Note**
> The `address` in the output has been redacted to avoid confusion.
> It will be visible when running the command locally.

</details>

After creating an account, send enough of STRK (or equivalent in ETH) tokens to the address to cover the price of the
account creation.
At least `max_fee` amount of fri (1 fri = 10<sup>-18</sup> strk) or ETH equivalent should be sent.

> 💡 **Tip**
> On Sepolia, [this free faucet](https://starknet-faucet.vercel.app/) can be used to fund the account.


Then, deploy the account

```shell
sncast account deploy \
--name my_account
--url https://starknet-sepolia.public.blastapi.io/rpc/v0_7
--fee-token strk
```

<details>
<summary>Output:</summary>

```shell
transaction_hash: 0x0**************

To see invocation details, visit:
transaction: https://sepolia.starkscan.co/tx/0x0**************

```

</details>

[Read more about accounts here](./account-import.md)

## Calling a Contract

Simply calling a contract doesn't require an account

```shell
sncast call \
--contract-address 0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d
--function decimals
--url https://starknet-sepolia.public.blastapi.io/rpc/v0_7
```

<details>
<summary>Output:</summary>

```shell
command: call
response: [0x12]
```

</details>

[Read more about calling contracts here](./call.md)

## Sending a Transaction

To send a transaction, invoke a contract.

> 📝 **Note**
> `--account` argument must be passed before invoke (subcommand).
> This is the same for other commands as well.

```shell
sncast \
--account my_account \
invoke \
--contract-address 0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d \
--function transfer \
--arguments '0x123, 100' \
--fee-token strk \
--url https://starknet-sepolia.public.blastapi.io/rpc/v0_7
```

> 💡 **Tip**
> `--arguments` flag supports various kinds of Cairo types including
> structs `--arguments 'MyStruct { a: 1, b: 2 }` and enums `--arguments MyEnum::Variant1`.
>
> See [calldata transformation](./calldata-transformation.md) for more details.

<details>
<summary>Output:</summary>

```shell
command: invoke
transaction_hash: 0x2**************

To see invocation details, visit:
transaction: https://sepolia.starkscan.co/tx/0x2**************
```

</details>

[Read more about sending transactions here](./invoke.md)

## Declare a Contract

`sncast` uses `scarb` to build contracts and can find contracts by their names (part after `mod` for
`#[starknet::contract]`).
To declare a contract, simply pass it name to `sncast`.

> 💡 **Tip**
> There is no need to run `scarb build` before declaration.
> `sncast` will do that automatically

Create a project

```shell
snforge init my_project
```

Within the `my_project` directory run

```shell
sncast \
--account my_account \
declare \
--contract-name HelloStarknet \
--fee-token strk \
--url https://starknet-sepolia.public.blastapi.io/rpc/v0_7
```

<details>
<summary>Output:</summary>

```shell
command: declare
class_hash: 0x1**************
transaction_hash: 0x2**************

To see declaration details, visit:
class: https://sepolia.starkscan.co/class/0x1**************
transaction: https://sepolia.starkscan.co/tx/0x2**************
```

</details>

[Read more about declaring contracts here](./declare.md)

## Deploy a Contract

Provide a class hash of your contract obtained from declaring it.

```shell
sncast \
--account my_account \
deploy \
--class-hash 0x06813150c8b6256546fe2324b49f85021a207b6a383fc207d587f4bfacec00d8 \
--fee-token strk \
--url https://starknet-sepolia.public.blastapi.io/rpc/v0_7
```

<details>
<summary>Output:</summary>

```shell
command: deploy
contract_address: 0x1**************
transaction_hash: 0x2**************

To see deployment details, visit:
contract: https://sepolia.starkscan.co/contract/0x1**************
transaction: https://sepolia.starkscan.co/tx/0x2**************
```

</details>

[Read more about deploying contracts here](./deploy.md)
Loading