# Constructors

A contract may need to initialize its state before it is ready for public use. For example, one may want to designate a contract owner, that can do certain operations that other users can’t. Setting a storage variable to the owner can be done by the contract constructor. The contract constructor is defined using the `@constructor` decorator and its name must be `constructor`. The constructor semantics are similar to that of any other external function, except that the constructor is guaranteed to run during the contract deployment and it cannot be invoked again after the contract is deployed.

For example, we can define an ownable contract as follows:

``````%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin

// Define a storage variable for the owner address.
@storage_var
func owner() -> (owner_address: felt) {
}

@constructor
func constructor{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr,
return ();
}

@view
func get_owner{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr,
Save the contract as `ownable.cairo` and then compile and declare it.
``````starknet-compile ownable.cairo \
After compiling the contract, you can deploy it. When you deploy the contract, replace `${OWNABLE_CLASS_HASH}` with the class hash you got from `starknet declare`, and pass the arguments using the `--inputs` flag. The number of inputs must match the signature of the constructor, or the deploy transaction will fail. ``starknet deploy --class_hash${OWNABLE_CLASS_HASH} --inputs 123``