Hello,
I have a quick question. Can i change a private variable to public when upgrading a contract?
Hello,
I have a quick question. Can i change a private variable to public when upgrading a contract?
Hey, happy new year!
Yes, I think so, maybe later I can have a test to confirm.
Cause I think all variables in the contract can be got, just with different levels of difficulty. For public
and external
, you can get them from the contract directly, but for the private
and internal
, you should use another way, such as by the method web3.eth.getStorageAt in the web3.js
Hi @Dellybro,
I assume visibility has no impact on how state variables are stored. As long as you are not changing type or order of state variables this should be fine, though I recommend (as @Skyge said) trying it out yourself.
Could you please show your code?
Hi @Dellybro,
The keyword override
applies to functions, and not state variables: https://docs.soliditylang.org/en/v0.8.0/contracts.html?highlight=override#function-overriding
So we are using this variable in another contract, so we use the override keyword so it “implements” it’s interface
https://docs.soliditylang.org/en/v0.5.3/contracts.html#visibility-and-getters
Hi @Dellybro,
I am still not sure what you mean. Can you give a simple example. Something like the following?
// contracts/A.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.0;
contract A {
uint256 public value;
}
// contracts/B.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.0;
import "./A.sol";
contract B is A {
uint256 public value;
}
Hi @Dellybro,
Is this what you were referring to: Is public state var auto getter override upgrade safe? - #2 by Skyge