Solidity Basics

Hi @Nev
Thanks for reaching out. Can you specify the time in the video this was mentioned?

1 Like

@Taha right around minute 4ā€¦

My understanding (super limited might I add) is that computer reads code top to bottom and when I was learning about JS we would write function first, then call it later (lines underneath it). However in this video, while we did create function first, the calling of the action came on the lines above the function itself and I just want to understand why that is and whether that is how solidity works in contrast to JS.

1 Like

@Nev
JS (apart from Nodejs) is browser oriented and reads from top to bottom. While other programming languages first compile the code for the machine to understand and then execute.
In solidity, the code is first compiled for the EVM to understand and then publish, hence by the time the EVM has all the functions irrespective of the vertical order :slight_smile: coded

2 Likes

@Taha Got it! THANK YOU. this makes sense now.

1 Like

@filip
Hi Filip
I tried to follow ā€œhello worldā€ contract but when I try to compile I get an error saying: browser/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.
The website confused me some more. Is there some licensing I need to have, like register as a user or something. Please help.
Thanks a lot.

1 Like

Hi
What did you do to resolve this issue?

Actually I didnā€™t resolve it. The contract did compile, the SPDX-License-Identifier is simply a ā€œprecautionā€ā€¦so the ā€˜resolutionā€™ was just to ignore it and move on as it is just another ā€˜minor issueā€™ getting in the way of learning more important matters.

Like many, Remix is quite a big step from a simple ā€˜notepadā€™ or ā€˜Atomā€™ text editor so it was and still is a bit learning curve to get familiar with it and having an older laptop and poor internet connection does not help. This application is run from the backend isnā€™t it? One cannot download a desktop appā€¦but perhaps you can! This is one of the merits of the forum: generation of ideas and the benefits of collaberation! Cheers

2 Likes

@Rasselas_Wildcat
Thanks for reaching out!
Point to remember: ā€œwarningsā€ are not error. You should be able to compile your contract.

Let me know it doesnā€™t. :slight_smile:

2 Likes

Thank you guys! I was able to move forward!

1 Like

Hello everyone :smiley:
I was working through the mapping video with Filip and have a ā€œParserErrorā€ at the end. If youā€™d be so kind to look it over and give me any hints or info iā€™d thoroughly appreciate it. REALLY thought I was doing this word for word as Filip did, but here we are :stuck_out_tongue:

Screen Shot 2020-07-07 at 2.48.04 AM

Thank You for your time :]

1 Like

Hi @Mining365 You have forgotten to open and close the curly brackets when you write the function. This should work

function getPerson() public view returns(string memory name, uint age, uint height){
        address creator = msg.sender;
        return (people[creator].name, people[creator].age, people[creator].height);
    }  
2 Likes

Thank You so much @abuga :100:
knew it was something simple that I wasnā€™t seeing! really appreciate the help 10/10

1 Like

Question:
If there are so many addresses, how can the program instantly return its value? Doesnā€™t it have to go through each address to find the right one?

Hi @JohnJR,

Firstly, many apologies for having missed your post and for therefore taking so long to respond to your question.

I do hope you managed to resolve it and move on, because Iā€™ve just run the exact code that youā€™ve posted here, and it should run exactly as Filipā€™s does in the video.

With your code, I retrieve the first person I input by accessing index 0 of the people array, the second person at index 1, the third person at index 2 ā€¦ etc.

The only thing I can think of that may have caused your confusion is if you executed createPerson twice with the same person information. You would then have 2 people, one at index 0, and the second at index 1, but they would appear to be the same person as their details would be identical.

Do let us know if youā€™re still having problems, and weā€™ll respond a lot quicker this time around :pray:

2 Likes

No probs, thanks for getting back. I see it now and it indeed works. think that was what happened.
thanks for clearing it up!

1 Like

@rostyslavdzhohola
Thanks for reaching out!
Can you elaborate your question more? Like what program?

If you are talking about the EVM returning addresses values then this is the answer:

  1. Address are nothing but keys and its value (i.e. balance) is an Unspent transaction output (UTXO) in the blockchain
  2. the EVM can easily act as a read-only database/ledger, the bottle neck is when we try to insert some data/tranx, hence there is no gas fees for only reading the blockchain :slight_smile:
  3. Returning value still take fraction of seconds more in public Ethereum due to so many address as compared to private Ethereum/Ganache.

Regards

2 Likes

For example, when we use msg.sender to find the address. The program still needs to look up that address in the millions of different addresses on the blockchain. How does it find it quicker than if you were using an array, for example? You still need to go through each address and compare if it is the right one.

@rostyslavdzhohola
msg.sender is an address only :slightly_smiling_face:

it basically means the address which is sending the message (i.e. calling the function )

2 Likes

Iā€™m having to repeat some of this course due to a lack of understandingā€¦

I do not understand the mapping comparison to arrays. Is not an array a dictionary as well? the key to arrays are the indices. If you know the index, ā€˜0ā€™ for example, you know the value instantly. there is no guessing. if you had to guess the hexadecimal address, you would never find the value. so I donā€™t get that comparison.

the array index is also unique to the value as well. index ā€˜zeroā€™ has itā€™s value and that value may be shared with other index values, but there is only one value for index zero as with mapping. so I donā€™t get the uniqueness comparison either. a single digit is just as unique as a 32 or whatever bit hexadecimal address to my understanding (yes, I am a nube)

is it a security thing? if you have an array value that is linked to its index, open and free for any and all to see. You have the value to index zero you know itā€™s tie to index zeroā€¦this tie is not secure. stated in another way, if an array is defined or undefinedā€¦its index is not hidden.

so is mapping some sort of secure array?

basically what we are following is a simple entry of the database field ā€˜balanceā€™ to the database field ā€˜ownerā€™ā€¦please bear with me, I am old school. That is done in a balance-owner line entry.

this relationship is can be performed with an array operation
or it can be performed with a mapping operation

simply put, remembering an array index is much easier than remembering an ethereum addressā€¦(I know, I am missing the big picture hereā€¦lost in the forrest gump)

is the concept ā€˜to setā€™ the same as ā€˜to inputā€™ or ā€˜to passā€™ or ā€˜to throwā€™ data to a function? Is this also creating ā€˜an instanceā€™ and this instance is persistent as it goes to a ā€˜state variableā€™?

this is probably the MOST important section of all the vids for me as I gotta get these concepts, yesā€¦I am a repeat customer here as I didnā€™t get it and just eased on down the road only to be hit by a collision near the end.

also I have noticed that I can ā€˜setā€™ the string variable without quotation marks and it appears to workā€¦so is this necessary???

cheers

1 Like