Skip to content

Commit 7823d25

Browse files
THenry14DelevoXDG
andauthored
Add get_nonce docs (#1302)
<!-- Reference any GitHub issues resolved by this PR --> Closes #1197 ## Introduced changes <!-- A brief description of the changes --> - add get_nonce docs, update examples ## 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: Maksim Zdobnikau <[email protected]>
1 parent 6874f0d commit 7823d25

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@
9696
* [deploy](appendix/cast-library/deploy.md)
9797
* [invoke](appendix/cast-library/invoke.md)
9898
* [call](appendix/cast-library/call.md)
99+
* [get_nonce](appendix/cast-library/get_nonce.md)

docs/src/appendix/cast-library.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* [`deploy`](cast-library/deploy.md) - deploys a contract
55
* [`invoke`](cast-library/invoke.md) - invokes a contract's function
66
* [`call`](cast-library/call.md) - calls a contract's function
7+
* [`get_nonce`](cast-library/get_nonce.md) - gets account's nonce for a given block tag
78

89
> ℹ️ **Info**
910
> To use the library functions you need to add `sncast_std` package as a dependency in
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# `get_nonce`
2+
3+
> `fn get_nonce(block_tag: felt252) -> felt252`
4+
5+
Gets nonce of an account for a given block tag (`pending` or `latest`) and returns nonce as `felt252`.
6+
7+
- `block_tag` - block tag name, one of `pending` or `latest`.
8+
9+
```rust
10+
use sncast_std::{get_nonce};
11+
use debug::PrintTrait;
12+
13+
fn main() {
14+
let nonce = get_once('latest');
15+
nonce.print();
16+
}
17+
```

docs/src/starknet/script.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,28 @@ This example script declares, deploys and interacts with an example [map contrac
8787

8888
```cairo
8989
use sncast_std::{
90-
declare, deploy, invoke, call, DeclareResult, DeployResult, InvokeResult, CallResult
90+
declare, deploy, invoke, call, DeclareResult, DeployResult, InvokeResult, CallResult, get_nonce
9191
};
9292
use debug::PrintTrait;
9393
9494
fn main() {
9595
let max_fee = 99999999999999999;
9696
let salt = 0x3;
97+
let nonce = get_nonce('latest');
9798
98-
let declare_result = declare('Map', Option::Some(max_fee));
99+
let declare_result = declare('Map', Option::Some(max_fee), Option::Nonce);
99100
100101
let class_hash = declare_result.class_hash;
101102
let deploy_result = deploy(
102-
class_hash, ArrayTrait::new(), Option::Some(salt), true, Option::Some(max_fee)
103+
class_hash, ArrayTrait::new(), Option::Some(salt), true, Option::Some(max_fee), Option::Some(nonce)
103104
);
104105
105106
'Deployed the contract to address'.print();
106107
deploy_result.contract_address.print();
107108
109+
let invoke_nonce = get_nonce('pending');
108110
let invoke_result = invoke(
109-
deploy_result.contract_address, 'put', array![0x1, 0x2], Option::Some(max_fee)
111+
deploy_result.contract_address, 'put', array![0x1, 0x2], Option::Some(max_fee), Option::Some(invoke_nonce)
110112
);
111113
112114
'Invoke tx hash is'.print();

0 commit comments

Comments
 (0)