Skip to content

Commit 6874f0d

Browse files
authored
Add docs on sncast_std, update cast docs (#1297)
<!-- Reference any GitHub issues resolved by this PR --> Closes # ## Introduced changes <!-- A brief description of the changes --> - Add docs for sncast_std, update docs for #1283 ## 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`
1 parent 695738f commit 6874f0d

File tree

11 files changed

+203
-3
lines changed

11 files changed

+203
-3
lines changed

docs/src/SUMMARY.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
* [spy_events](appendix/cheatcodes/spy_events.md)
6060
* [start_spoof](appendix/cheatcodes/start_spoof.md)
6161
* [stop_spoof](appendix/cheatcodes/stop_spoof.md)
62-
63-
6462
* [Forge Library Functions References](appendix/forge-library.md)
6563
* [declare](appendix/forge-library/declare.md)
6664
* [precalculate_address](appendix/forge-library/precalculate_address.md)
@@ -93,3 +91,8 @@
9391
* [run](appendix/cast/multicall/run.md)
9492
* [show-config](appendix/cast/show_config.md)
9593
* [script](appendix/cast/script.md)
94+
* [Cast Library Functions References](appendix/cast-library.md)
95+
* [declare](appendix/cast-library/declare.md)
96+
* [deploy](appendix/cast-library/deploy.md)
97+
* [invoke](appendix/cast-library/invoke.md)
98+
* [call](appendix/cast-library/call.md)

docs/src/appendix/cast-library.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Library Functions References
2+
3+
* [`declare`](cast-library/declare.md) - declares a contract
4+
* [`deploy`](cast-library/deploy.md) - deploys a contract
5+
* [`invoke`](cast-library/invoke.md) - invokes a contract's function
6+
* [`call`](cast-library/call.md) - calls a contract's function
7+
8+
> ℹ️ **Info**
9+
> To use the library functions you need to add `sncast_std` package as a dependency in
10+
> your [`Scarb.toml`](https://docs.swmansion.com/scarb/docs/guides/dependencies.html#adding-a-dependency)
11+
> using appropriate release tag.
12+
>```toml
13+
> [dependencies]
14+
> sncast_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.12.0" }
15+
> ```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# `call`
2+
3+
> `fn call(
4+
contract_address: ContractAddress, function_name: felt252, calldata: Array::<felt252>
5+
) -> CallResult`
6+
7+
Calls a contract and returns `CallResult`.
8+
9+
```rust
10+
#[derive(Drop, Clone)]
11+
struct CallResult {
12+
data: Array::<felt252>,
13+
}
14+
```
15+
16+
- `contract_address` - address of the contract to call.
17+
- `function_name` - the name of the function to call, as Cairo shortstring.
18+
- `calldata` - inputs to the function to be called.
19+
20+
```rust
21+
use sncast_std::{call, CallResult};
22+
use starknet::{ContractAddress, Felt252TryIntoContractAddress};
23+
use debug::PrintTrait;
24+
25+
fn main() {
26+
let contract_address: ContractAddress = 0x1e52f6ebc3e594d2a6dc2a0d7d193cb50144cfdfb7fdd9519135c29b67e427
27+
.try_into()
28+
.expect('Invalid contract address value');
29+
30+
let call_result = call(contract_address, 'get', array![0x1]);
31+
let first_item = *call_result.data[0];
32+
first_item.print();
33+
}
34+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# `declare`
2+
3+
> `fn declare(contract_name: felt252, max_fee: Option<felt252>, nonce: Option<felt252>) -> DeclareResult`
4+
5+
Declares a contract and returns `DeclareResult`.
6+
7+
```rust
8+
#[derive(Drop, Clone)]
9+
struct DeclareResult {
10+
class_hash: ClassHash,
11+
transaction_hash: felt252,
12+
}
13+
```
14+
15+
- `contract_name` - name of a contract as Cairo shortstring. It is a name of the contract (part after `mod` keyword) e.g. `'HelloStarknet'`.
16+
- `max_fee` - max fee for declare transaction. If not provided, max fee will be automatically estimated.
17+
- `nonce` - nonce for declare transaction. If not provided, nonce will be set automatically.
18+
19+
```rust
20+
use sncast_std::{declare, DeclareResult};
21+
use debug::PrintTrait;
22+
23+
fn main() {
24+
let max_fee = 9999999;
25+
let declare_result = declare('HelloStarknet', Option::Some(max_fee), nonce::None);
26+
27+
let class_hash = declare_result.class_hash;
28+
class_hash.print();
29+
}
30+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# `deploy`
2+
3+
> `fn deploy(
4+
class_hash: ClassHash,
5+
constructor_calldata: Array::<felt252>,
6+
salt: Option<felt252>,
7+
unique: bool,
8+
max_fee: Option<felt252>,
9+
nonce: Option<felt252>
10+
) -> DeployResult`
11+
12+
Deploys a contract and returns `DeployResult`.
13+
14+
```rust
15+
#[derive(Drop, Clone)]
16+
struct DeployResult {
17+
contract_address: ContractAddress,
18+
transaction_hash: felt252,
19+
}
20+
```
21+
22+
- `class_hash` - class hash of a contract to deploy.
23+
- `constructor_calldata` - calldata for the contract constructor.
24+
- `salt` - salt for the contract address.
25+
- `unique` - determines if salt should be further modified with the account address.
26+
- `max_fee` - max fee for declare transaction. If not provided, max fee will be automatically estimated.
27+
- `nonce` - nonce for declare transaction. If not provided, nonce will be set automatically.
28+
29+
```rust
30+
use sncast_std::{deploy, DeployResult};
31+
use starknet::{ClassHash, Felt252TryIntoClassHash};
32+
use debug::PrintTrait;
33+
34+
fn main() {
35+
let max_fee = 9999999;
36+
let salt = 0x1;
37+
let nonce = 0x1;
38+
let class_hash: ClassHash = 0x03a8b191831033ba48ee176d5dde7088e71c853002b02a1cfa5a760aa98be046
39+
.try_into()
40+
.expect('Invalid class hash value');
41+
42+
let deploy_result = deploy(
43+
class_hash,
44+
ArrayTrait::new(),
45+
Option::Some(salt),
46+
true,
47+
Option::Some(max_fee),
48+
Option::Some(nonce)
49+
);
50+
51+
deploy_result.contract_address.print();
52+
}
53+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# `invoke`
2+
3+
> `fn invoke(
4+
contract_address: ContractAddress,
5+
entry_point_selector: felt252,
6+
calldata: Array::<felt252>,
7+
max_fee: Option<felt252>,
8+
nonce: Option<felt252>
9+
) -> InvokeResult`
10+
11+
Deploys a contract and returns `InvokeResult`.
12+
13+
```rust
14+
#[derive(Drop, Clone)]
15+
struct InvokeResult {
16+
transaction_hash: felt252,
17+
}
18+
```
19+
20+
- `contract_address` - address of the contract to invoke.
21+
- `entry_point_selector` - the name of the function to invoke, as Cairo shortstring.
22+
- `calldata` - inputs to the function to be invoked.
23+
- `max_fee` - max fee for declare transaction. If not provided, max fee will be automatically estimated.
24+
- `nonce` - nonce for declare transaction. If not provided, nonce will be set automatically.
25+
26+
```rust
27+
use sncast_std::{invoke, InvokeResult};
28+
use starknet::{ContractAddress, Felt252TryIntoContractAddress};
29+
30+
fn main() {
31+
let contract_address: ContractAddress = 0x1e52f6ebc3e594d2a6dc2a0d7d193cb50144cfdfb7fdd9519135c29b67e427
32+
.try_into()
33+
.expect('Invalid contract address value');
34+
35+
let invoke_result = invoke(
36+
contract_address, 'put', array![0x1, 0x2], Option::None, Option::None
37+
);
38+
39+
}
40+
```

docs/src/appendix/cast/common.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ Optional.
5959

6060
If passed, command will wait until transaction is accepted or rejected.
6161

62+
## `--wait-timeout <TIME_IN_SECONDS>`
63+
Optional.
64+
65+
If `--wait` is passed, this will set the time after which cast times out. Defaults to 60s.
66+
67+
## `--wait-retry-timeout <TIME_IN_SECONDS>`
68+
Optional.
69+
70+
If `--wait` is passed, this will set the retry interval - how often cast should fetch tx info from the node. Defaults to 5s.
71+
6272
## `--version, -v`
6373

6474
Prints out `sncast` version.

docs/src/appendix/cast/declare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ Name of the contract. Contract name is a part after the mod keyword in your cont
1010
Optional.
1111

1212
Max fee for transaction. If not provided, max fee will be automatically estimated.
13+
14+
## `--nonce, -n <NONCE>`
15+
Optional.
16+
17+
Nonce for transaction. If not provided, nonce will be set automatically.

docs/src/appendix/cast/deploy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ If passed, the salt will be additionally modified with an account address.
2525
Optional.
2626

2727
Max fee for the transaction. If not provided, max fee will be automatically estimated.
28+
29+
## `--nonce, -n <NONCE>`
30+
Optional.
31+
32+
Nonce for transaction. If not provided, nonce will be set automatically.

docs/src/appendix/cast/invoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ Calldata arguments may be either 0x hex or decimal felts.
2121
Optional.
2222

2323
Max fee for the transaction. If not provided, it will be automatically estimated.
24+
25+
## `--nonce, -n <NONCE>`
26+
Optional.
27+
28+
Nonce for transaction. If not provided, nonce will be set automatically.

0 commit comments

Comments
 (0)