Skip to content

Commit 05c42a2

Browse files
authored
Prompt to add account to sncast config after deployment (#3280)
<!-- Reference any GitHub issues resolved by this PR --> Closes # ## Introduced changes <!-- A brief description of the changes --> - Changed the logic that prompts user to add account to `sncast` profile, to run after running `account deploy` not `account create` - Removed some default values placeholders from global config ## 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 b61796c commit 05c42a2

File tree

7 files changed

+34
-27
lines changed

7 files changed

+34
-27
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929

3030
- Bug that prevented from passing values to `--arguments` that started with a leading minus `-` sign.
3131

32+
### Cast
33+
34+
### Fixed
35+
36+
- User is now prompted to save an imported or deployed account in `sncast` config even when using `--network` flag
37+
3238
## [0.41.0] - 2025-04-08
3339

3440
### Forge

crates/sncast/src/helpers/config.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::helpers::constants::DEFAULT_ACCOUNTS_FILE;
44
use anyhow::Result;
55
use camino::Utf8PathBuf;
66
use indoc::formatdoc;
7-
use shared::consts::FREE_RPC_PROVIDER_URL;
87
use std::fs;
98
use std::fs::File;
109
use std::io::Write;
@@ -44,22 +43,19 @@ fn build_default_manifest() -> String {
4443
# and https://foundry-rs.github.io/starknet-foundry/projects/configuration.html for more information
4544
4645
# [sncast.default]
47-
# url = "{default_url}"
46+
# url = ""
4847
# block-explorer = "{default_block_explorer}"
4948
# wait-params = {{ timeout = {default_wait_timeout}, retry-interval = {default_wait_retry_interval} }}
5049
# show-explorer-links = {default_show_explorer_links}
5150
# accounts-file = "{default_accounts_file}"
52-
# account = "{default_account}"
53-
# keystore = "{default_keystore}"
51+
# account = ""
52+
# keystore = ""
5453
"#,
55-
default_url = FREE_RPC_PROVIDER_URL,
5654
default_accounts_file = DEFAULT_ACCOUNTS_FILE,
5755
default_wait_timeout = default_wait_params.timeout,
5856
default_wait_retry_interval = default_wait_params.retry_interval,
5957
default_block_explorer = "StarkScan",
6058
default_show_explorer_links = show_explorer_links_default(),
61-
default_account = "default",
62-
default_keystore = ""
6359
}
6460
}
6561

crates/sncast/src/main.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -520,15 +520,6 @@ async fn run_async_command(
520520
)
521521
.await;
522522

523-
let run_interactive_prompt =
524-
!create.silent && result.is_ok() && io::stdout().is_terminal();
525-
526-
if run_interactive_prompt {
527-
if let Err(err) = prompt_to_add_account_as_default(&account) {
528-
eprintln!("Error: Failed to launch interactive prompt: {err}");
529-
}
530-
}
531-
532523
print_command_result("account create", &result, numbers_format, output_format)?;
533524
print_block_explorer_link_if_allowed(
534525
&result,
@@ -550,7 +541,7 @@ async fn run_async_command(
550541
let result = starknet_commands::account::deploy::deploy(
551542
&provider,
552543
config.accounts_file,
553-
deploy,
544+
&deploy,
554545
chain_id,
555546
wait_config,
556547
&config.account,
@@ -559,6 +550,19 @@ async fn run_async_command(
559550
)
560551
.await;
561552

553+
let run_interactive_prompt =
554+
!deploy.silent && result.is_ok() && io::stdout().is_terminal();
555+
556+
if config.keystore.is_none() && run_interactive_prompt {
557+
if let Err(err) = prompt_to_add_account_as_default(
558+
&deploy
559+
.name
560+
.expect("Must be provided if not using a keystore"),
561+
) {
562+
eprintln!("Error: Failed to launch interactive prompt: {err}");
563+
}
564+
}
565+
562566
print_command_result("account deploy", &result, numbers_format, output_format)?;
563567
print_block_explorer_link_if_allowed(
564568
&result,

crates/sncast/src/starknet_commands/account/create.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ pub struct Create {
5353

5454
#[command(flatten)]
5555
pub rpc: RpcArgs,
56-
57-
/// If passed, the command will not trigger an interactive prompt to add an account as a default
58-
#[arg(long)]
59-
pub silent: bool,
6056
}
6157

6258
pub async fn create(

crates/sncast/src/starknet_commands/account/deploy.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ pub struct Deploy {
3636

3737
#[command(flatten)]
3838
pub rpc: RpcArgs,
39+
40+
/// If passed, the command will not trigger an interactive prompt to add an account as a default
41+
#[arg(long)]
42+
pub silent: bool,
3943
}
4044

4145
#[expect(clippy::too_many_arguments)]
4246
pub async fn deploy(
4347
provider: &JsonRpcClient<HttpTransport>,
4448
accounts_file: Utf8PathBuf,
45-
deploy_args: Deploy,
49+
deploy_args: &Deploy,
4650
chain_id: Felt,
4751
wait_config: WaitForTx,
4852
account: &str,
@@ -62,6 +66,7 @@ pub async fn deploy(
6266
} else {
6367
let account_name = deploy_args
6468
.name
69+
.clone()
6570
.ok_or_else(|| anyhow!("Required argument `--name` not provided"))?;
6671
check_account_file_exists(&accounts_file)?;
6772
deploy_from_accounts_file(

docs/src/appendix/sncast/account/create.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,3 @@ If passed, a profile with corresponding name will be added to the local snfoundr
5757
Optional.
5858

5959
Class hash of a custom openzeppelin account contract declared to the network.
60-
61-
## `--silent`
62-
Optional.
63-
64-
If passed, the command will not trigger an interactive prompt to add an account as a default

docs/src/appendix/sncast/account/deploy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ Maximum L1 data gas for the `deploy_account` transaction. When not used, default
5454
Optional.
5555

5656
Maximum L1 data gas unit price for the `deploy_account` transaction. When not used, defaults to auto-estimation.
57+
58+
## `--silent`
59+
Optional.
60+
61+
If passed, the command will not trigger an interactive prompt to add an account as a default

0 commit comments

Comments
 (0)