diff --git a/Cargo.lock b/Cargo.lock index d4d8ea1951c..311018f30f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2024,6 +2024,7 @@ dependencies = [ "forc-util", "fs_extra", "fuel-asm", + "fuels-core", "hex", "serde", "serde_json", diff --git a/forc/Cargo.toml b/forc/Cargo.toml index b220aa77071..2bd69c75a26 100644 --- a/forc/Cargo.toml +++ b/forc/Cargo.toml @@ -29,6 +29,7 @@ forc-tracing = { version = "0.63.3", path = "../forc-tracing" } forc-util = { version = "0.63.3", path = "../forc-util" } fs_extra = "1.2" fuel-asm = { workspace = true } +fuels-core = { workspace = true } hex = "0.4.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.73" diff --git a/forc/src/cli/commands/contract_id.rs b/forc/src/cli/commands/contract_id.rs index 55848428aa8..127789edc7b 100644 --- a/forc/src/cli/commands/contract_id.rs +++ b/forc/src/cli/commands/contract_id.rs @@ -32,6 +32,9 @@ pub struct Command { /// Disable the "new encoding" feature #[clap(long)] pub no_encoding_v1: bool, + // Flag to display contract-id in bech32 format + #[clap(long)] + pub bech32: bool, } pub(crate) fn exec(cmd: Command) -> ForcResult<()> { diff --git a/forc/src/ops/forc_contract_id.rs b/forc/src/ops/forc_contract_id.rs index f81441637a5..f595342e99e 100644 --- a/forc/src/ops/forc_contract_id.rs +++ b/forc/src/ops/forc_contract_id.rs @@ -2,6 +2,7 @@ use crate::cli::ContractIdCommand; use anyhow::{bail, Result}; use forc_pkg::{self as pkg, build_with_options}; use forc_tracing::println_green; +use fuels_core::types::bech32::Bech32ContractId; use pkg::manifest::build_profile::ExperimentalFlags; use sway_core::{fuel_prelude::fuel_tx, BuildTarget}; use tracing::info; @@ -39,7 +40,13 @@ pub fn contract_id(command: ContractIdCommand) -> Result<()> { let storage_slots = built_contract.storage_slots.clone(); let contract_id = pkg::contract_id(&built_contract.bytecode.bytes, storage_slots, &salt); println_green(&format!(" {name}")); - info!(" Contract id: 0x{contract_id}"); + //check if --bech32 flag is present in command + if command.bech32 { + let contract_id_bech32 = Bech32ContractId::from(contract_id); + info!(" Contract id: {contract_id_bech32}"); + } else { + info!(" Contract id: 0x{contract_id}"); + } } Ok(()) }