Accessing not public variables
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Is it possible as the creater of the smart contract to access a not public variable? E.g.:
contract MyContract
uint256 someLevel;
function changeLevel(uint _newLevel) public
someLevel = _newLevel;
How would I access in this case someLevel
via web3 or at all?
solidity web3js access visibility
add a comment |Â
up vote
2
down vote
favorite
Is it possible as the creater of the smart contract to access a not public variable? E.g.:
contract MyContract
uint256 someLevel;
function changeLevel(uint _newLevel) public
someLevel = _newLevel;
How would I access in this case someLevel
via web3 or at all?
solidity web3js access visibility
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Is it possible as the creater of the smart contract to access a not public variable? E.g.:
contract MyContract
uint256 someLevel;
function changeLevel(uint _newLevel) public
someLevel = _newLevel;
How would I access in this case someLevel
via web3 or at all?
solidity web3js access visibility
Is it possible as the creater of the smart contract to access a not public variable? E.g.:
contract MyContract
uint256 someLevel;
function changeLevel(uint _newLevel) public
someLevel = _newLevel;
How would I access in this case someLevel
via web3 or at all?
solidity web3js access visibility
solidity web3js access visibility
edited Sep 25 at 8:54
asked Sep 25 at 8:36
saitam
284310
284310
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
3
down vote
All variables on Ethereum are accessible and readable by everyone in the contract storage, even if they are marked private
. In the situation where you want to access the contract storage, you can do so using web3.eth.getStorageAt()
:
web3.eth.getStorageAt(contractAddress, 0)
.then(console.log);
If your contract only stores this one variable, it should be the first index in the storage as noted above.
That being said, in your sample, the variable is not marked private, so then it is made public by default, and there should be a getter function automatically generated for it. So you can simply call that function to read the variable.
add a comment |Â
up vote
1
down vote
It is very much possible to see values of even private variables stored in the smart contract.
Refer the following blog for more details -
https://hackernoon.com/your-private-solidity-variable-is-not-private-save-it-before-it-becomes-public-52a723f29f5e
True, though as mentioned in the other answer, this specific variable is notprivate
.
â goodvibration
Sep 25 at 9:10
add a comment |Â
up vote
0
down vote
The other answers are right in the fact that is possible to access the storage of any contract deployed in ethereum, including private variables.
However, I do not think this answer the question. The questions if this is possible form another contract. Reading the storage of a contract from another contract is not possible (as far as I know). From the point of view of a contract, it can only do what the code in it allows to.
Hope this helps
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
All variables on Ethereum are accessible and readable by everyone in the contract storage, even if they are marked private
. In the situation where you want to access the contract storage, you can do so using web3.eth.getStorageAt()
:
web3.eth.getStorageAt(contractAddress, 0)
.then(console.log);
If your contract only stores this one variable, it should be the first index in the storage as noted above.
That being said, in your sample, the variable is not marked private, so then it is made public by default, and there should be a getter function automatically generated for it. So you can simply call that function to read the variable.
add a comment |Â
up vote
3
down vote
All variables on Ethereum are accessible and readable by everyone in the contract storage, even if they are marked private
. In the situation where you want to access the contract storage, you can do so using web3.eth.getStorageAt()
:
web3.eth.getStorageAt(contractAddress, 0)
.then(console.log);
If your contract only stores this one variable, it should be the first index in the storage as noted above.
That being said, in your sample, the variable is not marked private, so then it is made public by default, and there should be a getter function automatically generated for it. So you can simply call that function to read the variable.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
All variables on Ethereum are accessible and readable by everyone in the contract storage, even if they are marked private
. In the situation where you want to access the contract storage, you can do so using web3.eth.getStorageAt()
:
web3.eth.getStorageAt(contractAddress, 0)
.then(console.log);
If your contract only stores this one variable, it should be the first index in the storage as noted above.
That being said, in your sample, the variable is not marked private, so then it is made public by default, and there should be a getter function automatically generated for it. So you can simply call that function to read the variable.
All variables on Ethereum are accessible and readable by everyone in the contract storage, even if they are marked private
. In the situation where you want to access the contract storage, you can do so using web3.eth.getStorageAt()
:
web3.eth.getStorageAt(contractAddress, 0)
.then(console.log);
If your contract only stores this one variable, it should be the first index in the storage as noted above.
That being said, in your sample, the variable is not marked private, so then it is made public by default, and there should be a getter function automatically generated for it. So you can simply call that function to read the variable.
answered Sep 25 at 9:01
Shawn Tabrizi
2,9802421
2,9802421
add a comment |Â
add a comment |Â
up vote
1
down vote
It is very much possible to see values of even private variables stored in the smart contract.
Refer the following blog for more details -
https://hackernoon.com/your-private-solidity-variable-is-not-private-save-it-before-it-becomes-public-52a723f29f5e
True, though as mentioned in the other answer, this specific variable is notprivate
.
â goodvibration
Sep 25 at 9:10
add a comment |Â
up vote
1
down vote
It is very much possible to see values of even private variables stored in the smart contract.
Refer the following blog for more details -
https://hackernoon.com/your-private-solidity-variable-is-not-private-save-it-before-it-becomes-public-52a723f29f5e
True, though as mentioned in the other answer, this specific variable is notprivate
.
â goodvibration
Sep 25 at 9:10
add a comment |Â
up vote
1
down vote
up vote
1
down vote
It is very much possible to see values of even private variables stored in the smart contract.
Refer the following blog for more details -
https://hackernoon.com/your-private-solidity-variable-is-not-private-save-it-before-it-becomes-public-52a723f29f5e
It is very much possible to see values of even private variables stored in the smart contract.
Refer the following blog for more details -
https://hackernoon.com/your-private-solidity-variable-is-not-private-save-it-before-it-becomes-public-52a723f29f5e
answered Sep 25 at 9:10
Soham Lawar
1,374223
1,374223
True, though as mentioned in the other answer, this specific variable is notprivate
.
â goodvibration
Sep 25 at 9:10
add a comment |Â
True, though as mentioned in the other answer, this specific variable is notprivate
.
â goodvibration
Sep 25 at 9:10
True, though as mentioned in the other answer, this specific variable is not
private
.â goodvibration
Sep 25 at 9:10
True, though as mentioned in the other answer, this specific variable is not
private
.â goodvibration
Sep 25 at 9:10
add a comment |Â
up vote
0
down vote
The other answers are right in the fact that is possible to access the storage of any contract deployed in ethereum, including private variables.
However, I do not think this answer the question. The questions if this is possible form another contract. Reading the storage of a contract from another contract is not possible (as far as I know). From the point of view of a contract, it can only do what the code in it allows to.
Hope this helps
add a comment |Â
up vote
0
down vote
The other answers are right in the fact that is possible to access the storage of any contract deployed in ethereum, including private variables.
However, I do not think this answer the question. The questions if this is possible form another contract. Reading the storage of a contract from another contract is not possible (as far as I know). From the point of view of a contract, it can only do what the code in it allows to.
Hope this helps
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The other answers are right in the fact that is possible to access the storage of any contract deployed in ethereum, including private variables.
However, I do not think this answer the question. The questions if this is possible form another contract. Reading the storage of a contract from another contract is not possible (as far as I know). From the point of view of a contract, it can only do what the code in it allows to.
Hope this helps
The other answers are right in the fact that is possible to access the storage of any contract deployed in ethereum, including private variables.
However, I do not think this answer the question. The questions if this is possible form another contract. Reading the storage of a contract from another contract is not possible (as far as I know). From the point of view of a contract, it can only do what the code in it allows to.
Hope this helps
answered Sep 25 at 10:25
Jaime
3,9091216
3,9091216
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f59401%2faccessing-not-public-variables%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password