Accessing not public variables

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question



























    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?










    share|improve this question

























      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 25 at 8:54

























      asked Sep 25 at 8:36









      saitam

      284310




      284310




















          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.






          share|improve this answer



























            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






            share|improve this answer




















            • True, though as mentioned in the other answer, this specific variable is not private.
              – goodvibration
              Sep 25 at 9:10


















            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






            share|improve this answer




















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "642"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              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






























              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.






              share|improve this answer
























                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.






                share|improve this answer






















                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 25 at 9:01









                  Shawn Tabrizi

                  2,9802421




                  2,9802421




















                      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






                      share|improve this answer




















                      • True, though as mentioned in the other answer, this specific variable is not private.
                        – goodvibration
                        Sep 25 at 9:10















                      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






                      share|improve this answer




















                      • True, though as mentioned in the other answer, this specific variable is not private.
                        – goodvibration
                        Sep 25 at 9:10













                      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






                      share|improve this answer












                      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







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Sep 25 at 9:10









                      Soham Lawar

                      1,374223




                      1,374223











                      • 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
















                      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











                      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






                      share|improve this answer
























                        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






                        share|improve this answer






















                          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






                          share|improve this answer












                          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







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 25 at 10:25









                          Jaime

                          3,9091216




                          3,9091216



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              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













































































                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?