Hey @Florian_P
The EVM refunds you the gas fee that you have not spent yet .
The instructions that are executed before the require
are not refunded.
Cheers,
Dani
Hey @Florian_P
The EVM refunds you the gas fee that you have not spent yet .
The instructions that are executed before the require
are not refunded.
Cheers,
Dani
HI ,
I am a bit confused with = and ==
Is = used when key points to value ?
== is used when value equal to value ?
I am not sure.
Anyone can advise me so i can understand deeper ?
Thanks
Hey Filip,
I have a problem doing the quiz: For the last question I cannot choose an answer. I already checked in the dev tools:
Uncaught TypeError: _.contains is not a function
at App.AssessmentQuestion.choiceActive (application-aab0dfd604bd70fc0bd0cf183432d4fe3f0613476d71956eb50cedec03bba99a.js:72)
at HTMLDivElement.eval (eval at T (application-aab0dfd604bd70fc0bd0cf183432d4fe3f0613476d71956eb50cedec03bba99a.js:18), <anonymous>:3:37)
at Object.refresh (application-aab0dfd604bd70fc0bd0cf183432d4fe3f0613476d71956eb50cedec03bba99a.js:18)
at b (application-aab0dfd604bd70fc0bd0cf183432d4fe3f0613476d71956eb50cedec03bba99a.js:18)
at Object.Twine.refreshImmediately (application-aab0dfd604bd70fc0bd0cf183432d4fe3f0613476d71956eb50cedec03bba99a.js:18)
at HTMLButtonElement.r (application-aab0dfd604bd70fc0bd0cf183432d4fe3f0613476d71956eb50cedec03bba99a.js:18)
at HTMLButtonElement.dispatch (application-aab0dfd604bd70fc0bd0cf183432d4fe3f0613476d71956eb50cedec03bba99a.js:2)
at HTMLButtonElement.g.handle (application-aab0dfd604bd70fc0bd0cf183432d4fe3f0613476d71956eb50cedec03bba99a.js:2)
This error message comes every time I try to choose an answer.
Btw Iâm using the latest version of the brave browser (already turned off brave shields for that site).
Thanks already
xela
Hey @xela, hope you are ok.
I have tested the quiz and is working great for me, maybe you could try to test it again but with another browser? which one are you using?
Carlos Z
Hi Filip.
This is the first time I message you. I would like to tell that I like your Solidity lectures very much.
I have a question about require.
I wonder if we can use require on two conditions simultaneously. I have looked on google and I have found that we can require condition1 && condition2. but is there a require condition1 OR condition2?
I couldnât find anything about that. or is there another way to express it?
I believe that i could be very useful to require that if either condition1 or 2 or maybe 3 is met, then run the function.
Some of these quizes are not working with the brave browser. But then it worked with Microsoft edge.
Hey @Meriem, hope you are ok.
yeah it is complete possible to have an OR instead of AND.
Example:
// cond1 AND cond2 must be true
require(condition1 == true && condition2 == true);
// cond1 OR cond2 must be true
require(condition1 == true || condition2 == true);
Carlos Z
Some times is the brave shields, you could try to turn them off for the academy.
Carlos Z
yes I know that brave shields causes trouble on some websites. Therefore I already turned it off, but I still get that error at some quizes. I than just copy-paste the quiz-url into my microsoft edge and do it there (:
Hey @Meriem,
As you can see from @thecilâs example, the syntax in Solidity for coding conditions with logical operators is very much like JavaScript. Iâm hesitant to say it is exactly the same, as I have never done a thorough comparison test. But as you can see you can use Logical ANDâ&&
âand Logical ORâ||
âjust like in JavaScript. You can also use Logical NOTâ!
âin the same way too. In fact there is a huge overlap with the operators in general *.
Iâm assuming, of course, that youâve already familiar with JavaScript. If not, then before moving on too much more with Solidity, you should definitely consider doing our JavaScript course, as in Solidity there is a lot of overlap with Javascript in terms of syntax, structure and concepts. There are obviously key differences, but knowing JavaScript certainly helps a lot.
* One good example of a difference is with the equality operators. JavaScript has bothâ ===
âand ==
,â andâ!==
âandâ!=
,â but Solidity only hasâ ==
âandâ!=
â(there is a logical reason why, but Iâll leave you to work that out for yourself )
I wonder why the function transfer
is not working?? it throws an error on the require
statement as shown in picture. Thanks!
Try to move the assert
to the end of the function, you should _transfer
first, and then the assert
will check the condition.
Carlos Z
Thank you for the reply! Iâll look at those details more carefully next time
Hi @juanmcba,
If youâre still having problems with thisâŚ
I canât see your code very clearly from the fuzzy screen shot, or the error message, but maybe your first require statement is throwing because itâs actually doing its job? Does the error message youâre getting include the message youâve added to the require statement, âNot sufficient balanceâ? If so, then are you calling transfer from an address which hasnât added any balance yet? If you are, then require() is preventing the caller from transferring funds they donât have⌠which is good. Check the address that is calling the transfer function in the Account field, and make sure this same address has already added a balance that is more than the amount input into the transfer function.
If thatâs not the problem, and you havenât resolved it yet, then youâll need to post your full code, and not a screen shot, so that we can deploy and test it ourselves.
⌠but if your error message doesnât include âNot sufficient balanceâ, then that means it isnât your first require statement thatâs throwing at all, but the assert statement. You need to make the modification that @thecil has already told you about, anyway, otherwise assert() will still throw after youâve resolved any other issues.
Can someone please help me understand if the gas fees get returned to the user when the contract gets reverted? On one blog it says that they do not (blog one here) and in two blog it says that they do ( blog two here) . I hope someone with sufficient understanding of the topic and or experience can clarify this.
Thank you in advance.
Joseph G
Hi @JosephGarza,
It depends on whether it is require() or assert() which fails and causes the transaction to revertâŚ
When a function is called, a gas limit has to be allocated to the transaction. If require()
throws, only the gas consumed up to that point is spent (including the gas required to execute the require function itself) , and the gas remaining in the âbudgetâ for that transaction (up to the gas limit) is refunded to the caller (effectively unspent). Because of this functionality in terms of gas consumption, you can proabably see that the earlier in the function require()
is placed, the less the cost of gas will be if it throws and the transaction reverts. This seems logical when we consider that require()
is meant to throw. While we want to ensure that there is at least some cost associated with calling a function (whether it is successful or not) as a disincentive to spam the network, we donât necessarily want to penalise those who call the function with invalid inputs by mistake.
In contrast, if assert()
throws, it causes all of the remaining gas in the âbudgetâ allocated to that transaction (up to the gas limit) to be consumed, and so can result in a considerably higher cost.
I hope that clarifies things, but do let us know if anything is unclear, or if you have any further questions
Thank you, it actually does. Thank you very much. My reasoning was the actual block hash but I can see that my logic was far off. I can see how transaction costs are designed to incentivize and impact.
Thank you.
Great, Iâm glad that has helped
The situation with gas costs and refunds etc. is pretty difficult to wrap your head around to start with. It took me a while to piece together what was really happening, as I think it does most people. The problem is that many articles and blogs about the subject either donât tell you the full story, or they are far too technical for beginners.
Since replying to you, I have also read the two blogs you attached, and, in my opinion, this one from EthereumDev, is the more helpful in terms of what happens with require()
, because it does clarify that it is only the remaining gas which is refunded. But it doesnât mention assert(). What is actually meant by remaining gas is also something that often seems to be missed out of many explanations, and I think to understand what this really means, you need to understand that remaining gas is linked to the gas limit.
This blog from Halborn, doesnât mention either assert() or require(), and I also think it could easily cause confusion and could potentially be misleading, because it doesnât explain that it is only the gas consumed for the operations up to and including the execution of require() , which is the cost to the caller when require() triggers revert.