0
modifier restriction(){msg.sender == 0x123456}

function myFunction() private restriction { int a = 1; int b = 2

int c = a+b; }

How do I access "c" from another function which is public view? Basically I want to make "c" available for everyone, without them knowing "a" or "b". I can't find anything about global variables in solidity

2

It's worth pointing out that a and b will be visible to any mildly interested adversary because they will be baked into the blockchain history - just in case confidentiality is important.

pragma solidity 0.4.24;

contract State {

    uint public c;

    function updateC(uint a, uint b) public {

        c = a + b;

    }
}

You get a "free" getting function with public:

function c() public view returns(uint) { return c; }

Hope it helps.

0

I was told that I can declare variables as public such as

int public c; 

function myFunction() private restriction { int a = 1; int b = 2

int c = a+b; }

I wasn't aware of this possibility!

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.