Why this function should be pure? (it is working with view too)
It is not clear in the lesson.
function count(int number) public pure return(int) {
for(int i = 0 ; i < 10 ; i++) {
number++;
}
return number;
}
}
Why this function should be pure? (it is working with view too)
It is not clear in the lesson.
function count(int number) public pure return(int) {
for(int i = 0 ; i < 10 ; i++) {
number++;
}
return number;
}
}
Hi @RasHam,
Yes ⌠your function will still work when defined with any of the four function types âŚ
However, when developing smart contracts, it is important to reduce security risk by only permitting each function to access and change what it needs to. So, because your function not only doesnât need to change any data stored in a state variable, but also doesnât need to access and read any data stored in a state variable, your function should be defined with the most restrictive function type: pure
.
The compiler helps us to ensure that we define a function as the most restrictive data type for the operations it needs to perform. If you define your function as view
, the compiler will generate an orange warning for the line with the function header containing the keyword. The warning message will tell you that the more restrictive keyword pure
should be used instead of view
. The compiler will also throw a red error if the function type has been defined as too restrictive for the operations it needs to perform, and the error message will tell you which keyword is the most appropriate.
Compiler errors will prevent your code from compiling and your contract from being deployed. But you can choose to ignore compiler warnings, because they wonât prevent your contract from being deployed. However, the compiler generates warnings to highlight specific issues and risk factors, and so they should only be ignored if you fully understand these issues and potential risks, and if you are certain that in your particular use case they can be safely disregarded.
By the way, your returns
keyword is missing an âs
â in the function header. It should be âŚ
returns(int)
⌠otherwise it wonât compile at all.
I hope that clarifies things. But just let me know if you have any further questions
thank you very much, I am 100% clarified. I am getting the habbit of return and returns yet.
What are the examples of usages regarding to several data types of key in a dictionary?
I am familiar with mapping unique key in string but not in other data types.
I love the old school blackboard.
Hello folks !
Im new to the course and im trying to deploy a code from the Control Flow lesson,
and the code runs without any bugs, but the decoded output I always get is - .
Any idea how to get the decoded output instead of blank statement ?
ParserError: Invalid SPDX license identifier.
What does this error mean ?
Iâm having the same issue. Even if i copy the exact same code on the video, the output is always â-â
Iâm thinking there is some type of version differences where you have to put the strings in inverted commas or something. Ill let you know if i find it
Ok i got it.
Full beginner event here but good on us for learning haha, we deploy the contract then we need to expand the deployed contracts section and hit the Function button we created there.
see below
I am having a problem with the setter function.
When I run it and want to add a number on count, I get the number I insert +10.
So for instance, if i insert 10 I do not get 10 like Philip does in the video but get 20.
If I type 345 I do not get 345 as Philip does but 355.
What is the reason for this? Please find my code below.
pragma solidity 0.7.5;
contract HelloWorld {
int number;
function getNumber() public view returns(int){
return number;
}
function setNumber(int _number) public {
number = _number;
}
}
I ran this program you pasted and it works as it should. Is this is all of the code you are using for this contract? And remember to save + restart remix
Hi everyone!
I completed 60% of the Ethereum 101 (Solidity Basics) course, but still feel like lacking some fundamental knowledge and overall understanding of Solidity.
Filip explains everything clear, but I need some more practical tasks to learn.
Maybe someone could share their experience of learning Solidity Basics and practical implementation of this new skill?
Hey man, in the future we`ll look back and miss the times we were noobs !
Thanks for your help, now I got it working too!
During the control flow lecture, we learn how to use if else statements.
However, there is one thing I do not understand in Philipâs code.
after he writes the contract name, constructor, function, if condition, else condition, at the end he still has separately the old âreturn message;â function.
Please see the picture for reference.
Can someone explain to me if this is necessary or if he just forgot to remove it? Thank you
the return in the end does not really matter since the function is gonna return error if you type anything else than a number in it. I dont think its necessary, you can keep it or remove it, up to you.
Thank you! My code was running without it but it is better always to double check when you have not programmed before
As a person who has never programmed before, is it normal that I have to program the basic stuff many times for them to stick into my head? In my first day of Solidity i went through the first chapter and the past 2 days I am repeating this chapter by programming what Philip does on my own and then check if my code is similar to his.
I am not per se frustrated, but sometimes it does feel like I am a bit stupid for not getting something the first time I program it or see Filip program it, and having to do it 2,3,4 times. For instance, Bitcoin 101 and Ethereum 101 were so easy as courses compared to programming.
Is it normal thus to struggle a bit with typing as a beginner? I understand immediately what every variable or function does when Filip explains but where I do get stuck is in composing the code and adding variables. I am in no way quitting as I love the space, the academy, the industry and I love that we are building something for the people of tomorrow when we will not even be here to enjoy it anymore, but could use some emotional support since as I said, I get frustrated having to repeat my code 2,3,4 times before it gets stuck into my head.
In terms of mappings, can we see a block explorer as a mapping or key value storage? I am asking this because in the block explorer, one adds a key (an address) and gets a value (how much eth or btc etc the address has). Would tha qualify as mapping?
It´s quite normal, even experienced coders have to look up solutions regularly for problems from Stack Overflow for example. Each programming language has a little different styling which must be learnt, and depending on previous experience it takes more or less time.
About the mapping, at an idea-level (when you program mappings) you could think it in that way. Etherscan indexes data read from public ledger of Ethereum´s blockchain, whether they use mappings to do this, I dont know, their code is private I think.
Is the course still up to date? i noticed you were using version 0.7.5 in one of the course videos which is very outdated.