diff --git a/Cargo.lock b/Cargo.lock index b9fa0b1262..0b0d30e9bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1893,10 +1893,13 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" name = "docs" version = "0.34.0" dependencies = [ + "camino", "regex", "serde", "serde_json", "shell-words", + "tempfile", + "toml_edit", "walkdir", ] diff --git a/crates/docs/Cargo.toml b/crates/docs/Cargo.toml index 41e8b672b1..bd24e1877d 100644 --- a/crates/docs/Cargo.toml +++ b/crates/docs/Cargo.toml @@ -11,6 +11,9 @@ shell-words = "1.1.0" walkdir.workspace = true serde.workspace = true serde_json.workspace = true +toml_edit.workspace = true +camino.workspace = true +tempfile.workspace = true [features] testing = [] diff --git a/crates/docs/src/snippet.rs b/crates/docs/src/snippet.rs index 2b03f74534..7d0fd6b427 100644 --- a/crates/docs/src/snippet.rs +++ b/crates/docs/src/snippet.rs @@ -1,6 +1,16 @@ +use std::sync::LazyLock; + use regex::Regex; use serde::{Deserialize, Serialize}; +static RE_SNCAST: LazyLock = LazyLock::new(|| { + Regex::new( r"(?ms)^(?:\n)?```shell\n\$ (?Psncast .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?").expect("Failed to create regex for sncast snippet") +}); + +static RE_SNFORGE: LazyLock = LazyLock::new(|| { + Regex::new( r"(?ms)^(?:\n)?```shell\n\$ (?Psnforge .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?").expect("Failed to create regex for snforge snippet") +}); + #[derive(Clone, Debug)] pub struct SnippetType(String); @@ -21,9 +31,9 @@ impl SnippetType { } #[must_use] - pub fn get_re(&self) -> Regex { + pub fn get_re(&self) -> &'static Regex { // The regex pattern is used to match the snippet, its config and the output. Example: - // + // // ```shell // $ snforge or sncast command with args... // ``` @@ -34,19 +44,22 @@ impl SnippetType { // ``` //
- let escaped_command = regex::escape(self.as_str()); - let pattern = format!( - r"(?ms)^(?:\n)?```shell\n\$ (?P{escaped_command} .+?)\n```(?:\s*
\nOutput:<\/summary>\n\n```shell\n(?P[\s\S]+?)\n```[\s]*<\/details>)?" - ); - - Regex::new(&pattern).unwrap() + match self.as_str() { + "snforge" => &RE_SNFORGE, + "sncast" => &RE_SNCAST, + _ => panic!("Regex for {} not found", self.as_str()), + } } } #[derive(Debug, Deserialize, Serialize, Default)] pub struct SnippetConfig { - pub ignored: Option, + #[serde(default)] + pub ignored: bool, pub package_name: Option, + pub contract_name: Option, + #[serde(default)] + pub ignored_output: bool, } #[derive(Debug)] diff --git a/crates/docs/src/utils.rs b/crates/docs/src/utils.rs index 9b5b3bcfaa..ab88de351b 100644 --- a/crates/docs/src/utils.rs +++ b/crates/docs/src/utils.rs @@ -1,6 +1,8 @@ -use std::{env, path::PathBuf}; - use crate::snippet::Snippet; +use camino::Utf8PathBuf; +use std::{env, fs, path::PathBuf, str::FromStr}; +use tempfile::TempDir; +use toml_edit::{value, DocumentMut}; #[must_use] pub fn get_nth_ancestor(levels_up: usize) -> PathBuf { @@ -27,15 +29,45 @@ pub fn assert_valid_snippet(condition: bool, snippet: &Snippet, err_message: &st ); } -pub fn print_success_message(snippets_len: usize, tool_name: &str) { - println!("Successfully validated {snippets_len} {tool_name} docs snippets"); +pub fn print_snippets_validation_summary(snippets: &[Snippet], tool_name: &str) { + let validated_snippets_count = snippets + .iter() + .filter(|snippet| !snippet.config.ignored) + .count(); + let ignored_snippets_count = snippets.len() - validated_snippets_count; + + println!("Finished validation of {tool_name} docs snippets\nValidated: {validated_snippets_count}, Ignored: {ignored_snippets_count}"); } -pub fn print_skipped_snippet_message(snippet: &Snippet) { +pub fn print_ignored_snippet_message(snippet: &Snippet) { println!( - "Skipped validation of {} snippet in the docs in file: {} at line {}", + "Ignoring {} docs snippet, file: {}:{}:1", snippet.snippet_type.as_str(), snippet.file_path, snippet.line_start, ); } + +fn get_canonical_path(relative_path: &str) -> Result> { + Ok(Utf8PathBuf::from_str(relative_path)? + .canonicalize_utf8()? + .to_string()) +} + +pub fn update_scarb_toml_dependencies(temp: &TempDir) -> Result<(), Box> { + let snforge_std_path = get_canonical_path("../../snforge_std")?; + let sncast_std_path = get_canonical_path("../../sncast_std")?; + let scarb_toml_path = temp.path().join("Scarb.toml"); + + let mut scarb_toml = fs::read_to_string(&scarb_toml_path) + .unwrap() + .parse::() + .unwrap(); + + scarb_toml["dependencies"]["sncast_std"]["path"] = value(&sncast_std_path); + scarb_toml["dev-dependencies"]["snforge_std"]["path"] = value(&snforge_std_path); + + fs::write(&scarb_toml_path, scarb_toml.to_string())?; + + Ok(()) +} diff --git a/crates/forge/tests/e2e/docs_snippets_validation.rs b/crates/forge/tests/e2e/docs_snippets_validation.rs index a385d1c06a..ac16e555a1 100644 --- a/crates/forge/tests/e2e/docs_snippets_validation.rs +++ b/crates/forge/tests/e2e/docs_snippets_validation.rs @@ -1,7 +1,8 @@ use clap::Parser; use docs::snippet::SnippetType; use docs::utils::{ - assert_valid_snippet, get_nth_ancestor, print_skipped_snippet_message, print_success_message, + assert_valid_snippet, get_nth_ancestor, print_ignored_snippet_message, + print_snippets_validation_summary, }; use docs::validation::extract_snippets_from_directory; use forge::Cli; @@ -20,14 +21,14 @@ fn test_docs_snippets() { .expect("Failed to extract command snippets"); for snippet in &snippets { - let args = snippet.to_command_args(); - let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); - - if snippet.config.ignored.unwrap_or(false) { - print_skipped_snippet_message(snippet); + if snippet.config.ignored { + print_ignored_snippet_message(snippet); continue; } + let args = snippet.to_command_args(); + let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); + let parse_result = Cli::try_parse_from(args.clone()); let err_message = if let Err(err) = &parse_result { err.to_string() @@ -55,5 +56,5 @@ fn test_docs_snippets() { } } - print_success_message(snippets.len(), snippet_type.as_str()); + print_snippets_validation_summary(&snippets, snippet_type.as_str()); } diff --git a/crates/sncast/README.md b/crates/sncast/README.md index d7dda0a8cc..9ee19756fc 100644 --- a/crates/sncast/README.md +++ b/crates/sncast/README.md @@ -31,10 +31,13 @@ All subcommand usages are shown for two scenarios - when all necessary arguments ### Declare a contract + + ```shell -$ sncast --account myuser \ +$ sncast --account my_account \ declare \ - --contract-name SimpleBalance + --contract-name HelloSncast \ + --fee-token strk ```
@@ -42,17 +45,20 @@ $ sncast --account myuser \ ```shell command: Declare -class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +class_hash: [..] +transaction_hash: [..] ```

With arguments taken from `snfoundry.toml` file (default profile name): + + ```shell $ sncast declare \ - --contract-name SimpleBalance + --contract-name HelloSncast \ + --fee-token strk ```
@@ -60,8 +66,8 @@ $ sncast declare \ ```shell command: Declare -class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +class_hash: [..] +transaction_hash: [..] ```

@@ -69,10 +75,13 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 ### Deploy a contract + + ```shell -$ sncast --account myuser \ - deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ - --url http://127.0.0.1:5050/rpc \ +$ sncast --account my_account \ + deploy --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --url http://127.0.0.1:5055 \ + --fee-token strk ```
@@ -80,16 +89,21 @@ $ sncast --account myuser \ ```shell command: Deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +contract_address: [..] +transaction_hash: [..] ```

With arguments taken from `snfoundry.toml` file (default profile name): + + ```shell -$ sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a +$ sncast deploy \ +--class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ +--fee-token strk + ```
@@ -97,8 +111,8 @@ $ sncast deploy --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2 ```shell command: Deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +contract_address: [..] +transaction_hash: [..] ```

@@ -106,21 +120,27 @@ transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5a ### Invoke a contract + ```shell $ sncast \ - --account example_user \ + --account my_account \ invoke \ - --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ - --function "some_function" \ - --arguments '1, 2, 3' + --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --function "sum_numbers" \ + --arguments '1, 2, 3' \ + --url http://127.0.0.1:5055/rpc \ + --fee-token strk ```
Output: ```shell -command: Invoke -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +command: invoke +transaction_hash: [..] + +To see invocation details, visit: +transaction: https://sepolia.starkscan.co/tx/[..] ```

@@ -128,31 +148,39 @@ transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee2 With arguments taken from `snfoundry.toml` file (default profile name): + ```shell $ sncast invoke \ - --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ - --function "some_function" \ - --arguments '1, 2, 3' + --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --function "sum_numbers" \ + --arguments '1, 2, 3' \ + --url http://127.0.0.1:5055/rpc \ + --fee-token strk ```
Output: ```shell -command: Invoke -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +command: invoke +transaction_hash: [..] + +To see invocation details, visit: +transaction: https://sepolia.starkscan.co/tx/[..] ```

### Call a contract + ```shell $ sncast \ call \ - --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ - --function "some_function" \ - --arguments '1, 2, 3' + --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --function "sum_numbers" \ + --arguments '1, 2, 3' \ + --url http://127.0.0.1:5055/rpc ```
@@ -160,7 +188,7 @@ $ sncast \ ```shell command: call -response: [0x0] +response: [0x6] ```

@@ -168,11 +196,13 @@ response: [0x0] With arguments taken from `snfoundry.toml` file (default profile name): + ```shell $ sncast call \ - --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ - --function "some_function" \ - --arguments '1, 2, 3' + --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --function "sum_numbers" \ + --arguments '1, 2, 3' \ + --url http://127.0.0.1:5055/rpc ```
@@ -180,7 +210,7 @@ $ sncast call \ ```shell command: call -response: [0x0] +response: [0x6] ```

diff --git a/crates/sncast/src/lib.rs b/crates/sncast/src/lib.rs index 181d3558dc..f5c17041f6 100644 --- a/crates/sncast/src/lib.rs +++ b/crates/sncast/src/lib.rs @@ -560,7 +560,7 @@ pub async fn wait_for_tx( tx_hash: Felt, wait_params: ValidatedWaitParams, ) -> Result<&str, WaitForTransactionError> { - println!("Transaction hash = {tx_hash:#x}"); + println!("Transaction hash: {tx_hash:#x}"); let retries = wait_params.get_retries(); for i in (1..retries).rev() { diff --git a/crates/sncast/tests/docs_snippets/validation.rs b/crates/sncast/tests/docs_snippets/validation.rs index 362cd07e7e..df31c1e06e 100644 --- a/crates/sncast/tests/docs_snippets/validation.rs +++ b/crates/sncast/tests/docs_snippets/validation.rs @@ -1,16 +1,34 @@ +use crate::helpers::devnet::{prepare_accounts_file, setup_contracts_map}; +use crate::helpers::fixtures::copy_directory_to_tempdir; +use crate::helpers::runner::runner; +use camino::Utf8PathBuf; use docs::snippet::{Snippet, SnippetType}; use docs::utils::{ - assert_valid_snippet, get_nth_ancestor, print_skipped_snippet_message, print_success_message, + get_nth_ancestor, print_ignored_snippet_message, print_snippets_validation_summary, + update_scarb_toml_dependencies, }; use docs::validation::{extract_snippets_from_directory, extract_snippets_from_file}; -use tempfile::tempdir; +use shared::test_utils::output_assert::assert_stdout_contains; -use crate::helpers::runner::runner; +fn swap_next_element<'a>(args: &mut [&'a str], target: &str, new_value: &'a str) { + if let Some(index) = args.iter().position(|&x| x == target) { + if index + 1 < args.len() { + args[index + 1] = new_value; + } + } +} + +fn get_contract_name_from_args(args: &[&str]) -> Option { + let index = args.iter().position(|&x| x == "--contract-name")?; + args.get(index + 1).copied().map(String::from) +} + +fn is_command(args: &[&str], commands: &[&str]) -> bool { + commands.iter().any(|&cmd| args.contains(&cmd)) +} #[test] fn test_docs_snippets() { - let tempdir = tempdir().expect("Unable to create a temporary directory"); - let root_dir_path = get_nth_ancestor(2); let docs_dir_path = root_dir_path.join("docs/src"); let sncast_readme_path = root_dir_path.join("crates/sncast/README.md"); @@ -28,25 +46,56 @@ fn test_docs_snippets() { .chain(readme_snippets) .collect::>(); + let hello_sncast_dir = + Utf8PathBuf::from_path_buf(root_dir_path.join("docs/listings/hello_sncast")) + .expect("Invalid UTF-8 path"); + let tempdir = copy_directory_to_tempdir(&hello_sncast_dir); + let accounts_json_path = prepare_accounts_file(&tempdir); + + update_scarb_toml_dependencies(&tempdir).unwrap(); + + let contracts = setup_contracts_map(&tempdir, &accounts_json_path); + for snippet in &snippets { + if snippet.config.ignored { + print_ignored_snippet_message(snippet); + continue; + } + let args = snippet.to_command_args(); let mut args: Vec<&str> = args.iter().map(String::as_str).collect(); // remove "sncast" from the args args.remove(0); - if snippet.config.ignored.unwrap_or(false) { - print_skipped_snippet_message(snippet); - continue; + args.insert(0, "--accounts-file"); + args.insert(1, accounts_json_path.as_str()); + + if let Some(contract_name) = + get_contract_name_from_args(&args).or_else(|| snippet.config.contract_name.clone()) + { + let contract = contracts + .get(contract_name.as_str()) + .unwrap_or_else(|| panic!("Contract {contract_name} not found")); + + // In case of invoke/call/verify, we need to replace contract address in snippet's + // args with prepared contract's address + if is_command(&args, &["invoke", "call", "verify"]) { + swap_next_element(&mut args, "--contract-address", &contract.contract_address); + // Similarly for deploy, we need to replace class-hash in snippet's + // args with prepared contract's class-hash + } else if is_command(&args, &["deploy"]) { + swap_next_element(&mut args, "--class-hash", &contract.class_hash); + } } let snapbox = runner(&args).current_dir(tempdir.path()); - let output = snapbox.output().expect("Failed to execute the command"); - let exit_code = output.status.code().unwrap_or_default(); - let stderr = String::from_utf8_lossy(&output.stderr); + let output = snapbox.assert().success(); - assert_valid_snippet(exit_code != 2, snippet, &stderr); + if snippet.output.is_some() && !snippet.config.ignored_output { + assert_stdout_contains(output, snippet.output.as_ref().unwrap()); + } } - print_success_message(snippets.len(), snippet_type.as_str()); + print_snippets_validation_summary(&snippets, snippet_type.as_str()); } diff --git a/crates/sncast/tests/e2e/script/general.rs b/crates/sncast/tests/e2e/script/general.rs index 5b82923645..637205b53b 100644 --- a/crates/sncast/tests/e2e/script/general.rs +++ b/crates/sncast/tests/e2e/script/general.rs @@ -238,13 +238,13 @@ async fn test_run_script_display_debug_traits() { test declare_nonce: [..] debug declare_nonce: [..] - Transaction hash = 0x[..] + Transaction hash: 0x[..] declare_result: class_hash: [..], transaction_hash: [..] debug declare_result: DeclareResult::Success(DeclareTransactionResult { class_hash: [..], transaction_hash: [..] }) - Transaction hash = 0x[..] + Transaction hash: 0x[..] deploy_result: contract_address: [..], transaction_hash: [..] debug deploy_result: DeployResult { contract_address: [..], transaction_hash: [..] } - Transaction hash = 0x[..] + Transaction hash: 0x[..] invoke_result: [..] debug invoke_result: InvokeResult { transaction_hash: [..] } call_result: [2] diff --git a/crates/sncast/tests/helpers/devnet.rs b/crates/sncast/tests/helpers/devnet.rs index 491f0634fb..fdb1482ef1 100644 --- a/crates/sncast/tests/helpers/devnet.rs +++ b/crates/sncast/tests/helpers/devnet.rs @@ -3,14 +3,27 @@ use crate::helpers::fixtures::{ deploy_argent_account, deploy_braavos_account, deploy_cairo_0_account, deploy_keystore_account, deploy_latest_oz_account, }; +use camino::Utf8PathBuf; use ctor::{ctor, dtor}; +use regex::Regex; +use shared::test_utils::output_assert::AsOutput; +use std::collections::HashMap; +use std::fs; use std::net::TcpStream; use std::process::{Command, Stdio}; use std::string::ToString; use std::time::{Duration, Instant}; +use tempfile::TempDir; use tokio::runtime::Runtime; use url::Url; +use super::runner::runner; + +pub struct Contract { + pub class_hash: String, + pub contract_address: String, +} + #[allow(clippy::zombie_processes)] #[cfg(test)] #[ctor] @@ -89,3 +102,111 @@ fn stop_devnet() { .spawn() .expect("Failed to kill devnet processes"); } + +fn declare_and_deploy_contract( + contract_name: &str, + accounts_file: &str, + temp: &TempDir, +) -> Contract { + let args = vec![ + "--accounts-file", + accounts_file, + "--account", + "my_account", + "declare", + "--url", + URL, + "--contract-name", + contract_name, + "--max-fee", + "99999999999999999", + "--fee-token", + "strk", + ]; + + let snapbox = runner(&args).current_dir(temp.path()); + let output = snapbox.assert().success(); + let re_class_hash = Regex::new(r"class_hash:\s+(0x[a-fA-F0-9]+)").unwrap(); + + let class_hash = re_class_hash + .captures(output.as_stdout()) + .and_then(|captures| captures.get(1)) + .map(|match_| match_.as_str()) + .expect("class_hash not found in the output"); + + let args = vec![ + "--accounts-file", + accounts_file, + "--account", + "my_account", + "deploy", + "--url", + URL, + "--class-hash", + class_hash, + "--max-fee", + "99999999999999999", + "--fee-token", + "strk", + ]; + + let re_contract_address = Regex::new(r"contract_address:\s+(0x[a-fA-F0-9]+)").unwrap(); + + let snapbox = runner(&args).current_dir(temp.path()); + let output = snapbox.assert().success(); + + let contract_address = re_contract_address + .captures(output.as_stdout()) + .and_then(|captures| captures.get(1)) + .map(|match_| match_.as_str()) + .expect("contract_address not found in the output"); + + Contract { + class_hash: class_hash.to_string(), + contract_address: contract_address.to_string(), + } +} + +#[must_use] +pub fn prepare_accounts_file(temp: &TempDir) -> Utf8PathBuf { + // Account from predeployed accounts in starknet-devnet-rs + let accounts = r#" + { + "alpha-sepolia": { + "my_account": { + "address": "0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d", + "deployed": true, + "private_key": "0x0000000000000000000000000000000056c12e097e49ea382ca8eadec0839401", + "public_key": "0x048234b9bc6c1e749f4b908d310d8c53dae6564110b05ccf79016dca8ce7dfac", + "type": "open_zeppelin" + } + } + } + "#; + + let accounts_path = temp.path().join("accounts.json"); + fs::write(&accounts_path, accounts).expect("Failed to write accounts.json"); + + Utf8PathBuf::from_path_buf(accounts_path).expect("Invalid UTF-8 path") +} + +#[must_use] +pub fn setup_contracts_map( + tempdir: &TempDir, + account_json_path: &Utf8PathBuf, +) -> HashMap { + let mut contracts: HashMap = HashMap::new(); + let contract_names = [ + "HelloSncast", + "DataTransformerContract", + "ConstructorContract", + ]; + + for contract_name in &contract_names { + let contract = + declare_and_deploy_contract(contract_name, account_json_path.as_str(), tempdir); + contracts.insert((*contract_name).to_string(), contract); + } + + contracts +} diff --git a/docs/listings/hello_sncast/Scarb.toml b/docs/listings/hello_sncast/Scarb.toml new file mode 100644 index 0000000000..b76dc6a713 --- /dev/null +++ b/docs/listings/hello_sncast/Scarb.toml @@ -0,0 +1,19 @@ +[package] +name = "hello_sncast" +version = "0.1.0" +edition = "2023_11" + +# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html + +[dependencies] +starknet = "2.7.0" +sncast_std = { path = "../../../sncast_std" } + +[dev-dependencies] +snforge_std = { path = "../../../snforge_std" } + +[[target.starknet-contract]] +sierra = true + +[scripts] +test = "snforge test" diff --git a/docs/listings/hello_sncast/snfoundry.toml b/docs/listings/hello_sncast/snfoundry.toml new file mode 100644 index 0000000000..b31107df2c --- /dev/null +++ b/docs/listings/hello_sncast/snfoundry.toml @@ -0,0 +1,9 @@ +[sncast.default] +account = "my_account" +accounts-file = "accounts.json" +url = "http://127.0.0.1:5055/rpc" + +[sncast.myprofile] +account = "my_account" +accounts-file = "accounts.json" +url = "http://127.0.0.1:5055/rpc" diff --git a/docs/listings/hello_sncast/src/constructor_contract.cairo b/docs/listings/hello_sncast/src/constructor_contract.cairo new file mode 100644 index 0000000000..dc6fd6d810 --- /dev/null +++ b/docs/listings/hello_sncast/src/constructor_contract.cairo @@ -0,0 +1,8 @@ +#[starknet::contract] +pub mod ConstructorContract { + #[storage] + struct Storage {} + + #[constructor] + fn constructor(ref self: ContractState, x: felt252, y: felt252, z: felt252) {} +} diff --git a/docs/listings/hello_sncast/src/data_transformer_contract.cairo b/docs/listings/hello_sncast/src/data_transformer_contract.cairo new file mode 100644 index 0000000000..aa5bf49624 --- /dev/null +++ b/docs/listings/hello_sncast/src/data_transformer_contract.cairo @@ -0,0 +1,60 @@ +#[derive(Serde, Drop)] +pub struct SimpleStruct { + a: felt252 +} + +#[derive(Serde, Drop)] +pub struct NestedStructWithField { + a: SimpleStruct, + b: felt252 +} + +#[derive(Serde, Drop)] +pub enum Enum { + One: (), + Two: u128, + Three: NestedStructWithField +} + +#[starknet::interface] +pub trait IDataTransformerContract { + fn tuple_fn(self: @TContractState, a: (felt252, u8, Enum)); + fn nested_struct_fn(self: @TContractState, a: NestedStructWithField); + fn complex_fn( + self: @TContractState, + arr: Array>, + one: u8, + two: i8, + three: ByteArray, + four: (felt252, u32), + five: bool, + six: u256 + ); +} + + +#[starknet::contract] +pub mod DataTransformerContract { + use super::{NestedStructWithField, Enum}; + + #[storage] + struct Storage {} + + #[abi(embed_v0)] + impl DataTransformerContractImpl of super::IDataTransformerContract { + fn tuple_fn(self: @ContractState, a: (felt252, u8, Enum)) {} + + fn nested_struct_fn(self: @ContractState, a: NestedStructWithField) {} + + fn complex_fn( + self: @ContractState, + arr: Array>, + one: u8, + two: i8, + three: ByteArray, + four: (felt252, u32), + five: bool, + six: u256 + ) {} + } +} diff --git a/docs/listings/hello_sncast/src/hello_sncast.cairo b/docs/listings/hello_sncast/src/hello_sncast.cairo new file mode 100644 index 0000000000..45772b6e65 --- /dev/null +++ b/docs/listings/hello_sncast/src/hello_sncast.cairo @@ -0,0 +1,30 @@ +#[starknet::interface] +pub trait IHelloSncast { + fn increase_balance(ref self: TContractState, amount: felt252); + fn get_balance(self: @TContractState) -> felt252; + fn sum_numbers(ref self: TContractState, a: felt252, b: felt252, c: felt252) -> felt252; +} + +#[starknet::contract] +mod HelloSncast { + #[storage] + struct Storage { + balance: felt252, + } + + #[abi(embed_v0)] + impl HelloSncastImpl of super::IHelloSncast { + fn increase_balance(ref self: ContractState, amount: felt252) { + assert(amount != 0, 'Amount cannot be 0'); + self.balance.write(self.balance.read() + amount); + } + + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } + + fn sum_numbers(ref self: ContractState, a: felt252, b: felt252, c: felt252) -> felt252 { + a + b + c + } + } +} diff --git a/docs/listings/hello_sncast/src/lib.cairo b/docs/listings/hello_sncast/src/lib.cairo new file mode 100644 index 0000000000..b282cbfd57 --- /dev/null +++ b/docs/listings/hello_sncast/src/lib.cairo @@ -0,0 +1,3 @@ +pub mod hello_sncast; +pub mod data_transformer_contract; +pub mod constructor_contract; diff --git a/docs/src/projects/configuration.md b/docs/src/projects/configuration.md index 51b6580bfe..d7c783bac1 100644 --- a/docs/src/projects/configuration.md +++ b/docs/src/projects/configuration.md @@ -49,12 +49,12 @@ defined in the profile. > Not all parameters have to be present in the configuration - you can choose to include only some of them and supply > the rest of them using CLI flags. You can also override parameters from the configuration using CLI flags. + ```shell $ sncast --profile myprofile \ call \ - --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ - --function get \ - --arguments '0' \ + --contract-address 0xcd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 \ + --function get_balance \ --block-id latest ``` @@ -87,11 +87,11 @@ url = "http://127.0.0.1:5050/rpc" With this, there's no need to include the `--profile` argument when using `sncast`. + ```shell $ sncast call \ - --contract-address 0x38b7b9507ccf73d79cb42c2cc4e58cf3af1248f342112879bfdf5aa4f606cc9 \ - --function get \ - --arguments '0' \ + --contract-address 0xcd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008 \ + --function get_balance \ --block-id latest ``` @@ -100,7 +100,7 @@ $ sncast call \ ```shell command: call -response: [0x1, 0x23, 0x4] +response: [0x0] ```

diff --git a/docs/src/snforge-advanced-features/storage-cheatcodes.md b/docs/src/snforge-advanced-features/storage-cheatcodes.md index d82a2d9e41..a18ceb02a0 100644 --- a/docs/src/snforge-advanced-features/storage-cheatcodes.md +++ b/docs/src/snforge-advanced-features/storage-cheatcodes.md @@ -54,5 +54,5 @@ And perform a test checking `load` and `store` behavior in context of those stru This example uses `storage_address_from_base` with entry's of the storage variable. ```rust -{{#include ../../listings/snforge_advanced_features/crates/direct_storage_access/tests/using_storage_address_from_base.cairo}} +{{#include ../../listings/direct_storage_access/tests/using_storage_address_from_base.cairo}} ``` \ No newline at end of file diff --git a/docs/src/starknet/account-import.md b/docs/src/starknet/account-import.md index 31039fe0ae..1f75b5a437 100644 --- a/docs/src/starknet/account-import.md +++ b/docs/src/starknet/account-import.md @@ -74,7 +74,7 @@ To import an account into the file holding the accounts info (`~/.starknet_accou ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name account_123 \ --address 0x1 \ --private-key 0x2 \ @@ -91,7 +91,7 @@ If you don't want to pass the private key in the command (because of safety aspe ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name account_123 \ --address 0x1 \ --type oz @@ -113,7 +113,7 @@ To import Argent account, set the `--type` flag to `argent`. ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name account_argent \ --address 0x1 \ --private-key 0x2 \ @@ -127,7 +127,7 @@ To import Braavos account, set the `--type` flag to `braavos`. ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name account_braavos \ --address 0x1 \ --private-key 0x2 \ @@ -141,7 +141,7 @@ To import OpenZeppelin account, set the `--type` flag to `oz` or `open_zeppelin ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name account_oz \ --address 0x1 \ --private-key 0x2 \ diff --git a/docs/src/starknet/account.md b/docs/src/starknet/account.md index 517e30e62a..07af04d94d 100644 --- a/docs/src/starknet/account.md +++ b/docs/src/starknet/account.md @@ -25,8 +25,8 @@ Do the following to start interacting with the Starknet: ```shell $ sncast \ account create \ - --url http://127.0.0.1:5050 \ - --name some-name + --url http://127.0.0.1:5055 \ + --name new_account ```
@@ -35,12 +35,12 @@ $ sncast \ ```shell command: account create add_profile: --add-profile flag was not set. No profile added to snfoundry.toml -address: 0x34ae54182d04754d8043189afd315a808d4bea1a63862b3b05aa78b37756d7b -max_fee: 180527346330500 +address: [..] +max_fee: [..] message: Account successfully created. Prefund generated address with at least STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand. To see account creation details, visit: -account: https://starkscan.co/search/contract/34ae54182d04754d8043189afd315a808d4bea1a63862b3b05aa78b37756d7b +account: https://sepolia.starkscan.co/contract/[..] ```

@@ -59,11 +59,13 @@ You can do it both by sending tokens from another starknet account or by bridgin >![image](images/starknet-faucet-sepolia.png) #### Deploy account with the `sncast account deploy` command + + ```shell $ sncast \ account deploy \ - --url http://127.0.0.1:5050 \ - --name some-name \ + --url http://127.0.0.1:5055 \ + --name new_account \ --fee-token strk \ --max-fee 9999999999999 ``` @@ -73,10 +75,10 @@ $ sncast \ ```shell command: account deploy -transaction_hash: 0x20b20896ce63371ef015d66b4dd89bf18c5510a840b4a85a43a983caa6e2579 +transaction_hash: [..] To see invocation details, visit: -transaction: https://starkscan.co/search/0x20b20896ce... +transaction: https://sepolia.starkscan.co/tx/[..] ```

@@ -96,7 +98,7 @@ To import an account to the `default accounts file`, use the `account import` co ```shell $ sncast \ account import \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --name my_imported_account \ --address 0x3a0bcb72428d8056cc7c2bbe5168ddfc844db2737dda3b4c67ff057691177e1 \ --private-key 0x2 \ @@ -106,23 +108,36 @@ $ sncast \ ### [`account list`](../appendix/sncast/account/list.md) List all accounts saved in `accounts file`, grouped based on the networks they are defined on. + + ```shell $ sncast account list ``` +
+Output: + +```shell +Available accounts (at [..]): +- new_account: + network: alpha-sepolia + public key: [..] + address: [..] + salt: [..] + class hash: [..] + deployed: false + legacy: false + type: OpenZeppelin + +- my_account: + network: alpha-sepolia + public key: 0x48234b9bc6c1e749f4b908d310d8c53dae6564110b05ccf79016dca8ce7dfac + address: 0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d + deployed: true + type: OpenZeppelin ``` -Available accounts (at /Users//.starknet_accounts/starknet_open_zeppelin_accounts.json): -- user0 -public key: 0x2f91ed13f8f0f7d39b942c80bfcd3d0967809d99e0cc083606cbe59033d2b39 -network: alpha-sepolia -address: 0x4f5f24ceaae64434fa2bc2befd08976b51cf8f6a5d8257f7ec3616f61de263a -type: OpenZeppelin -deployed: false -legacy: false - -- user1 -[...] -``` +
+
You can specify a custom location for the accounts file with the `--accounts-file` or `-f` flag. There is also possibility to show private keys with the `--display-private-keys` or `-p` flag. @@ -133,7 +148,7 @@ Delete an account from `accounts-file` and its associated Scarb profile. If you ```shell $ sncast account delete \ - --name some-name \ + --name new_account \ --network alpha-sepolia ``` @@ -148,8 +163,8 @@ with `--class-hash` flag: ```shell $ sncast \ account create \ - --name some-name \ - --url http://127.0.0.1:5050 \ + --name new_account_2 \ + --url http://127.0.0.1:5055 \ --class-hash 0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6 --type oz ``` @@ -161,8 +176,8 @@ Instead of random generation, salt can be specified with `--salt`. ```shell $ sncast \ account create \ - --url http://127.0.0.1:5050 \ - --name some-name \ + --url http://127.0.0.1:5055 \ + --name another_account_3 \ --salt 0x1 ``` @@ -187,12 +202,14 @@ Accounts created and deployed with [starkli](https://book.starkli.rs/accounts#ac > 💡 **Info** > When passing the `--keystore` argument, `--account` argument must be a path to the starkli account JSON file. + + ```shell $ sncast \ --keystore keystore.json \ --account account.json \ declare \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --contract-name my_contract \ --fee-token eth ``` @@ -201,6 +218,8 @@ $ sncast \ It is possible to create an openzeppelin account with keystore in a similar way [starkli](https://book.starkli.rs/accounts#accounts) does. + + ```shell $ sncast \ --keystore my_key.json \ diff --git a/docs/src/starknet/call.md b/docs/src/starknet/call.md index 541c297f5e..d16293cbe3 100644 --- a/docs/src/starknet/call.md +++ b/docs/src/starknet/call.md @@ -19,7 +19,7 @@ For a detailed CLI description, see the [call command reference](../appendix/snc ```shell $ sncast \ call \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \ --function "balance_of" \ --arguments '0x0554d15a839f0241ba465bb176d231730c01cf89cdcb95fe896c51d4a6f4bb8f' @@ -44,7 +44,7 @@ You can call a contract at the specific block by passing `--block-id` argument. ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \ --function "balance_of" \ --arguments '0x0554d15a839f0241ba465bb176d231730c01cf89cdcb95fe896c51d4a6f4bb8f' \ diff --git a/docs/src/starknet/calldata-transformation.md b/docs/src/starknet/calldata-transformation.md index 52c8aea376..e060f8766a 100644 --- a/docs/src/starknet/calldata-transformation.md +++ b/docs/src/starknet/calldata-transformation.md @@ -8,54 +8,16 @@ It's declared on Sepolia network with class hash `0x02a9b456118a86070a8c116c41b0 It has a few methods accepting different types and items defined in its namespace: ```rust -// data_transformer_contract/src/lib.cairo - -pub struct SimpleStruct { - a: felt252 -} - -pub struct NestedStructWithField { - a: SimpleStruct, - b: felt252 -} - -pub enum Enum { - One: (), - Two: u128, - Three: NestedStructWithField -} - -#[starknet::contract] -pub mod DataTransformerContract { - /* ... */ - - use super::*; - - fn tuple_fn(self: @ContractState, a: (felt252, u8, Enum)) { ... } - - fn nested_struct_fn(self: @ContractState, a: NestedStructWithField) { ... } - - fn complex_fn( - self: @ContractState, - arr: Array>, - one: u8, - two: i16, - three: ByteArray, - four: (felt252, u32), - five: bool, - six: u256 - ) { - ... - } -} +{{#include ../../listings/hello_sncast/src/data_transformer_contract.cairo}} ``` A default form of calldata passed to commands requiring it is a series of hex-encoded felts: + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --url http://127.0.0.1:5055 \ + --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function tuple_fn \ --calldata 0x10 0x3 0x0 \ --block-id latest @@ -78,12 +40,13 @@ the [Starknet specification](https://docs.starknet.io/architecture-and-concepts/ We can write the same command as above, but with arguments: + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --url http://127.0.0.1:5055 \ + --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function tuple_fn \ - --arguments '0x10, 3, data_stransformer_contract::Enum::One' \ + --arguments '(0x10, 3, hello_sncast::data_transformer_contract::Enum::One)' \ --block-id latest ``` @@ -123,10 +86,11 @@ Numeric types (primitives and `felt252`) can be paseed with type suffix specifie 1. `complex_fn` - different data types: + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --url http://127.0.0.1:5055 \ + --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function complex_fn \ --arguments \ 'array![array![1, 2], array![3, 4, 5], array![6]],'\ @@ -146,10 +110,11 @@ $ sncast call \ Alternatively, you can continue the single quote for multiple lines. + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --url http://127.0.0.1:5055 \ + --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function complex_fn \ --arguments 'array![array![1, 2], array![3, 4, 5], array![6]], 12, @@ -168,14 +133,15 @@ true, 2. `nested_struct_fn` - struct nesting: + ```shell $ sncast call \ - --url http://127.0.0.1:5050 \ - --contract-address 0x016ad425af4585102e139d4fb2c76ce786d1aaa1cfcd88a51f3ed66601b23cdd \ + --url http://127.0.0.1:5055 \ + --contract-address 0xcd7bbe72e64e86a894de5c8c9afa0ba9f0434765c52df822f18f5c93cc395f \ --function nested_struct_fn \ --arguments \ -'data_transformer_contract::NestedStructWithField {'\ -' a: data_transformer_contract::SimpleStruct { a: 10 },'\ +'hello_sncast::data_transformer_contract::NestedStructWithField {'\ +' a: hello_sncast::data_transformer_contract::SimpleStruct { a: 10 },'\ ' b: 12'\ '}'\ --block-id latest diff --git a/docs/src/starknet/declare.md b/docs/src/starknet/declare.md index 8cecbaa5e5..fe468a9c06 100644 --- a/docs/src/starknet/declare.md +++ b/docs/src/starknet/declare.md @@ -17,12 +17,14 @@ First make sure that you have created a `Scarb.toml` file for your contract (it Then run: + + ```shell -$ sncast --account myuser \ +$ sncast --account my_account \ declare \ - --url http://127.0.0.1:5050/rpc \ + --url http://127.0.0.1:5055 \ --fee-token strk \ - --contract-name SimpleBalance + --contract-name HelloSncast ```
@@ -30,12 +32,12 @@ $ sncast --account myuser \ ```shell command: declare -class_hash: 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +class_hash: [..] +transaction_hash: [..] To see declaration details, visit: -class: https://starkscan.co/search/0x8448a68b5e... -transaction: https://starkscan.co/search/0x7ad0d6e449... +class: https://starkscan.co/search/[..] +transaction: https://starkscan.co/search/[..] ```

diff --git a/docs/src/starknet/deploy.md b/docs/src/starknet/deploy.md index d4b19f8260..9d38960930 100644 --- a/docs/src/starknet/deploy.md +++ b/docs/src/starknet/deploy.md @@ -14,26 +14,27 @@ For detailed CLI description, see [deploy command reference](../appendix/sncast/ After [declaring your contract](./declare.md), you can deploy it the following way: + ```shell $ sncast \ - --account myuser \ + --account my_account \ deploy \ - --url http://127.0.0.1:5050/rpc \ + --url http://127.0.0.1:5055/rpc \ --fee-token strk \ - --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a + --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 ```
Output: ```shell -command: Deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +command: deploy +contract_address: [..] +transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/0x301316d47a... -transaction: https://starkscan.co/search/0x64a62a0002... +contract: https://sepolia.starkscan.co/contract/[..] +transaction: https://sepolia.starkscan.co/tx/[..] ```

@@ -57,11 +58,12 @@ fn constructor(ref self: ContractState, first: felt252, second: u256) { you have to pass constructor calldata to deploy it. + ```shell $ sncast deploy \ --fee-token strk \ --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ - --constructor-calldata 0x1 0x1 0x0 + --constructor-calldata 0x1 0x2 0x3 ```
@@ -69,12 +71,12 @@ $ sncast deploy \ ```shell command: deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed53035a -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +contract_address: [..] +transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/0x301316d47a... -transaction: https://starkscan.co/search/0x64a62a0002... +contract: https://sepolia.starkscan.co/contract/[..] +transaction: https://sepolia.starkscan.co/tx/[..] ```

@@ -88,10 +90,11 @@ transaction: https://starkscan.co/search/0x64a62a0002... Salt is a parameter which modifies contract's address, if not passed it will be automatically generated. + ```shell $ sncast deploy \ --fee-token strk \ - --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ + --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ --salt 0x123 ``` @@ -100,12 +103,12 @@ $ sncast deploy \ ```shell command: deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed5303bc -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +contract_address: [..] +transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/0x301316d47a... -transaction: https://starkscan.co/search/0x64a62a0002... +contract: https://sepolia.starkscan.co/contract/[..] +transaction: https://sepolia.starkscan.co/tx/[..] ```
@@ -115,10 +118,11 @@ transaction: https://starkscan.co/search/0x64a62a0002... Unique is a parameter which modifies contract's salt with the deployer address. It can be passed even if the `salt` argument was not provided. + ```shell $ sncast deploy \ --fee-token strk \ - --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a \ + --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ --unique ``` @@ -127,11 +131,11 @@ $ sncast deploy \ ```shell command: deploy -contract_address: 0x301316d47a81b39c5e27cca4a7b8ca4773edbf1103218588d6da4d3ed5303aa -transaction_hash: 0x64a62a000240e034d1862c2bbfa154aac6a8195b4b2e570f38bf4fd47a5ab1e +contract_address: [..] +transaction_hash: [..] Details: -contract: https://starkscan.co/search/0x301316d47a... -transaction: https://starkscan.co/search/0x64a62a0002... +contract: https://sepolia.starkscan.co/contract/[..] +transaction: https://sepolia.starkscan.co/tx/[..] ``` diff --git a/docs/src/starknet/fees-and-versions.md b/docs/src/starknet/fees-and-versions.md index 918ec8374c..2587abedb8 100644 --- a/docs/src/starknet/fees-and-versions.md +++ b/docs/src/starknet/fees-and-versions.md @@ -27,7 +27,7 @@ When paying in STRK, you need to either set `--fee-token` to `strk`: ```shell $ sncast account deploy \ - --name some-name \ + --name example-name \ --fee-token strk \ --max-fee 9999999999999 ``` @@ -35,7 +35,7 @@ or set `--version` to `v3`: ```shell $ sncast account deploy \ - --name some-name \ + --name example-name \ --version v3 \ --max-fee 9999999999999 ``` @@ -44,7 +44,7 @@ In case of paying in ETH, same rules apply. You need to set either `--fee-token` ```shell $ sncast account deploy \ - --name some-name \ + --name example-name \ --fee-token eth \ --max-fee 9999999999999 ``` @@ -53,7 +53,7 @@ or set `--version` to `v1`: ```shell $ sncast account deploy \ - --name some-name \ + --name example-name \ --version v1 \ --max-fee 9999999999999 ``` diff --git a/docs/src/starknet/invoke.md b/docs/src/starknet/invoke.md index 10bd551526..89d5b004fb 100644 --- a/docs/src/starknet/invoke.md +++ b/docs/src/starknet/invoke.md @@ -16,11 +16,13 @@ For detailed CLI description, see [invoke command reference](../appendix/sncast/ ### General Example + + ```shell $ sncast \ - --account example_user \ + --account my_account \ invoke \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \ --function "add" \ --fee-token eth \ @@ -35,10 +37,10 @@ $ sncast \ ```shell command: invoke -transaction_hash: 0x504f830428d0fcf462b4b814e2f67e12dfbcf3dc7847c1e36ba39d3eb7ac313 +transaction_hash: [..] To see invocation details, visit: -transaction: https://sepolia.starkscan.co/tx/0x504f830428d0fcf462b4b814e2f67e12dfbcf3dc7847c1e36ba39d3eb7ac313 +transaction: https://sepolia.starkscan.co/tx/[..] ```
@@ -53,11 +55,12 @@ transaction: https://sepolia.starkscan.co/tx/0x504f830428d0fcf462b4b814e2f67e12d Not every function accepts parameters. Here is how to call it. + ```shell $ sncast invoke \ --fee-token strk \ - --contract-address 0x4a739ab73aa3cac01f9da5d55f49fb67baee4919224454a2e3f85b16462a911 \ - --function "function_without_params" + --contract-address 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --function "get_balance" ```
@@ -65,9 +68,9 @@ $ sncast invoke \ ```shell command: invoke -transaction_hash: 0x7ad0d6e449e33b6581a4bb8df866c0fce3919a5ee05a30840ba521dafee217f +transaction_hash: [..] To see invocation details, visit: -transaction: https://starkscan.co/tx/0x7ad0d6e449... +transaction: https://sepolia.starkscan.co/tx/[..] ```
diff --git a/docs/src/starknet/multicall.md b/docs/src/starknet/multicall.md index 2134d927d0..c365ee16d2 100644 --- a/docs/src/starknet/multicall.md +++ b/docs/src/starknet/multicall.md @@ -46,8 +46,10 @@ Additionally, the `id` can be referenced in the inputs of deploy and invoke call > 📝 **Note** > For numbers larger than 2^63 - 1 (that can't fit into `i64`), use string format (e.g., `"9223372036854775808"`) due to TOML parser limitations. + + ```shell -$ sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-token strk +$ sncast multicall run --path multicall_example.toml --fee-token strk ```
@@ -55,10 +57,10 @@ $ sncast multicall run --path /Users/john/Desktop/multicall_example.toml --fee-t ```shell command: multicall -transaction_hash: 0x38fb8a0432f71bf2dae746a1b4f159a75a862e253002b48599c9611fa271dcb +transaction_hash: [..] To see invocation details, visit: -transaction: https://starkscan.co/tx/0x38fb8a0432... +transaction: https://sepolia.starkscan.co/tx/[..] ```

@@ -81,14 +83,8 @@ $ sncast multicall new ./template.toml Output: ```shell -Multicall template successfully saved in ./template.toml -``` - -
- -Resulting in output: -```toml -[[call]] +command: multicall new +content: [[call]] call_type = "deploy" class_hash = "" inputs = [] @@ -100,7 +96,11 @@ call_type = "invoke" contract_address = "" function = "" inputs = [] + +path: ./template.toml ``` + +
> ⚠️ **Warning** > Trying to pass any existing file as an output for `multicall new` will result in error, as the command doesn't overwrite by default. @@ -117,6 +117,20 @@ $ sncast multicall new ./template.toml --overwrite Output: ```shell -Multicall template successfully saved in ./new_multicall_template.toml +command: multicall new +content: [[call]] +call_type = "deploy" +class_hash = "" +inputs = [] +id = "" +unique = false + +[[call]] +call_type = "invoke" +contract_address = "" +function = "" +inputs = [] + +path: ./template.toml ``` diff --git a/docs/src/starknet/script.md b/docs/src/starknet/script.md index d822d4dda0..02e266e927 100644 --- a/docs/src/starknet/script.md +++ b/docs/src/starknet/script.md @@ -255,6 +255,8 @@ sncast_std = "0.33.0" To run the script, do: + + ```shell $ sncast \ script run my_script @@ -333,6 +335,7 @@ Please note that `map` contract was specified as the dependency. In our example, To run the script, do: + ```shell $ sncast \ --account example_user \ @@ -360,6 +363,7 @@ status: success As [an idempotency](#state-file) feature is turned on by default, executing the same script once again ends with a success and only `call` functions are being executed (as they do not change the network state): + ```shell $ sncast \ --account example_user \ @@ -384,6 +388,7 @@ status: success whereas, when we run the same script once again with `--no-state-file` flag set, it fails (as the `Map` contract is already deployed): + ```shell $ sncast \ --account example_user \ diff --git a/docs/src/starknet/show_config.md b/docs/src/starknet/show_config.md index c51664b7fb..82a49719cf 100644 --- a/docs/src/starknet/show_config.md +++ b/docs/src/starknet/show_config.md @@ -15,9 +15,8 @@ replace any subcommand (and its parameters) with `show-config` and it will show ```shell $ sncast \ - --account user1 \ - show-config \ - --url http://127.0.0.1:5050 + --account my_account \ + show-config ```
@@ -25,10 +24,9 @@ $ sncast \ ```shell command: show-config -account: user1 +account: my_account chain_id: alpha-sepolia -keystore: ../keystore -rpc_url: http://127.0.0.1:5050/rpc +rpc_url: http://127.0.0.1:5055/rpc ```

\ No newline at end of file diff --git a/docs/src/starknet/sncast-overview.md b/docs/src/starknet/sncast-overview.md index 95602ff2ca..8e3aff6b58 100644 --- a/docs/src/starknet/sncast-overview.md +++ b/docs/src/starknet/sncast-overview.md @@ -29,9 +29,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 call \ - --url http://127.0.0.1:5050 \ + --url http://127.0.0.1:5055 \ --contract-address 0x522dc7cbe288037382a02569af5a4169531053d284193623948eac8dd051716 \ --function "pokemon" \ --arguments '"Charizard"' \ @@ -80,19 +82,21 @@ Read more about it in the [Cairo documentation](https://book.cairo-lang.org/appe Let's invoke a transaction and wait for it to be `ACCEPTED_ON_L2`. + ```shell -$ sncast --account myuser \ +$ sncast --account my_account \ --wait \ deploy \ - --url http://127.0.0.1:5050 \ - --class-hash 0x8448a68b5ea1affc45e3fd4b8b480ea36a51dc34e337a16d2567d32d0c6f8a + --url http://127.0.0.1:5055 \ + --class-hash 0x0555d84fd95ab9fa84a826382ca91127336d4b3c640d8571c32c4e7717e38799 \ + --fee-token strk ```
Output: ```shell -Transaction hash: 0x3062310a1e40d4b66d8987ba7447d1c7317381d0295d62cb12f2fe3f11e6983 +Transaction hash: [..] Waiting for transaction to be received. Retries left: 11 Waiting for transaction to be received. Retries left: 10 Waiting for transaction to be received. Retries left: 9 @@ -105,12 +109,12 @@ Received transaction. Status: Pending Received transaction. Status: Pending Received transaction. Status: Pending command: deploy -contract_address: 0x1d91599ec661e97fdcbb10c642a1c4f920986f1a7a9659d157d0db09baaa29e -transaction_hash: 0x3062310a1e40d4b66d8987ba7447d1c7317381d0295d62cb12f2fe3f11e6983 +contract_address: [..] +transaction_hash: [..] To see deployment details, visit: -contract: https://starkscan.co/search/0x1d91599ec6... -transaction: https://starkscan.co/search/0x3062310a1e... +contract: https://starkscan.co/search/[..] +transaction: https://starkscan.co/search/[..] ```

diff --git a/docs/src/starknet/tx-status.md b/docs/src/starknet/tx-status.md index 8dee638a90..aa6ba7b27a 100644 --- a/docs/src/starknet/tx-status.md +++ b/docs/src/starknet/tx-status.md @@ -16,7 +16,7 @@ You can track the details about the execution and finality status of a transacti $ sncast \ tx-status \ 0x07d2067cd7675f88493a9d773b456c8d941457ecc2f6201d2fe6b0607daadfd1 \ - --url http://127.0.0.1:5050 + --url https://starknet-sepolia.public.blastapi.io ```
@@ -25,6 +25,6 @@ $ sncast \ ```shell command: tx-status execution_status: Succeeded -finality_status: AcceptedOnL2 +finality_status: AcceptedOnL1 ```
diff --git a/docs/src/starknet/verify.md b/docs/src/starknet/verify.md index 07ab134cf9..8de44190a3 100644 --- a/docs/src/starknet/verify.md +++ b/docs/src/starknet/verify.md @@ -23,11 +23,12 @@ First, ensure that you have created a `Scarb.toml` file for your contract (it sh Then run: + ```shell $ sncast \ verify \ --contract-address 0x01e4ebe3278ab4633a9d0d3f5c4290001f29bc3179a70e570b6817dd7f8264fa \ - --contract-name SimpleBalance \ + --contract-name HelloSncast \ --verifier walnut \ --network sepolia ```