If you draw an analogy from Java:
I’d say visibility analogies are:
internal -> protected
external -> package
What does memory do in the syntax ?
Is one of the memory type that you can use on solidity to handle different type of operations.
Here you can read more about them https://cryptodetail.com/memory-types-solidity
If you have any more questions, please let us know so we can help you!
Carlos Z.
Hey Guys, I have a minor question regarding the people array part in the video. Does the Javascript way of thinking apply here? So Person[] is the array and people is the binding to the array?
Also Filip calls .push a function. Is it also called a method? Or in solidity the terminology is different?
hey @barnabas, hope you are well.
Person
is a struct, people
is the array which all data must be filled based on the struct.
Remember you have the basic struct for each person
struct Person {
string name;
uint age;
uint height
}
Then people
will be an array which data must be filled based on the struct variables.
Person [] people
//people array => [Person]
The .push
method is to append data into the array people
so every time you add a person, data will be saved on the last indexed position with Person
values.
Example:
Assuming that:
- there is a person already saved with {name: bob, age: 50, height: 150}
when you call people[0].name
should return “bob”.
If you have finished the createPerson
function, it will give you the whole idea of the Person [] people
variable definition.
If you have any more questions, please let us know so we can help you!
Carlos Z.
Hi @thecil thanks for the explanation! So people will be an array of Structs, and the Struct Person is basically a blueprint to populate the array with instances of Person. I think I got it, thank you! Reminds me of classes.
I guess the confusing part is that you have to put brackets after Person[]
but not after people
, even though people
will be an array, and Person
is a struct. And in this case Person
is actually the type I guess?
Yes at the beginning is a little bit confusing, and no, the type is not the Person struct is the record structure for the array.
You can read more about here: https://www.tutorialspoint.com/solidity/solidity_structs.htm
If you have any more questions, please let us know so we can help you!
Carlos Z.
Hi all how does the Remix IDE work? I have not been asked to created an account so how does this remember that it me and what are my files? Thanks.
Because your files are recorded in a folder on your computer (cache browser), if you delete the browser cache, you will lose all of them, so basically your files are stored in the computer waiting to be used again in remix.
Carlos Z
Ok cheers for that Carlos Z.
How do I save HelloWorld.sol to my HD?
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!
Carlos Z.
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:
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!
Carlos Z.
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?
Hi @Maya,
Great to hear that you’re really enjoying the course!
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.
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?
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.
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