Solidity Basics

I’ve wanted to rewatch the “Implementing Visibility” Video and now the same video is shown for “Introduction to Visibility” and “Implementing Visibility”
There might be some error.

1 Like

Hey @Konzaih, hope you are great.

Indeed, we made yesterday a few adjustment in some courses, probably we set the wrong video.

I have fixed it now, “Introduction to Visibility” was ok, the incorrect was “Implementing Visibility”, please give it a look and is all good now let me know :nerd_face:

Carlos Z

Hey @thecil

Now it is as it used to be and the correct video is shown. :+1:

1 Like

Hi @thecil , in the mapping lesson, why did Filip used “from” in the _transfer private function, and not in the transfer public function?

Hey @salvatorev, hope you are well.

basically keep this in mind: one function is for internal use of the contract, the other is for the public use.

We assume that in the transfer public function, msg.sender will be “from” (the caller of the function) internally for the contract, then it will run the internal function and will send the parameter to that one (_from, _to, _amount).

Hope I explained my self clear, if not let me know :nerd_face:

Carlos Z

1 Like

There’s something I don’t understand. I am getting confused about the cursor of the compilor and where it goes upon certain function calls. Here is an example:

pragma solidity 0.8.7;

contract Example {
    
    function f1() public returns(uint) {
        uint output1 = 1;
        f2();
        return output1;
    }
    
    function f2() private returns(uint) {
        uint output2 = 2;
        return output2;
    }
}

This contract runs a function f1, whcih simply calls another function f2, and outputs a variable’s value.

Now, I always thought that it was the first return statement which the compiler reads that will be outputted to the user (in this case, I thought output2 would be emitted). However, for some reason that I don’t understand, output1 is emitted.

Could someone explain to me how the compiler reads this and why the output is the way it is in this case, please?

1 Like

Although f2() is invoked in f1, it does not do anything with the returned value, next codeline execution is to return output1 value. So basically, f1 does not do anything else than call f2, but the returned value is useless.

Carlos z

1 Like

So, I’m assuming because the contract calls f1(), it will run every line in the contract. So:

  1. Is the return value of f2() useless? What happens to it?
  2. Is there a way to send output2 to f1() so that it can be returned?

Let me know and thanks for your help.

nothing happens, the function f2 is just triggered and thats it.

You mean something like this:

    function f1() public returns(uint) {       
        return  f2();
    }

Carlos Z

Oh, I see. Thanks @thecil!

question:
i was playing around with the while and for loop differences…

function looper(int input) pure public returns (int, int){
   int i = 4;
   while (i < 10){
       input++;
       i++;
       }
   return (input, input+i);
   }

versus

function looperfor(int input4) pure public returns (int, int){
    for (int i=2; i<5; i++){
        input4++;
        }
    return (input4, input4 + i);
    }
}

and as you might expect, i get a DeclarationError ONLY in the second one: essentially undeclared identifier “i” for “input4 + i”… i guess identifying within the for header does not work, huh? is that a general rule i should be aware of or something more specific to solidity? (i haven’t yet taken js for blockchain developers, so if it’s in there, my apologies upfront…)

Hi
I’m finding it difficult to create a file in the remix editor. I created the file but it is not opening to where you write the code. Also, is it downloadable?

Kindly help me guys.

Thank you.

@filip

Hey @Zakzub, hope you are well.

Would be great if you can share a screenshot of the error that is showed to you on remix. That will give me an idea on how to solve it :face_with_monocle:

Carlos Z

Screenshot 2021-08-17 at 21-48-17 Remix - Ethereum IDE

1 Like

Ok, if you right click on the folder “contracts” you can create a New File inside this folder and rename it as you like (must end with .sol format, example: hello.sol).
image

Carlos Z

Thanks. Issue resolved.

Henry

1 Like

hiii@filip…i am facing with an issue
helloworld.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use “SPDX-License-Identifier: UNLICENSED” for non-open-source code. Please see https://spdx.org for more information.

helloworld.sol:4:1: Warning: Function state mutability can be restricted to view function hel()public returns(string memory){ ^ (Relevant source part starts here and spans across multiple lines).

1 Like

hey @bhallasatyansh13, hope you are well.

Please share your code in the following way so we can help you solve the issue :face_with_monocle:

Thats just a warning msg to add the SPDX license to the contract. You can skip it by adding this at the start of the contract:

// SPDX-License-Identifier: UNLICENSED

Apparently, this function is hel()public returns(string memory) which will return a string value, for those function that returns a value, you must also use view keyword.
Example:

hello () public view returns(string memory) ...

Carlos Z

hey @thecil …thanks for the reply …it was of great help…can you please explain me the difference between view function and not using any function at all?and why i cannot place empty fnction in above code?..THANK YOU

Sorry, I do not understand quite well the question, the view keyword is used on the functions that will return a value and let the function show this value to the caller (the function invoker). If you dont need to return the value, there is no need to return or view anything.

Carlos Z