Constructor
constructor
is a special function that is called only once when the contract is deployed.
The main purpose of the the constructor
is to set state variables to some initial state.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract ConstructorIntro {
address public owner;
uint public x;
constructor(uint _x) {
// Here the owner is set to the caller
owner = msg.sender;
x = _x;
}
}
Last updated
Was this helpful?