0

For example, is there a difference between these two snippets of code, or is there a best practice? From my experimentation, it doesn't seem like it makes a difference. Thanks.

contract A {

uint public a;
uint public someInput;


constructor(uint _someInput) {
    a=5;
    someInput = _someInput;
}

function setA(uint _a) external {
    a = _a;
}  
}

contract A {

uint public a = 5;
uint public someInput;


constructor(uint _someInput) {
    someInput = _someInput;
}

function setA(uint _a) external {
    a = _a;
}
}
1
0

Both works. Assigning variables inside the constructor method would cost you more gas when deploying the contract. It is better to assign it inline unless you do not need a param from the constructor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.