Solidity Basics

How do I save HelloWorld.sol to my HD?

2 Likes

If you are working on remix, there is no way (at least i know) to save the file on your computer.

In this cases what I do is, after my contract works on remix, I copy the entire code and paste it on a new file in Atom, then I save that Atom file with “.sol” format at the end of its name. (contractName.sol)

Still i know you can upload all your remix code into your github account, but this is not the solution if you want to save them in your own computer.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Hello @filip and team,

I am racking my head on what’s wrong with my code. I’m just getting started in the Solidity training and am receiving this message when I click “setNumber”. Can you help?

Error Message:

transact to HelloWorld.setNumber errored: Error encoding arguments: Error: invalid BigNumber string (argument=“value”, value=“1000.1”, code=INVALID_ARGUMENT, version=bignumber/5.0.8)

Here’s my code:
pragma solidity 0.5.12;

contract HelloWorld{

string public message = "Hello World";

uint[] public numbers = [1, 20, 45];

function getMessage() public view returns(string memory){
    return message;
}
function setMessage(string memory newMessage) public {
  message = newMessage;
}

function getNumber(uint index) public view returns(uint){
    return numbers[index];
}

function setNumber(uint newNumber, uint index) public {
  numbers[index] = newNumber;
}

function addNumber(uint newNumber) public {
  numbers.push(newNumber);
}

}

Screenshot for reference:

1 Like

Hey @crypto_j55, hope you are well.

Your setNumber function requires 2 arguments, a uint number and uint index, but you are sending one value, which is 1000.1, it should be 1000, 1 (the comma is probably your mistake), when you have to send many arguments to a function, you have to use a comma between each argument.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Hello,
I am really enjoying this course so far.
I just finished taking the mappings quiz and I am wondering about one of the questions.
It is question #3: “Is it possible to find all values entered into a mapping in solidity?”
I said yes but the correct answer is No.
If I have all of the keys, why can I not find all of the values?
(I do understand that you cannot get keys from values, hence the No answer to question 4)
Could you please shed some light as to why the answer to question #3 is No?

1 Like

Hi @Maya,

Great to hear that you’re really enjoying the course! :grinning:

This question depends a lot on how you interpret it. As you can see, I was confused in the same way, when I first did this quiz:

Theoretically speaking, you are correct. However, the question is trying to highlight the difference between the practical use cases of mappings v arrays. You can’t iterate over a mapping, meaning that each look-up can only be performed using a single unique key, which will only allow you to find and retrieve a single value (the one mapped to that key). However, arrays can be iterated over (e.g. using a for loop), meaning that, while you may only be searching for a single value, all of the values can still be checked on an index-by-index basis until the value you are looking for is found. If the value you are searching for is stored at the final index, then during the iteration process all values will need to be found and checked.

Here’s an explanation I wrote about the difference between Solidity mappings and arrays, in case you find it helpful:

Think of an array as being like a filing system/cabinet. You can search around in it, retrieve data from specific places in it, and you can iterate over it. All of the values stored in an array are like the contents/data in each of the files in a filing cabinet. These values (file contents) are ordered according to a sequence of indices (0, 1, 2, 3 etc.), a bit like filing reference numbers. Each index (file reference number) and it’s associated value (file contents/data) is a key/value pair (the key being the index).

A mapping is more like a telephone operator (bear with me…). If you give it a key (whatever the key has been defined as — let’s say a telephone number for this analogy, but in Solidity it’s more likely to be an address)… with that key (telephone number) the mapping will supply you with the value that the key is mapped to (the telephone operator will connect you to the person who is “mapped” to the telephone number you gave them).

The telephone operator (mapping) can only connect you to the other person (return the value) if you already have their telephone number (key/address). With a filing cabinet (array) you can hunt around (manipulate it / iterate over it etc.) until you find what you’re looking for, because of its ordered sequence of reference numbers (indices). Generally speaking, you can’t iterate over a mapping due to it’s non-sequential nature. However, if you have the key to a value (the telephone number of the person you want to speak to and interact with) the mapping (telephone operator) can “put you through” straight away. If you have very large mappings this will save you a noticeable amount of gas (as opposed to using an array). The advantage of an array is its flexibility, whereas a mapping will give you more privacy (you don’t have to speak to a load of other people until you find the one you actually want to talk to).

I hope that helps to clarify things, but just let us know if you have any further questions. :slight_smile:

That fixed it. Thanks so much @thecil

2 Likes

Hi @filip,

great course thank you. I have a question. I would like to become a Solidity Smart Contract Auditor.

Do you know what qualifications you need to do this?

1 Like

Hi @mattqs,

I imagine that if you are aiming to be a smart contract auditor, then qualifications where you have learnt and practised the analytical, investigative and evidence gathering skills used in auditing will be very beneficial: courses such as accounting, financial management or business administration should cover these skills, although you would have to check the specific syllabus of each course. Obviously, you would also need to demonstrate an in-depth knowledge of smart contracts and Solidity. As the blockchain industry and smart contracts is such a new technology and ecosystem, I don’t think there are as yet any specific Solidity Smart Contract Auditor courses or qualifications. The courses in this academy will certainly give you enough in-depth theoretical and practical knowledge of Ethereum smart contracts and the Ethereum blockchain ecosystem to be able to demonstrate this specialist industry knowledge to a potential employer. Then, in order to work specifically on the auditing side of things (especially if you want to work for one of the professional services companies that provide auditing and consultancy services to clients), then the more traditional finance qualifications that I’ve mentioned above will provide the additional evidence of the types of auditing skills and practical experience that employers would be looking for.

