Skip to main content

Questions tagged [visibility]

Questions regarding the types of visibility for function and state variables (external, internal, public, private, etc.)

Filter by
Sorted by
Tagged with
2 votes
2 answers
67 views

When should contract global variables be public vs private

Contract A { uint public x = 1; uint private y = 2; function getY() external view returns(uint){ return y; } } If a contract has important global variables that need to be ...
0xOmen's user avatar
  • 21
0 votes
1 answer
265 views

Can you change an overridden function's visibility/mutability?

Say I have a parent and a child contract, in the child I don't want to use one of the parent's functions, so I changed the logic to just revert if it is ever called. Now the terminal output shows me ...
Rohan Nero's user avatar
  • 1,725
1 vote
0 answers
73 views

Explicitly linked Solidity libraries produce bigger contract size than having it embedded

If I replace all the library functions' visibility to either external or public, I will have to deploy the libraries separately first, and then explicitly link them in the contract which is using them....
user2340939's user avatar
0 votes
0 answers
31 views

Function Visibility specifiers during inheritance

when am overriding a function in solidity must my child function have the same visibility as the parent function? can the parent function be public and the child function be internal
Emmanuel Anah's user avatar
0 votes
1 answer
46 views

Differences between function visibility features in Libraries

Function visibility in Libraries seems to provide different set of features than in ordinary contracts. I think that also depends on the library type - if it is externally deployed or if it's code is ...
lqzic's user avatar
  • 1
2 votes
2 answers
440 views

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

I am aware that a solidity library function marked as external will be deployed separately and called with delegatecall from the calling contract. Whereas a function marked as internal will just be ...
FreddyC's user avatar
  • 311
0 votes
2 answers
733 views

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

Why gas prices vary according to state visibility(public/external/private/internal) to Function?
imelon2's user avatar
  • 590
0 votes
1 answer
38 views

wrapper getter functions

OpenZeppelin's ERC20 token contract contains the following declaration of decimals, and then a getter function for accessing that variable: uint8 private decimals; function decimals() public view ...
Eric Falkenstein's user avatar
0 votes
1 answer
15 views

Why is so common to see internal function calls from (seemingly) useless wrapping external functions?

Many times I see this type of architecture within a smart contract: function mint(uint256 amount) external { require(msg.sender == owner, "Only owner can mint tokens"); _mint(amount);...
Hiperfly's user avatar
0 votes
1 answer
177 views

Why/Should you use private for mapping?

mapping(address => uint) private _balances; function balance() public view returns (uint) { return _balances[msg.sender]; } My question is. Should you/Why/When should you use private ...
smenir443's user avatar
  • 135
1 vote
1 answer
320 views

Solidity private/internal function call from external function

what the purpose of that way to restrict access to function call? function updateQuorumNumerator(uint256 newQuorumNumerator) external virtual onlyGovernance { _updateQuorumNumerator(...
4rgon4ut's user avatar
0 votes
1 answer
72 views

Why no private constructors in solidity?

I am looking for a mechanism that allows me to restrict the creation of a contract A from anywhere but another contract B. contract A { // ... } contract B { constructor() { A a = new ...
Jacob Krieg's user avatar
0 votes
1 answer
41 views

Why Remix is telling me to use "pure"?

// SPDX-License-Identifier: MIT pragma solidity ^0.6.0; contract enumTesting{ enum frenchFriesSize {large, medium, small} frenchFriesSize choice; frenchFriesSize constant defaultChoice = ...
CorujaNoturna's user avatar
1 vote
1 answer
68 views

Which one is better visibility option of solidity method?

I have a external method declared. At some point I realized that I need to call that external method from one of the another method within a contract and which is not possible. There are options to ...
NinjaMAN's user avatar
  • 419
6 votes
1 answer
519 views

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

I am using libraries to reduce the cost of deployment of a contract of which there may be many instances (using a factory contract). When I mark a library function as internal, the code seems to get ...
dorian108's user avatar
1 vote
1 answer
277 views

Are calls to internal pure functions cached by Solidity?

One of my library functions calls another internal pure function like this: library MyLibrary { function foo(uint256 x) internal pure returns (uint256 result) { // do important work } ...
Paul Razvan Berg's user avatar
2 votes
1 answer
3k views

Override inherited function visability

I have a contract that looks like this: pragma solidity ^0.6.0; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract SwappableToken is ERC20 { constructor(string memory name, ...
Patrick Collins's user avatar
1 vote
1 answer
246 views

Read and write private variable from child contract

I have a contract MyContract is ERC721. MyContract needs to concatenate a string with an existing token URI using this function: string(abi.encodePacked(_tokenURIs[_tokenId], _URI)); Problem is all ...
Pm Rivière's user avatar
8 votes
2 answers
15k views

What are private variables in solidity?

The following variables here, assuming solidity 4.24 or later. mapping(something => something) private yourmapping; bool private yourbool; address private youraddress; uint256 private ...
Fifth Dimension Dragon's user avatar
3 votes
2 answers
1k views

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

I'm really struggling to understand variable visibility. I'm aware that everything is public on a blockchain. Yes you can make a variable private to make it invisible to other contracts, but so what? ...
Andrew Stanger's user avatar
1 vote
2 answers
244 views

How to see data sent using a smart contract?

See this transaction: https://rinkeby.etherscan.io/tx/0xf38b9f1fdb1a6f309bb4671bbcee235c9b75685ac96f99955d59b9a112db1156 Is referred to the creation of this contract: https://rinkeby.etherscan.io/...
realtebo's user avatar
  • 343
1 vote
1 answer
190 views

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

In external vs public best practices, Tjaden Hess says that: It almost never makes sense to use the this.f() pattern, as this requires a real CALL to be executed, which is expensive So why does ...
Paul Razvan Berg's user avatar
0 votes
2 answers
47 views

Can events always be called directly by user accounts? Is there a way to make them internal?

I am using events to fire an order, basically using them as a vehicle for a master/slave connection with an IoT device, through the blockchain. Ideally i want to always verify the right msg.sender is ...
Leo A's user avatar
  • 1
1 vote
1 answer
170 views

Unit test compilation failed due member not found or not visible

I have written an unit test but when I launch it I get following error: Test.sol:25:22: TypeError: Member "val1" not found or not visible after argument-dependent lookup in function () view external ...
kitsune's user avatar
  • 219
4 votes
1 answer
458 views

What are function types in Solidity used for?

Can you provide an example of when and why you would want to define and use a function type, as a opposed to simply calling a function? I understand how from here: https://ethereum.stackexchange.com/...
valem's user avatar
  • 317
4 votes
3 answers
2k views

Accessing not public variables

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 { ...
sunwarr10r's user avatar
0 votes
1 answer
1k views

Calling External Contract Function with Modifiers - Results in Unknown Error

I am attempting to call an external contract function, but modifier on the function is throwing an error. And I can't figure out why. Any help is appreciated! Info is below: I have two contracts: ...
Nick Major's user avatar
2 votes
1 answer
741 views

Why are parameters of external functions not lvalue types?

When a function's visibility is external, trying to modify the function parameters within that function gives the error: TypeError: Expression has to be an lvalue. However, if I change the ...
AnAllergyToAnalogy's user avatar