Skip to main content
7 votes

Accessing not public variables

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 ...
Shawn Tabrizi's user avatar
7 votes
Accepted

What are private variables in solidity?

According to Solidity Documentation: Private functions and state variables are only visible for the contract they are defined in and not in derived contracts. In Sol, the private keyword doesn't ...
João Quintanilha's user avatar
5 votes
Accepted

What is an example of when a solidity variable must NOT be public? Where it would break the security of the contract?

There are further security considerations. There are a few possibilities related to inheritance. The compiler is getting better at flagging unintended shadowing of variables used elsewhere but it ...
Rob Hitchens's user avatar
  • 55.4k
5 votes
Accepted

Why are parameters of external functions not lvalue types?

A public function need to write all of the arguments to memory and may be called internally, which is actually an entirely different process than external calls. Internal calls are executed via jumps ...
oktapodia's user avatar
  • 467
4 votes

What are private variables in solidity?

You are correct. private variables are only private for the smart contract scope which means they can't be accessed or modified from other smart contracts. But their values can be read freely outside ...
Lauri Peltonen's user avatar
2 votes

What are function types in Solidity used for?

The answer is why not? IMHO it is not a feature that is really needed for smart contract, but it doesn't hurt to have it available. For example it is possible to implement a kind of dispatch. (If ...
Ismael's user avatar
  • 30.5k
2 votes

What is an example of when a solidity variable must NOT be public? Where it would break the security of the contract?

You are correct that even private variables are still publicly visible due to the public nature of blockchain. So marking a variable as private will not hide it from anybody. However, making a ...
AnAllergyToAnalogy's user avatar
2 votes
Accepted

Are calls to internal pure functions cached by Solidity?

Possibly someone with deeper knowledge of compilation details will chime in with more precision. Intuitively, one might expect a slight difference to account for the extra steps of jumping into ...
Rob Hitchens's user avatar
  • 55.4k
2 votes
Accepted

Override inherited function visability

The _approve method has visibility of internal The whole idea of explicit visibility and modifiers like virtual and override is to catch developer errors at compile time. So, you'll be at cross-...
Rob Hitchens's user avatar
  • 55.4k
2 votes
Accepted

Read and write private variable from child contract

Can I simply change _tokenURIs mapping from private to internal and still be ERC721 compliant? Yes, the ERC721 standard (as any other standard) defines the contract's API, not its internal ...
goodvibration's user avatar
2 votes
Accepted

Why gas prices vary according to state visibility (public/external/private/internal)?

In Ethereum, transactions cost gas and hence ether. The gas consumption of a transaction depends on the opcodes that the EVM has to execute. So it's all about the opcode being used. More opcode, more ...
Olivier Demeaux's user avatar
2 votes

Which one is better visibility option of solidity method?

There is no one way which is absolutely better. By using an external visibility modifier, you declare intention that the function should only be used by external parties. In my opinion, using that ...
Lauri Peltonen's user avatar
1 vote

When should contract global variables be public vs private

Private variables do not have a getter function. By default, a function is private. Only public variables get a getter function from the compiler. Hope that helps.
Ishan's user avatar
  • 51
1 vote

If a solidity library function is marked as public does it inline the function or call it with a delegatecall from the calling contract?

public and external behave the same as each other in solidity library. you could the bytecode of two contracts that the only difference are one is used public another one is used external visibility ...
0xbeny's user avatar
  • 303
1 vote

Why gas prices vary according to state visibility (public/external/private/internal)?

Gas prices vary according to state visibilities mainly due to how the data are manipulated, especially between public and external specifiers. Public visibility generally costs more gas because ...
Yongjian P.'s user avatar
  • 4,218
1 vote

Is it safe to mark library functions that modify the calling contract's state as public in Solidity?

Yes, it's safe. The fragment you're citing refers to calling library functions using an ordinary external CALL instead of the typical DELEGATECALL. At the EVM level there's no difference between a ...
cameel's user avatar
  • 2,251
1 vote
Accepted

Why/Should you use private for mapping?

The only reason to write your own getter and use private for the mapping is if you want to combine the mapping somehow with some other state of the contract (add some additional value to the getter). ...
matabeitt's user avatar
1 vote
Accepted

Solidity private/internal function call from external function

One possible reason is for the sake of inheritance. If you wanted to use the logic within _updateQuorumNumerator without the onlyGovernance modifier in a child smart contract, you would want the ...
Jeremy Boetticher's user avatar
1 vote
Accepted

Why no private constructors in solidity?

I don't think it's possible, because every contract is public by construction. Creating an instance of the contract just makes it easier for someone to interact with the contract, which is impossible ...
João Paulo Morais's user avatar
1 vote

How to see data sent using a smart contract?

If your goal is to have persistent certification data storage on the blockchain, and retrieve the same, you can make use of setter and getter methods. Solidity creates a getter method for public ...
Sudeep's user avatar
  • 170
1 vote
Accepted

How to see data sent using a smart contract?

You can see the "25" in the state change tab (switch to 'number'). But the easiest is probably to make the contract emit an event, as it is easy to read all events of contract from web3.
Ossip's user avatar
  • 161
1 vote
Accepted

When does it make sense to use `this.f()` instead of making the function public?

I find myself challenged to think of a reason, because it's almost never necessary and is more expensive. It does, however, change the context, so it is useful to know that this tool is in the box. ...
Rob Hitchens's user avatar
  • 55.4k
1 vote
Accepted

Unit test compilation failed due member not found or not visible

In solidity you do not have direct access to a different contract properties even if they are public. You have to explicitely call the getter function partProductionContract.production(). But since ...
Ismael's user avatar
  • 30.5k
1 vote

Accessing not public variables

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-...
Soham Lawar's user avatar
  • 2,567
1 vote
Accepted

Calling External Contract Function with Modifiers - Results in Unknown Error

Sounds like you might have a slight misunderstanding to how calls to smart contracts, and msg.sender works. When you're calling the external Balances contract from MainContract, msg.sender will be the ...
hextet's user avatar
  • 1,583

Only top scored, non community-wiki answers of a minimum length are eligible