diff --git a/docs/book/src/forc/plugins/forc_client/index.md b/docs/book/src/forc/plugins/forc_client/index.md index 13800088b96..feb436af788 100644 --- a/docs/book/src/forc/plugins/forc_client/index.md +++ b/docs/book/src/forc/plugins/forc_client/index.md @@ -92,24 +92,30 @@ By default `--default-signer` flag would sign your transactions with the followi 0xde97d8624a438121b86a1956544bd72ed68cd69f2c99555b08b1e8c51ffd511c ``` -## Interacting with the testnet +## Selecting a target network -To interact with the latest testnet, use the `--testnet` flag. When this flag is passed, transactions created by `forc-deploy` will be sent to the latest `testnet`. +By default, `local` is used for the target network. To interact with the latest testnet, use the `--testnet` flag. When this flag is passed, transactions created by `forc-deploy` will be sent to the latest `testnet`: ```sh forc-deploy --testnet ``` -It is also possible to pass the exact node URL while using `forc-deploy` or `forc-run` which can be done using `--node-url` flag. +The same can be done to target mainnet: ```sh -forc-deploy --node-url https://beta-3.fuel.network +forc-deploy --mainnet ``` -Another alternative is the `--target` option, which provides useful aliases to all targets. For example if you want to deploy to `beta-5` you can use: +It is also possible to pass the exact node URL while using `forc-deploy` or `forc-run` which can be done using `--node-url` flag: ```sh -forc-deploy --target beta-5 +forc-deploy --node-url https://mainnet.fuel.network +``` + +Another alternative is the `--target` option, which provides useful aliases to all targets. For example if you want to deploy to `testnet` you can use: + +```sh +forc-deploy --target testnet ``` Since deploying and running projects on the testnet cost gas, you will need coins to pay for them. You can get some using the [testnet faucet](https://faucet-testnet.fuel.network/). diff --git a/forc-plugins/forc-client/src/cmd/deploy.rs b/forc-plugins/forc-client/src/cmd/deploy.rs index 5553a2fe06b..87428dfbca7 100644 --- a/forc-plugins/forc-client/src/cmd/deploy.rs +++ b/forc-plugins/forc-client/src/cmd/deploy.rs @@ -10,7 +10,7 @@ forc_util::cli_examples! { super::Command { [ Deploy a single contract => "forc deploy bc09bfa7a11a04ce42b0a5abf04fd437387ee49bf4561d575177e2946468b408" ] [ Deploy a single contract from a different path => "forc deploy bc09bfa7a11a04ce42b0a5abf04fd437387ee49bf4561d575177e2946468b408 --path {path}" ] - [ Deploy to a custom network => "forc deploy --node-url https://beta-5.fuel.network/graphql" ] + [ Deploy to a custom network => "forc deploy --node-url https://testnet.fuel.network/graphql" ] } } diff --git a/forc-plugins/forc-client/src/constants.rs b/forc-plugins/forc-client/src/constants.rs index f6e1faa4201..1b195f733e6 100644 --- a/forc-plugins/forc-client/src/constants.rs +++ b/forc-plugins/forc-client/src/constants.rs @@ -1,20 +1,12 @@ /// Default to localhost to favour the common case of testing. pub const NODE_URL: &str = sway_utils::constants::DEFAULT_NODE_URL; -pub const BETA_2_ENDPOINT_URL: &str = "https://node-beta-2.fuel.network"; -pub const BETA_3_ENDPOINT_URL: &str = "https://beta-3.fuel.network"; -pub const BETA_4_ENDPOINT_URL: &str = "https://beta-4.fuel.network"; -pub const BETA_5_ENDPOINT_URL: &str = "https://beta-5.fuel.network"; -pub const DEVNET_ENDPOINT_URL: &str = "https://devnet.fuel.network"; pub const TESTNET_ENDPOINT_URL: &str = "https://testnet.fuel.network"; +pub const MAINNET_ENDPOINT_URL: &str = "https://mainnet.fuel.network"; -pub const BETA_2_FAUCET_URL: &str = "https://faucet-beta-2.fuel.network"; -pub const BETA_3_FAUCET_URL: &str = "https://faucet-beta-3.fuel.network"; -pub const BETA_4_FAUCET_URL: &str = "https://faucet-beta-4.fuel.network"; -pub const BETA_5_FAUCET_URL: &str = "https://faucet-beta-5.fuel.network"; -pub const DEVNET_FAUCET_URL: &str = "https://faucet-devnet.fuel.network"; pub const TESTNET_FAUCET_URL: &str = "https://faucet-testnet.fuel.network"; -pub const TESTNET_EXPLORER_URL: &str = "https://app.fuel.network"; +pub const TESTNET_EXPLORER_URL: &str = "https://app-testnet.fuel.network"; +pub const MAINNET_EXPLORER_URL: &str = "https://app.fuel.network"; /// Default PrivateKey to sign transactions submitted to local node. pub const DEFAULT_PRIVATE_KEY: &str = diff --git a/forc-plugins/forc-client/src/lib.rs b/forc-plugins/forc-client/src/lib.rs index cce5e5ab95e..a4db6b262a1 100644 --- a/forc-plugins/forc-client/src/lib.rs +++ b/forc-plugins/forc-client/src/lib.rs @@ -14,19 +14,27 @@ pub struct NodeTarget { /// If unspecified, checks the manifest's `network` table, then falls back /// to `http://127.0.0.1:4000` /// - /// You can also use `--target` or `--testnet` to specify the Fuel node. + /// You can also use `--target`, `--testnet`, or `--mainnet` to specify the Fuel node. #[clap(long, env = "FUEL_NODE_URL")] pub node_url: Option, + /// Use preset configurations for deploying to a specific target. /// - /// You can also use `--node-url` or `--testnet` to specify the Fuel node. + /// You can also use `--node-url`, `--testnet`, or `--mainnet` to specify the Fuel node. /// - /// Possible values are: [beta-1, beta-2, beta-3, beta-4, local] + /// Possible values are: [local, testnet, mainnet] #[clap(long)] pub target: Option, - /// Use preset configuration for the latest testnet. + + /// Use preset configuration for testnet. /// - /// You can also use `--node-url` or `--target` to specify the Fuel node. + /// You can also use `--node-url`, `--target`, or `--mainnet` to specify the Fuel node. #[clap(long)] pub testnet: bool, + + /// Use preset configuration for mainnet. + /// + /// You can also use `--node-url`, `--target`, or `--testnet` to specify the Fuel node. + #[clap(long)] + pub mainnet: bool, } diff --git a/forc-plugins/forc-client/src/op/deploy.rs b/forc-plugins/forc-client/src/op/deploy.rs index 798fd788826..cdc5d35162c 100644 --- a/forc-plugins/forc-client/src/op/deploy.rs +++ b/forc-plugins/forc-client/src/op/deploy.rs @@ -192,7 +192,7 @@ async fn deploy_chunked( let storage_slots = resolve_storage_slots(command, compiled)?; let chain_info = provider.chain_info().await?; - let target = Target::from_str(&chain_info.name).unwrap_or(Target::testnet()); + let target = Target::from_str(&chain_info.name).unwrap_or_default(); let contract_url = match target.explorer_url() { Some(explorer_url) => format!("{explorer_url}/contract/0x"), None => "".to_string(), @@ -257,7 +257,7 @@ async fn deploy_new_proxy( .into(); let chain_info = provider.chain_info().await?; - let target = Target::from_str(&chain_info.name).unwrap_or(Target::testnet()); + let target = Target::from_str(&chain_info.name).unwrap_or_default(); let contract_url = match target.explorer_url() { Some(explorer_url) => format!("{explorer_url}/contract/0x"), None => "".to_string(), @@ -948,7 +948,7 @@ fn create_deployment_artifact( let contract_id = ContractId::from_str(&deployment_artifact.contract_id).unwrap(); let pkg_name = manifest.project_name(); - let target = Target::from_str(&chain_info.name).unwrap_or(Target::testnet()); + let target = Target::from_str(&chain_info.name).unwrap_or_default(); let (contract_url, block_url) = match target.explorer_url() { Some(explorer_url) => ( format!("{explorer_url}/contract/0x"), diff --git a/forc-plugins/forc-client/src/util/node_url.rs b/forc-plugins/forc-client/src/util/node_url.rs index b7fe3f8bf39..58e9dcd87e1 100644 --- a/forc-plugins/forc-client/src/util/node_url.rs +++ b/forc-plugins/forc-client/src/util/node_url.rs @@ -12,18 +12,22 @@ pub fn get_node_url( ) -> Result { let node_url = match ( node_target.testnet, + node_target.mainnet, node_target.target.clone(), node_target.node_url.clone(), ) { - (true, None, None) => Target::testnet().target_url(), - (false, Some(target), None) => target.target_url(), - (false, None, Some(node_url)) => node_url, - (false, None, None) => manifest_network + (true, false, None, None) => Target::testnet().target_url(), + (false, true, None, None) => Target::mainnet().target_url(), + (false, false, Some(target), None) => target.target_url(), + (false, false, None, Some(node_url)) => node_url, + (false, false, None, None) => manifest_network .as_ref() .map(|nw| &nw.url[..]) .unwrap_or(crate::constants::NODE_URL) .to_string(), - _ => bail!("Only one of `--testnet`, `--target`, or `--node-url` should be specified"), + _ => bail!( + "Only one of `--testnet`, `--mainnet`, `--target`, or `--node-url` should be specified" + ), }; Ok(node_url) @@ -35,6 +39,7 @@ fn test_get_node_url_testnet() { target: None, node_url: None, testnet: true, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); @@ -42,63 +47,41 @@ fn test_get_node_url_testnet() { } #[test] -fn test_get_node_url_target_devnet() { +fn test_get_node_url_mainnet() { let input = NodeTarget { - target: Some(Target::Devnet), - node_url: None, - testnet: false, - }; - let actual = get_node_url(&input, &None).unwrap(); - assert_eq!("https://devnet.fuel.network", actual); -} - -#[test] -fn test_get_node_url_target_testnet() { - let input = NodeTarget { - target: Some(Target::Testnet), + target: None, node_url: None, testnet: false, + mainnet: true, }; let actual = get_node_url(&input, &None).unwrap(); - assert_eq!("https://testnet.fuel.network", actual); + assert_eq!("https://mainnet.fuel.network", actual); } #[test] -fn test_get_node_url_beta5() { +fn test_get_node_url_target_mainnet() { let input = NodeTarget { - target: Some(Target::Beta5), + target: Some(Target::Mainnet), node_url: None, testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); - assert_eq!("https://beta-5.fuel.network", actual); + assert_eq!("https://mainnet.fuel.network", actual); } #[test] -fn test_get_node_url_beta4() { - let input = NodeTarget { - target: None, - node_url: Some("https://beta-4.fuel.network".to_string()), - testnet: false, - }; - let actual = get_node_url(&input, &None).unwrap(); - assert_eq!("https://beta-4.fuel.network", actual); -} - -#[test] -fn test_get_node_url_url_beta4_manifest() { - let network = Network { - url: "https://beta-4.fuel.network".to_string(), - }; +fn test_get_node_url_target_testnet() { let input = NodeTarget { - target: None, + target: Some(Target::Testnet), node_url: None, testnet: false, + mainnet: false, }; - let actual = get_node_url(&input, &Some(network)).unwrap(); - assert_eq!("https://beta-4.fuel.network", actual); + let actual = get_node_url(&input, &None).unwrap(); + assert_eq!("https://testnet.fuel.network", actual); } #[test] @@ -107,29 +90,20 @@ fn test_get_node_url_default() { target: None, node_url: None, testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); assert_eq!("http://127.0.0.1:4000", actual); } -#[test] -fn test_get_node_url_beta3() { - let input = NodeTarget { - target: Some(Target::Beta3), - node_url: None, - testnet: false, - }; - let actual = get_node_url(&input, &None).unwrap(); - assert_eq!("https://beta-3.fuel.network", actual); -} - #[test] fn test_get_node_url_local() { let input = NodeTarget { target: Some(Target::Local), node_url: None, testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); assert_eq!("http://127.0.0.1:4000", actual); @@ -137,26 +111,28 @@ fn test_get_node_url_local() { #[test] #[should_panic( - expected = "Only one of `--testnet`, `--target`, or `--node-url` should be specified" + expected = "Only one of `--testnet`, `--mainnet`, `--target`, or `--node-url` should be specified" )] fn test_get_node_url_local_testnet() { let input = NodeTarget { target: Some(Target::Local), node_url: None, testnet: true, + mainnet: false, }; get_node_url(&input, &None).unwrap(); } #[test] #[should_panic( - expected = "Only one of `--testnet`, `--target`, or `--node-url` should be specified" + expected = "Only one of `--testnet`, `--mainnet`, `--target`, or `--node-url` should be specified" )] fn test_get_node_url_same_url() { let input = NodeTarget { - target: Some(Target::Beta3), - node_url: Some("beta-3.fuel.network".to_string()), + target: Some(Target::Testnet), + node_url: Some("testnet.fuel.network".to_string()), testnet: false, + mainnet: false, }; get_node_url(&input, &None).unwrap(); } diff --git a/forc-plugins/forc-client/src/util/target.rs b/forc-plugins/forc-client/src/util/target.rs index 86b9b947666..3982f91ce07 100644 --- a/forc-plugins/forc-client/src/util/target.rs +++ b/forc-plugins/forc-client/src/util/target.rs @@ -1,8 +1,6 @@ use crate::constants::{ - BETA_2_ENDPOINT_URL, BETA_2_FAUCET_URL, BETA_3_ENDPOINT_URL, BETA_3_FAUCET_URL, - BETA_4_ENDPOINT_URL, BETA_4_FAUCET_URL, BETA_5_ENDPOINT_URL, BETA_5_FAUCET_URL, - DEVNET_ENDPOINT_URL, DEVNET_FAUCET_URL, NODE_URL, TESTNET_ENDPOINT_URL, TESTNET_EXPLORER_URL, - TESTNET_FAUCET_URL, + MAINNET_ENDPOINT_URL, MAINNET_EXPLORER_URL, NODE_URL, TESTNET_ENDPOINT_URL, + TESTNET_EXPLORER_URL, TESTNET_FAUCET_URL, }; use anyhow::{bail, Result}; use serde::{Deserialize, Serialize}; @@ -11,12 +9,8 @@ use std::str::FromStr; #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] /// Possible target values that forc-client can interact with. pub enum Target { - Beta2, - Beta3, - Beta4, - Beta5, - Devnet, Testnet, + Mainnet, Local, } @@ -29,12 +23,8 @@ impl Default for Target { impl Target { pub fn target_url(&self) -> String { let url = match self { - Target::Beta2 => BETA_2_ENDPOINT_URL, - Target::Beta3 => BETA_3_ENDPOINT_URL, - Target::Beta4 => BETA_4_ENDPOINT_URL, - Target::Beta5 => BETA_5_ENDPOINT_URL, - Target::Devnet => DEVNET_ENDPOINT_URL, Target::Testnet => TESTNET_ENDPOINT_URL, + Target::Mainnet => MAINNET_ENDPOINT_URL, Target::Local => NODE_URL, }; url.to_string() @@ -42,36 +32,37 @@ impl Target { pub fn from_target_url(target_url: &str) -> Option { match target_url { - BETA_2_ENDPOINT_URL => Some(Target::Beta2), - BETA_3_ENDPOINT_URL => Some(Target::Beta3), - BETA_4_ENDPOINT_URL => Some(Target::Beta4), - BETA_5_ENDPOINT_URL => Some(Target::Beta5), - DEVNET_ENDPOINT_URL => Some(Target::Devnet), TESTNET_ENDPOINT_URL => Some(Target::Testnet), + MAINNET_ENDPOINT_URL => Some(Target::Mainnet), NODE_URL => Some(Target::Local), _ => None, } } + pub fn local() -> Self { + Target::Local + } + pub fn testnet() -> Self { Target::Testnet } - pub fn faucet_url(&self) -> String { + pub fn mainnet() -> Self { + Target::Mainnet + } + + pub fn faucet_url(&self) -> Option { match self { - Target::Beta2 => BETA_2_FAUCET_URL.to_string(), - Target::Beta3 => BETA_3_FAUCET_URL.to_string(), - Target::Beta4 => BETA_4_FAUCET_URL.to_string(), - Target::Beta5 => BETA_5_FAUCET_URL.to_string(), - Target::Devnet => DEVNET_FAUCET_URL.to_string(), - Target::Testnet => TESTNET_FAUCET_URL.to_string(), - Target::Local => "http://localhost:3000".to_string(), + Target::Testnet => Some(TESTNET_FAUCET_URL.to_string()), + Target::Mainnet => None, + Target::Local => Some("http://localhost:3000".to_string()), } } pub fn explorer_url(&self) -> Option { match self { - Target::Testnet | Target::Devnet => Some(TESTNET_EXPLORER_URL.to_string()), + Target::Testnet => Some(TESTNET_EXPLORER_URL.to_string()), + Target::Mainnet => Some(MAINNET_EXPLORER_URL.to_string()), _ => None, } } @@ -82,21 +73,13 @@ impl FromStr for Target { fn from_str(s: &str) -> Result { match s { - "beta-2" => Ok(Target::Beta2), - "beta-3" => Ok(Target::Beta3), - "beta-4" => Ok(Target::Beta4), - "beta-5" => Ok(Target::Beta5), - "devnet" => Ok(Target::Devnet), "testnet" => Ok(Target::Testnet), + "mainnet" => Ok(Target::Mainnet), "local" => Ok(Target::Local), _ => bail!( - "'{s}' is not a valid target name. Possible values: '{}', '{}', '{}', '{}', '{}', '{}', '{}'", - Target::Beta2, - Target::Beta3, - Target::Beta4, - Target::Beta5, - Target::Devnet, + "'{s}' is not a valid target name. Possible values: '{}', '{}', '{}'", Target::Testnet, + Target::Mainnet, Target::Local ), } @@ -106,12 +89,8 @@ impl FromStr for Target { impl std::fmt::Display for Target { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let s = match self { - Target::Beta2 => "beta-2", - Target::Beta3 => "beta-3", - Target::Beta4 => "beta-4", - Target::Beta5 => "beta-5", - Target::Devnet => "devnet", Target::Testnet => "testnet", + Target::Mainnet => "mainnet", Target::Local => "local", }; write!(f, "{}", s) diff --git a/forc-plugins/forc-client/src/util/tx.rs b/forc-plugins/forc-client/src/util/tx.rs index d5a002e809f..d1ceb751194 100644 --- a/forc-plugins/forc-client/src/util/tx.rs +++ b/forc-plugins/forc-client/src/util/tx.rs @@ -181,12 +181,19 @@ pub(crate) async fn select_account( let first_account = accounts .get(&0) .ok_or_else(|| anyhow::anyhow!("No account derived for this wallet"))?; - let target = Target::from_str(&chain_info.name).unwrap_or(Target::testnet()); - let faucet_link = format!("{}/?address={first_account}", target.faucet_url()); - anyhow::bail!("Your wallet does not have any funds to pay for the transaction.\ - \n\nIf you are interacting with a testnet consider using the faucet.\ - \n-> {target} network faucet: {faucet_link}\ - \nIf you are interacting with a local node, consider providing a chainConfig which funds your account.") + let target = Target::from_str(&chain_info.name).unwrap_or_default(); + let message = if let Some(faucet_url) = target.faucet_url() { + format!( + "Your wallet does not have any funds to pay for the transaction.\ + \n\nIf you are interacting with a testnet, consider using the faucet.\ + \n-> {target} network faucet: {}/?address={first_account}\ + \nIf you are interacting with a local node, consider providing a chainConfig which funds your account.", + faucet_url + ) + } else { + "Your wallet does not have any funds to pay for the transaction.".to_string() + }; + anyhow::bail!(message) } let selections = format_base_asset_account_balances(&accounts, &account_balances, base_asset_id); diff --git a/forc-plugins/forc-client/tests/deploy.rs b/forc-plugins/forc-client/tests/deploy.rs index adb83853318..e1f416062ff 100644 --- a/forc-plugins/forc-client/tests/deploy.rs +++ b/forc-plugins/forc-client/tests/deploy.rs @@ -360,6 +360,7 @@ async fn test_simple_deploy() { node_url: Some(node_url), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -401,6 +402,7 @@ async fn test_deploy_submit_only() { node_url: Some(node_url), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -447,6 +449,7 @@ async fn test_deploy_fresh_proxy() { node_url: Some(node_url), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -498,6 +501,7 @@ async fn test_proxy_contract_re_routes_call() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -555,6 +559,7 @@ async fn test_proxy_contract_re_routes_call() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -629,6 +634,7 @@ async fn test_non_owner_fails_to_set_target() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -732,6 +738,7 @@ async fn chunked_deploy() { node_url: Some(node_url), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -764,6 +771,7 @@ async fn chunked_deploy_re_routes_calls() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -806,6 +814,7 @@ async fn chunked_deploy_with_proxy_re_routes_call() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -838,6 +847,7 @@ async fn can_deploy_script() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -868,6 +878,7 @@ async fn deploy_script_calls() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -899,6 +910,7 @@ async fn deploy_script_calls() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -989,6 +1001,7 @@ async fn can_deploy_predicates() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -1019,6 +1032,7 @@ async fn deployed_predicate_call() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -1164,6 +1178,7 @@ async fn call_with_forc_generated_overrides(node_url: &str, contract_id: Contrac node_url: Some(node_url.to_string()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -1273,6 +1288,7 @@ async fn offset_shifted_abi_works() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg,