declare
pub fn declare(contract_name: ByteArray, fee_settings: FeeSettings, nonce: Option<felt252>) -> Result<DeclareResult, ScriptCommandError>
Declares a contract and returns DeclareResult
.
contract_name
- name of a contract as Cairo string. It is a name of the contract (part aftermod
keyword) e.g."HelloStarknet"
.fee_settings
- fee settings for the transaction. Can beEth
orStrk
. Read more about it herenonce
- nonce for declare transaction. If not provided, nonce will be set automatically.
use sncast_std::{declare, DeclareResult, FeeSettings, EthFeeSettings};
fn main() {
let max_fee = 9999999;
let result = declare(
"HelloStarknet",
FeeSettings::Eth(EthFeeSettings { max_fee: Option::Some(max_fee) }),
Option::None
)
.expect('declare failed');
println!("declare result: {}", result);
println!("debug declare result: {:?}", result);
}
Returned Type
- If the contract has not been declared,
DeclareResult::Success
is returned containing respective transaction hash. - If the contract has already been declared,
DeclareResult::AlreadyDeclared
is returned.
Getting the Class Hash
Both variants contain class_hash
of the declared contract. Import DeclareResultTrait
to access it.
pub trait DeclareResultTrait {
fn class_hash(self: @DeclareResult) -> @ClassHash;
}
Structures Used by the Command
#[derive(Drop, Copy, Debug, Serde)]
pub enum DeclareResult {
Success: DeclareTransactionResult,
AlreadyDeclared: AlreadyDeclaredResult,
}
#[derive(Drop, Copy, Debug, Serde)]
pub struct DeclareTransactionResult {
pub class_hash: ClassHash,
pub transaction_hash: felt252,
}
#[derive(Drop, Copy, Debug, Serde)]
pub struct AlreadyDeclaredResult {
pub class_hash: ClassHash,
}
#[derive(Drop, Clone, Debug, Serde, PartialEq)]
pub struct EthFeeSettings {
pub max_fee: Option<felt252>,
}
#[derive(Drop, Clone, Debug, Serde, PartialEq)]
pub struct StrkFeeSettings {
pub max_fee: Option<felt252>,
pub max_gas: Option<u64>,
pub max_gas_unit_price: Option<u128>,
}