Web3 Dictionary Logo
Web3 Dictionary
Contribute

Categories

AllBlockchainDappsDAOsDeFiNFTsRegulationSecuritySmart ContractsTokenomicsWalletsWeb3 GamingOthers
  1. Web3 Dictionary
  2. Smart Contracts
  3. Constructor
Smart Contracts

Constructor

A special function that runs once when a contract is deployed, used to initialize state variables.

Last Updated

2026-03-19

Related Concepts

Smart ContractSolidityContract Deployment
Web3-Explorer Logo

Scale Blockchain Infra

AD

Smart contracts, protocol integrations, and scalable architecture for high-performance Web3 products.

See Blockchain Services

What is Constructor?

A constructor is a special function in a smart contract that runs only onceat the exact moment the contract is deployed. It is used to initialize the contract's starting state and settings.

How does Constructor work?

  1. When writing code (e.g., in Solidity), the developer defines the constructor function.
  2. This function can accept "arguments" like the name of a token or an owner's address.
  3. When the contract is sent to the blockchain, these arguments are provided by the deployer.
  4. The blockchain executes the constructor logic, sets the initial variables, and then discards the code.
  5. The constructor code is never stored in the final contract's "runtime bytecode" and cannot be called again.

Why does Constructor matter?

Constructors are essential for setting the "birth" parameters of a contract. They ensure that roles like the "Owner" are assigned immediately upon deployment, preventing unauthorized users from taking control of the contract later.

Key features of Constructor

  • Runs exactly once at deployment
  • Used for initial state setup
  • Can receive external parameters
  • Not callable after deployment
  • Essential for security and role assignment

Examples of Constructor

  • An ERC-20 contract using a constructor to mint the initial token supply to the creator.
  • A multisig wallet using a constructor to set the list of authorized signers.
  • A DeFi protocol setting the initial "Treasury" address during its launch.

External References

  • Solidity Constructors
  • Solidity Contracts Documentation