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 data transformer examples to docs #2682

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
10 changes: 5 additions & 5 deletions crates/sncast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ $ sncast --url http://127.0.0.1:5050 \
invoke \
--contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \
--function "some_function" \
--calldata 1 2 3
--arguments '0x1, 0x2, 0x3'
kkawula marked this conversation as resolved.
Show resolved Hide resolved
```

<details>
Expand All @@ -133,7 +133,7 @@ With arguments taken from `snfoundry.toml` file (default profile name):
$ sncast invoke \
--contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \
--function "some_function" \
--calldata 1 2 3
--arguments '0x1, 0x2, 0x3'
```

<details>
Expand All @@ -153,7 +153,7 @@ $ sncast --url http://127.0.0.1:5050 \
call \
--contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \
--function "some_function" \
--calldata 1 2 3
--arguments '0x1, 0x2, 0x3'
```

<details>
Expand All @@ -172,8 +172,8 @@ With arguments taken from `snfoundry.toml` file (default profile name):
```shell
$ sncast call \
--contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \
--function some_function \
--calldata 1 2 3
--function "some_function" \
--arguments '0x1, 0x2, 0x3'
```

<details>
Expand Down
4 changes: 2 additions & 2 deletions docs/src/projects/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ $ sncast --profile myprofile \
call \
--contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \
--function get \
--calldata 0x0 \
--arguments '0x0' \
--block-id latest
```

Expand Down Expand Up @@ -91,7 +91,7 @@ With this, there's no need to include the `--profile` argument when using `sncas
$ sncast call \
--contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \
--function get \
--calldata 0x0 \
--arguments '0x0' \
--block-id latest
```

Expand Down
19 changes: 10 additions & 9 deletions docs/src/starknet/call.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ For a detailed CLI description, see the [call command reference](../appendix/snc
$ sncast \
call \
--url http://127.0.0.1:5050 \
--contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \
--function "some_function" \
--calldata 1 2 3
--contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \
--function "balance_of" \
--arguments '0x0554d15a839f0241ba465bb176d231730c01cf89cdcb95fe896c51d4a6f4bb8f'
```

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

```shell
command: call
response: [0x1, 0x23, 0x4]
response: [0x1, 0x0]
```
</details>
<br>
Expand All @@ -44,17 +44,18 @@ You can call a contract at the specific block by passing `--block-id` argument.

```shell
$ sncast call \
--contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \
--function "some_function" \
--calldata 1 2 3 \
--block-id 1234
--url http://127.0.0.1:5050 \
--contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \
--function "balance_of" \
--arguments '0x0554d15a839f0241ba465bb176d231730c01cf89cdcb95fe896c51d4a6f4bb8f' \
--block-id 77864
```

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

```shell
command: call
response: [0x1, 0x23]
response: [0x0, 0x0]
```
</details>
17 changes: 9 additions & 8 deletions docs/src/starknet/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ You can, however, overwrite their values by supplying them as flags directly to
Let's use `sncast` to call a contract's function:

```shell
$ sncast --account myuser \
call \
$ sncast call \
--url http://127.0.0.1:5050 \
--contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \
--function get \
--calldata 0x0 \
--contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \
--function "pokemon" \
--arguments '"Charizard"' \
--block-id latest
```

Expand All @@ -42,7 +41,7 @@ $ sncast --account myuser \

```shell
command: call
response: [0x0]
response: [0x0, 0x0, 0x43686172697a617264, 0x9, 0x0, 0x0, 0x41a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf]
```
</details>
<br>
Expand All @@ -51,14 +50,16 @@ response: [0x0]
> In the above example we supply `sncast` with `--account` and `--url` flags. If `snfoundry.toml` is present, and have these properties set, values provided using these flags will override values from `snfoundry.toml`. Learn more about `snfoundry.toml` configuration [here](../projects/configuration.md#sncast).


### Calldata
### Arguments and Calldata
kkawula marked this conversation as resolved.
Show resolved Hide resolved

Some `sncast` commands (namely `call`, `deploy` and `invoke`) allow passing *calldata* - a series of arguments to perform an action with on blockchain.

In the example above we called a function with an argument: `0x0`, passed using `--calldata` flag.
In the example above we called a function with an argument: `'"Charizard"'`, passed using `--arguments` flag, but it can
be also obtained by passing a serialized form, in this example equivalent to passing `--calldata` with the following value: `0x0 0x43686172697a617264 0x9`.

Please note the notation of the argument. The default way of passing calldata is a list of hexadecimally encoded field elements - the *serialized* calldata.
To obtain the serialized form of the wished data, one must write a Cairo program calling `Serde::serialize` on subsequent arguments and displaying the results.
kkawula marked this conversation as resolved.
Show resolved Hide resolved
Read more about it in the [Cairo documentation](https://book.cairo-lang.org/appendix-03-derivable-traits.html?highlight=seri#serializing-with-serde).

It is also possible to pass calldata in more friendly, human readable form thanks to the [calldata transformation](./calldata-transformation.md) feature present in Cast.

Expand Down
15 changes: 9 additions & 6 deletions docs/src/starknet/invoke.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ $ sncast \
--account example_user \
invoke \
--url http://127.0.0.1:5050 \
--fee-token strk \
--contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \
--function "some_function" \
--calldata 1 2 0x1e
--contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \
--function "add" \
--fee-token eth \
--arguments 'pokemons::model::PokemonData {'\
' name: "Magmar",'\
' element: pokemons::model::Element::Fire'\
'}'
```

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

```shell
command: invoke
transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f
transaction_hash: 0x504f830428d0fcf462b4b814e2f67e12dfbcf3dc7847c1e36ba39d3eb7ac313

To see invocation details, visit:
transaction: https://starkscan.co/tx/0x7ad0d6e449...
transaction: https://sepolia.starkscan.co/tx/0x504f830428d0fcf462b4b814e2f67e12dfbcf3dc7847c1e36ba39d3eb7ac313
```
</details>
<br>
Expand Down
Loading