These are chat archives for ethereum/tutorials

9th
Feb 2018
Qaiswin
@Qaiswin
Feb 09 2018 13:40
Hi
KarzanBotani
@KarzanBotani
Feb 09 2018 13:46
Hi :D
imugera
@imugera
Feb 09 2018 19:16
ha anyone tried to create a token using the code on ethereum website and the function MyToken line is spitting out an error?
KarzanBotani
@KarzanBotani
Feb 09 2018 19:18
@imugera Send the code and I'll take a look and see if I can track down the error
imugera
@imugera
Feb 09 2018 19:23
@botanki this is the error code No visibility specified. Defaulting to "public".
function MyToken(uint256 initialSupply) {
^
Spanning multiple lines.
,
KarzanBotani
@KarzanBotani
Feb 09 2018 19:27

Functions and variables have a visibility, an "Access Modifier":

https://github.com/manojpramesh/solidity-cheatsheet#access-modifiers

Access modifiers
public - Accessible from this contract, inherited contracts and externally
private - Accessible only from this contract
internal - Accessible only from this contract and contracts inheriting from it
external - Cannot be accessed internally, only externally. Recommended to reduce gas. Access internally with this.f.

You should get used to assigning access modifiers to your functions, atleast, to get that error to go away.

imugera
@imugera
Feb 09 2018 19:28
makes a lot of sense. Thanks a lot!
KarzanBotani
@KarzanBotani
Feb 09 2018 19:29
Now if you write: function MyToken(uint256 initialSupply) public { } it will disappear. If you do not want your function (in this case, the constructor) to be accessible by everyone else, then you can for example make it private
I can recommend you this readMe on GitHub which gives a short explanation to all functions in Solidity: https://github.com/manojpramesh/solidity-cheatsheet