I've read that getters are automatically created when you make a variable public. Can other contracts access these getters or is it only for web3.eth? Also what would be the getter name?
1 Answer
The getter's name is the variable's name. So in
contract foo {
int public bar;
}
You can access it through someFooInstance.bar()
. It should work the same in both web3.js and solidity (from another contract.) If it's an array (i.e. int[] public bar
) or a mapping (mapping (address=>int) public bar
) you can access specific elements through someFooInstance.bar(n)
.
There's no way to automatically create a setter, because a setter anyone can access is probably a bad idea. But there's no obvious way to decide who can and can't access a setter.
-
-
Same way.
someStruct public bar
. You'll get an array of most elements. Some, such as arrays within arrays, recursive structs, and mapping won't be returned if they're inside a struct. Jan 28, 2017 at 16:10 -