The Ethereum Smart Contract Security course that we offer here in the academy is particularly focused on the risk management and security aspect of smart contracts. This will be vital knowledge for any smart contract auditor.

1 Like

Hi @filip,
In relation to Error Handling - require()… Is there any cost in gas to do any of the checks in require? Because if it fails it returns the gas, so could that be used as a way to spam the network? If for example you kept calling contracts with params that will fail at the require stage…
Thanks!
Brian

2 Likes

Hi @bdoherty, hope you are well.

Now the require() function is used to verify that the arguments passed to the function are valid before the execution of themself, it does not have any gas cost, functions cost gas when they are about to being processed by a miner, the gas is for the miner basically.

Take an example on:
Lets say i have a function that must verify my age before it can proceed to the next step of his logic.
So if my age is above the assigned by my require it will not execute the function logic.

function payMe(uint _age) public{
 //verify that _age is inside range
require(_age < 50, "You'r age is above the range, can't continue" );
//if _age is valid, continue execution
doSomething();
} 

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Hi Carlos,

Im great! Thanks for the feedback. So its not costing gas yet because this happens before it gets to a miner. So in your example, where and who is doing the processing to check the require statements? Is it happening on the EVM? If so would there be a cost in relation to resources to check the requires etc? So if you were to repeatedly call some function with lots of requires would things start to fall over at any point?

Hope I make sense!
Brian

Yes, the EVM have access to the smart contract, any call on a function will be handle by the EVM.

There is basically no use of big resources to check the arguments that must be passed to a function.

Is a simple calculation for the network, computers are very precise in terms of calculations so is almost impossible that calling multiple times a function with different arguments will fall, maths are very precise and even more because the EVM goes on binary code which is the most tiny and exact representation of what the computer must calculate.

Basically, the EVM verify the arguments, since this a very simple operation, no big resources are used, also it does not matter how many times a function is called if this one has been programmed decently to verify the inserted data before it’s execution (thats why require is important, to verify data before execution).

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

@filip
In the video series about storage you mention 3 locations:

  • Storage
  • Memory
  • Calldata

However, when I do the quiz afterwards, I only found 2 of these (Storage + Memory, Calldata was not in the list) which turned out to be wrong. In my breakdown, it shows “Stack” as third option. You never mentioned this in your video’s.

Screenshot 2020-12-23 at 17.08.44

Is this the old name for Calldata perhaps? Or are we missing something here?

1 Like

hi everybody i am in solidity basics and when I click on deploy it give me this

sender doesn’t have enough funds to send tx. The upfront cost is: 3000000

does anybody can help me with that please , thanks!!!

1 Like

Hi @steve777, hope you are well.

Could you please share a screenshot? If you are using remix, i would like to verify your compiler config, maybe also the code can help us solve your issue :nerd_face:

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Hey @seer,

It seems that your post about the data location quiz has been missed. Sorry about that!

There was actually a problem with this quiz. It hadn’t been updated from the old course which only discussed Memory, Storage and the Stack. It’s now been updated to coincide with the changes in the new course, and what you’ve been taught in the videos. So you may want to just retake the quiz, and you should find it makes sense now :slight_smile:

Apologies for the confusion and inconvenience!

Hey guys, they say that there’s no such thing as a stupid question, so here goes. Mine is a follow-on to keitra1948’s post above – but it relates to mapping.

In the video on Structs, Filip first demonstrates his “clearest” way (i.e., the function createPerson . . .) to code adding a new person to the people array, and then he demonstrates the alternative (i.e., “Person memory newPerson . . .”). See: @10:05 of the Structs video.

The distinction between the two methods as well as the subsequently explained reasons why we might choose to use one versus the other seems obvious enough but I must be missing something because what I don’t understand is why, Filip, you didn’t code the presentation in the Mappings video using the function createPerson . . . people.push(Person(people.length, name, age, height)) method?

In the Mappings video, you removed the “people.push(Person(people.length, name, age, height))” altogether, without explanation, and proceeded to use the less “clean” newPerson method to complete your Mappings illustration.

So, my question is, how do I code the mapping using the functionCreatePerson . . . people.push(Person(people.length, name, age, height))? I’ve tried to work this out on my own but I’m just spinning wheels.

Best regards!

P.S. I see that you’ve also removed the “people.push(Person(people . . .” expression from your GitHub structs.sol file. Is there a reason for that as well?

1 Like

Great question @novosel,

Have a look at this post. That should answer your question, but please come back and let us know if anything is still unclear or if you have any further questions :slight_smile:

1 Like

Ah! Jon_m, THANK YOU!!

Do you happen to know why Filip abandoned using this method?

If it’s a no-harm, no-foul way to use exclusively the expressions that don’t write to the state, then I’ll simply focus on that route. I’m a beginner so I’ll have to think this through.

Cheers!

1 Like